Continue refactor

This commit is contained in:
billsonnn 2024-03-20 22:37:27 -04:00
parent 815f1cd6c9
commit df3bd5bf52
23 changed files with 101 additions and 89 deletions

View File

@ -1,4 +1,4 @@
import { Container, Point, Sprite, Texture } from 'pixi.js';
import { Container, Point, Texture } from 'pixi.js';
import { IRoomGeometry } from '../IRoomGeometry';
import { RoomObjectSpriteData } from '../RoomObjectSpriteData';
import { ISortableSprite } from '../object';
@ -25,7 +25,7 @@ export interface IRoomRenderingCanvas
moveDown(): void;
id: number;
geometry: IRoomGeometry;
master: Sprite;
master: Container;
display: Container;
screenOffsetX: number;
screenOffsetY: number;

View File

@ -23,21 +23,26 @@ export class GraphicAssetPalette implements IGraphicAssetPalette
const pixelOutput = TextureUtils.getPixels(texture);
const pixels = pixelOutput?.pixels;
if(pixels)
if(!pixels) return texture;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const imageData = ctx.createImageData(texture.width, texture.height);
for(let i = 0; i < pixels.length; i += 4)
{
for(let i = 0; i < pixels.length; i += 4)
{
let paletteColor = this._palette[pixels[i + 1]];
let paletteColor = this._palette[pixels[i + 1]];
if(paletteColor === undefined) paletteColor = [0, 0, 0];
if(paletteColor === undefined) paletteColor = [0, 0, 0];
pixels[i] = paletteColor[0];
pixels[i + 1] = paletteColor[1];
pixels[i + 2] = paletteColor[2];
}
imageData.data[i] = paletteColor[0];
imageData.data[i + 1] = paletteColor[1];
imageData.data[i + 2] = paletteColor[2];
}
return Texture.from(pixelOutput);
ctx.putImageData(imageData, 0, 0);
return Texture.from(canvas);
}
public get primaryColor(): number

View File

@ -0,0 +1,5 @@
import { RoomCameraWidgetManager } from './RoomCameraWidgetManager';
const roomCameraWidgetManager = new RoomCameraWidgetManager();
export const GetRoomCameraWidgetManager = () => roomCameraWidgetManager;

View File

@ -1,3 +1,4 @@
export * from './GetRoomCameraWidgetManager';
export * from './RoomCameraWidgetEffect';
export * from './RoomCameraWidgetManager';
export * from './RoomCameraWidgetSelectedEffect';

View File

@ -1,4 +1,5 @@
import { IConfigurationManager } from './IConfigurationManager';
import { NitroLogger } from '@nitrots/utils';
import { IConfigurationManager } from './IConfigurationManager';
export class ConfigurationManager implements IConfigurationManager
{
@ -76,7 +77,7 @@ export class ConfigurationManager implements IConfigurationManager
catch (e)
{
console.error(e.stack);
NitroLogger.error(e.stack);
return false;
}
@ -116,7 +117,7 @@ export class ConfigurationManager implements IConfigurationManager
this._missingKeys.push(key);
console.warn(`Missing configuration key: ${key}`);
NitroLogger.warn(`Missing configuration key: ${key}`);
existing = value;
}

View File

@ -40,7 +40,7 @@ export class RoomEngine implements IRoomEngine, IRoomCreator, IRoomEngineService
private _sessionDataManager: ISessionDataManager = GetSessionDataManager();
private _roomManager: IRoomManager = GetRoomManager();
private _roomObjectEventHandler: RoomObjectEventHandler = new RoomObjectEventHandler();
private _roomObjectEventHandler: RoomObjectEventHandler = new RoomObjectEventHandler(this);
private _imageObjectIdBank: NumberBank = new NumberBank(1000);
private _imageCallbacks: Map<string, IGetImageListener[]> = new Map();
private _thumbnailObjectIdBank: NumberBank = new NumberBank(1000);
@ -345,11 +345,11 @@ export class RoomEngine implements IRoomEngine, IRoomCreator, IRoomEngineService
canvas.geometry.setDisplacement(vector, direction);
const displayObject = (canvas.master as Container);
const displayObject = canvas.master;
if(displayObject)
{
const overlay = new Sprite(Texture.EMPTY);
const overlay = new Container();
overlay.label = RoomEngine.OVERLAY;
@ -2474,21 +2474,21 @@ export class RoomEngine implements IRoomEngine, IRoomCreator, IRoomEngineService
this._roomObjectEventHandler.cancelRoomObjectInsert(this._activeRoomId);
}
private addOverlayIconSprite(k: Sprite, _arg_2: string, _arg_3: Texture, scale: number = 1): Sprite
private addOverlayIconSprite(container: Container, label: string, texture: Texture, scale: number = 1): Sprite
{
if(!k || !_arg_3) return;
if(!container || !texture) return;
let sprite = this.getOverlayIconSprite(k, _arg_2);
let sprite = this.getOverlayIconSprite(container, label);
if(sprite) return null;
sprite = new Sprite(_arg_3);
sprite = new Sprite(texture);
sprite.label = _arg_2;
sprite.label = label;
sprite.scale.set(scale);
k.addChild(sprite);
container.addChild(sprite);
return sprite;
}
@ -3006,37 +3006,37 @@ export class RoomEngine implements IRoomEngine, IRoomCreator, IRoomEngineService
if(!canvas) return;
const sprite = this.getRenderingCanvasOverlay(canvas);
const overlayContainer = this.getRenderingCanvasOverlay(canvas);
this.removeOverlayIconSprite(sprite, RoomEngine.OBJECT_ICON_SPRITE);
this.removeOverlayIconSprite(overlayContainer, RoomEngine.OBJECT_ICON_SPRITE);
}
private getRenderingCanvasOverlay(k: IRoomRenderingCanvas): Sprite
private getRenderingCanvasOverlay(canvas: IRoomRenderingCanvas): Container
{
if(!k) return null;
if(!canvas) return null;
const displayObject = (k.master as Container);
const displayObject = canvas.master;
if(!displayObject) return null;
return ((displayObject.getChildByName(RoomEngine.OVERLAY) as Sprite) || null);
return displayObject.getChildByName(RoomEngine.OVERLAY) ?? null;
}
private removeOverlayIconSprite(k: Sprite, _arg_2: string): boolean
private removeOverlayIconSprite(container: Container, label: string): boolean
{
if(!k) return false;
if(!container) return false;
let index = (k.children.length - 1);
let index = (container.children.length - 1);
while(index >= 0)
{
const child = (k.getChildAt(index) as Sprite);
const child = (container.getChildAt(index) as Sprite);
if(child)
{
if(child.label === _arg_2)
if(child.label === label)
{
k.removeChildAt(index);
container.removeChildAt(index);
if(child.children.length)
{
@ -3057,19 +3057,19 @@ export class RoomEngine implements IRoomEngine, IRoomCreator, IRoomEngineService
return false;
}
private getOverlayIconSprite(k: Sprite, _arg_2: string): Sprite
private getOverlayIconSprite(container: Container, label: string): Sprite
{
if(!k) return null;
if(!container) return null;
let index = (k.children.length - 1);
let index = (container.children.length - 1);
while(index >= 0)
{
const child = (k.getChildAt(index) as Sprite);
const child = (container.getChildAt(index) as Sprite);
if(child)
{
if(child.label === _arg_2) return child;
if(child.label === label) return child;
}
index--;

View File

@ -18,6 +18,11 @@ export class RoomManager implements IRoomManager, IRoomInstanceContainer
private _pendingContentTypes: string[] = [];
private _skipContentProcessing: boolean = false;
constructor()
{
this.onRoomContentLoadedEvent = this.onRoomContentLoadedEvent.bind(this);
}
public async init(listener: IRoomManagerListener): Promise<void>
{
this._listener = listener;

View File

@ -5,14 +5,11 @@ import { GetEventDispatcher, RoomEngineDimmerStateEvent, RoomEngineObjectEvent,
import { GetRoomSessionManager, GetSessionDataManager } from '@nitrots/session';
import { CreateLinkEvent, NitroLogger, RoomId, Vector3d } from '@nitrots/utils';
import { RoomEnterEffect, RoomObjectUpdateMessage } from '../../room';
import { GetRoomEngine } from './GetRoomEngine';
import { ObjectAvatarSelectedMessage, ObjectDataUpdateMessage, ObjectSelectedMessage, ObjectTileCursorUpdateMessage, ObjectVisibilityUpdateMessage } from './messages';
import { SelectedRoomObjectData } from './utils';
export class RoomObjectEventHandler implements IRoomCanvasMouseListener, IRoomObjectEventManager
{
private _roomEngine: IRoomEngineServices = GetRoomEngine();
private _eventIds: Map<number, Map<string, string>> = new Map();
private _selectedAvatarId: number = -1;
@ -21,7 +18,8 @@ export class RoomObjectEventHandler implements IRoomCanvasMouseListener, IRoomOb
private _whereYouClickIsWhereYouGo: boolean = true;
private _objectPlacementSource: string = null;
constructor()
constructor(
private readonly _roomEngine: IRoomEngineServices)
{
GetEventDispatcher().addEventListener<RoomEngineObjectEvent>(RoomEngineObjectEvent.ADDED, event => this.onRoomEngineObjectEvent(event));
}

View File

@ -491,8 +491,10 @@ export class RoomPreviewer
return this._addViewOffset;
}
public updatePreviewObjectBoundingRectangle(point: Point): void
public updatePreviewObjectBoundingRectangle(point: Point = null): void
{
if(!point) point = new Point(0, 0);
const objectBounds = this._roomEngine.getRoomObjectBoundingRectangle(this._previewRoomId, RoomPreviewer.PREVIEW_OBJECT_ID, this._currentPreviewObjectCategory, RoomPreviewer.PREVIEW_CANVAS_ID);
if(objectBounds && point)

View File

@ -1,4 +1,7 @@
export * from './GetRoomContentLoader';
export * from './GetRoomEngine';
export * from './GetRoomManager';
export * from './GetRoomMessageHandler';
export * from './GetRoomObjectLogicFactory';
export * from './GetRoomObjectVisualizationFactory';
export * from './ImageResult';

View File

@ -1,37 +1,27 @@
import { AvatarScaleType, IAssetData, IAvatarEffectListener, IAvatarImage, IAvatarImageListener, IAvatarRenderManager, IObjectVisualizationData } from '@nitrots/api';
import { AvatarScaleType, IAssetData, IAvatarEffectListener, IAvatarImage, IAvatarImageListener, IObjectVisualizationData } from '@nitrots/api';
import { GetAvatarRenderManager } from '@nitrots/avatar';
export class AvatarVisualizationData implements IObjectVisualizationData
{
private _avatarRenderer: IAvatarRenderManager;
public initialize(asset: IAssetData): boolean
{
this._avatarRenderer = GetAvatarRenderManager();
return true;
}
public dispose(): void
{
this._avatarRenderer = null;
}
public createAvatarImage(figure: string, size: number, gender: string = null, avatarListener: IAvatarImageListener = null, effectListener: IAvatarEffectListener = null): IAvatarImage
{
let avatarImage: IAvatarImage = null;
if(size > 48) avatarImage = this._avatarRenderer.createAvatarImage(figure, AvatarScaleType.LARGE, gender, avatarListener, effectListener);
else avatarImage = this._avatarRenderer.createAvatarImage(figure, AvatarScaleType.SMALL, gender, avatarListener, effectListener);
if(size > 48) avatarImage = GetAvatarRenderManager().createAvatarImage(figure, AvatarScaleType.LARGE, gender, avatarListener, effectListener);
else avatarImage = GetAvatarRenderManager().createAvatarImage(figure, AvatarScaleType.SMALL, gender, avatarListener, effectListener);
return avatarImage;
}
public get avatarManager(): IAvatarRenderManager
{
return this._avatarRenderer;
}
public get layerCount(): number
{
return 0;

View File

@ -24,6 +24,8 @@ export class LayerData
{
if(!layer) return;
console.log(layer.ink);
this._tag = layer.tag;
this._ink = layer.ink;
this._alpha = layer.alpha;

View File

@ -145,7 +145,7 @@ export class SizeData
if(layerId < 0 || (layerId >= this._layerCount)) return false;
// TODO: check the .nitro files for inks
if(layer.ink !== undefined) directionData.setLayerInk(layerId, (layer.ink as BLEND_MODES));
if(layer.ink !== undefined) directionData.setLayerInk(layerId, (layer.ink?.toLowerCase() as BLEND_MODES));
if(layer.tag !== undefined) directionData.setLayerTag(layerId, layer.tag);

View File

@ -1,4 +1,4 @@
import { SCALE_MODES, Texture } from 'pixi.js';
import { Texture } from 'pixi.js';
import { IsometricImageFurniVisualization } from './IsometricImageFurniVisualization';
export class FurnitureDynamicThumbnailVisualization extends IsometricImageFurniVisualization
@ -34,7 +34,7 @@ export class FurnitureDynamicThumbnailVisualization extends IsometricImageFurniV
{
const texture = Texture.from(image);
texture.baseTexture.scaleMode = SCALE_MODES.LINEAR;
texture.source.scaleMode = 'linear';
this.setThumbnailImages(texture);
};

View File

@ -1,7 +1,7 @@
import { IAssetPlane, IAssetPlaneVisualizationAnimatedLayer, IAssetPlaneVisualizationLayer, IVector3D } from '@nitrots/api';
import { GetConfiguration } from '@nitrots/configuration';
import { TextureUtils } from '@nitrots/utils';
import { RenderTexture } from 'pixi.js';
import { RenderTexture, Sprite } from 'pixi.js';
import { PlaneBitmapData, Randomizer } from '../../utils';
import { PlaneMaterial, PlaneRasterizer, PlaneVisualizationLayer } from '../basic';
import { LandscapePlane } from './LandscapePlane';
@ -206,7 +206,7 @@ export class LandscapeRasterizer extends PlaneRasterizer
if(graphic && (graphic !== canvas))
{
graphic = new RenderTexture(graphic.baseTexture);
graphic = TextureUtils.generateTexture(new Sprite(graphic.source));
if(!graphic) return null;
}

View File

@ -152,7 +152,7 @@ export class PlaneMaterialCellMatrix
{
if(this._cachedBitmapData)
{
if(this._cachedBitmapData.baseTexture && (this._cachedBitmapData.width === width) && (this._cachedBitmapData.height === height) && Vector3d.isEqual(this._cachedBitmapNormal, normal))
if(this._cachedBitmapData.source && (this._cachedBitmapData.width === width) && (this._cachedBitmapData.height === height) && Vector3d.isEqual(this._cachedBitmapNormal, normal))
{
if(canvas)
{

View File

@ -2,7 +2,7 @@ import { IRoomCanvasMouseListener, IRoomGeometry, IRoomObject, IRoomObjectSprite
import { GetConfiguration } from '@nitrots/configuration';
import { RoomSpriteMouseEvent } from '@nitrots/events';
import { GetTicker, TextureUtils, Vector3d } from '@nitrots/utils';
import { Container, Graphics, Matrix, Point, Rectangle, Sprite, Texture } from 'pixi.js';
import { Container, Graphics, Matrix, Point, Rectangle, Texture } from 'pixi.js';
import { RoomEnterEffect, RoomGeometry, RoomRotatingEffect, RoomShakingEffect } from '../utils';
import { RoomObjectCache, RoomObjectCacheItem } from './cache';
import { ExtendedSprite, ObjectMouseData, SortableSprite } from './utils';
@ -18,7 +18,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
private _totalTimeRunning: number;
private _lastFrame: number;
private _master: Sprite;
private _master: Container;
private _display: Container;
private _mask: Graphics;
@ -115,10 +115,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
private setupCanvas(): void
{
if(!this._master)
{
this._master = new Sprite();
}
if(!this._master) this._master = new Container();
if(!this._display)
{
@ -206,9 +203,8 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
if(!this._mask)
{
this._mask = new Graphics()
.beginFill(0xFF0000)
.drawRect(0, 0, width, height)
.endFill();
.rect(0, 0, width, height)
.fill(0xFF0000);
if(this._master)
{
@ -221,9 +217,8 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
{
this._mask
.clear()
.beginFill(0xFF0000)
.drawRect(0, 0, width, height)
.endFill();
.rect(0, 0, width, height)
.fill(0xFF0000);
}
}
@ -461,7 +456,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
if(!sprite || !sprite.visible) continue;
const texture = sprite.texture;
const baseTexture = texture && texture.baseTexture;
const baseTexture = texture && texture.source;
if(!texture || !baseTexture) continue;
@ -631,7 +626,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
if(this._spritePool.length > 0) extendedSprite = this._spritePool.pop();
if(!extendedSprite) extendedSprite = new ExtendedSprite();
if(!extendedSprite) extendedSprite = new ExtendedSprite({});
if(extendedSprite.children.length) extendedSprite.removeChildren();
@ -1164,7 +1159,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
return this._geometry;
}
public get master(): Sprite
public get master(): Container
{
return this._master;
}

View File

@ -1,6 +1,6 @@
import { AlphaTolerance } from '@nitrots/api';
import { TextureUtils } from '@nitrots/utils';
import { Point, Sprite, Texture, TextureSource } from 'pixi.js';
import { Point, Sprite, SpriteOptions, Texture, TextureSource } from 'pixi.js';
export class ExtendedSprite extends Sprite
{
@ -14,9 +14,9 @@ export class ExtendedSprite extends Sprite
private _updateId1: number = -1;
private _updateId2: number = -1;
constructor(texture: Texture = null)
constructor(options?: SpriteOptions | Texture)
{
super(texture);
super(options);
this._offsetX = 0;
this._offsetY = 0;

View File

@ -56,6 +56,7 @@ export class SessionDataManager implements ISessionDataManager
public async init(): Promise<void>
{
console.log('do this')
await this._furnitureData.init();
await this._productData.init();

View File

@ -1,4 +1,4 @@
import { IAdvancedMap, IMessageEvent, IMusicController, IPlaylistController, ISongInfo } from '@nitrots/api';
import { IAdvancedMap, IMusicController, IPlaylistController, ISongInfo } from '@nitrots/api';
import { GetCommunication, GetNowPlayingMessageComposer, GetSongInfoMessageComposer, GetUserSongDisksMessageComposer, TraxSongInfoMessageEvent, UserSongDisksInventoryMessageEvent } from '@nitrots/communication';
import { GetConfiguration } from '@nitrots/configuration';
import { GetEventDispatcher, NotifyPlayedSongEvent, NowPlayingEvent, RoomObjectSoundMachineEvent, SongDiskInventoryReceivedEvent, SongInfoReceivedEvent, SoundManagerEvent } from '@nitrots/events';
@ -25,7 +25,6 @@ export class MusicController implements IMusicController
private _songDiskInventory: IAdvancedMap<number, number> = new AdvancedMap();
private _priorityPlaying: number = -1;
private _requestNumberPlaying: number = -1;
private _messageEvents: IMessageEvent[];
private _roomItemPlaylist: IPlaylistController;
private _musicPlayer: MusicPlayer;
@ -51,8 +50,6 @@ export class MusicController implements IMusicController
this._timerInstance = window.setInterval(this.onTick.bind(this), 1000);
this._musicPlayer = new MusicPlayer(GetConfiguration().getValue<string>('external.samples.url'));
this._messageEvents.forEach(event => GetCommunication().registerMessageEvent(event));
GetEventDispatcher().addEventListener(RoomObjectSoundMachineEvent.JUKEBOX_INIT, this.onJukeboxInit);
GetEventDispatcher().addEventListener(RoomObjectSoundMachineEvent.JUKEBOX_DISPOSE, this.onJukeboxDispose);
GetEventDispatcher().addEventListener(RoomObjectSoundMachineEvent.SOUND_MACHINE_INIT, this.onSoundMachineInit);
@ -159,8 +156,6 @@ export class MusicController implements IMusicController
this._timerInstance = undefined;
}
this._messageEvents.forEach(event => GetCommunication().removeMessageEvent(event));
GetEventDispatcher().removeEventListener(RoomObjectSoundMachineEvent.JUKEBOX_INIT, this.onJukeboxInit);
GetEventDispatcher().removeEventListener(RoomObjectSoundMachineEvent.JUKEBOX_DISPOSE, this.onJukeboxDispose);
GetEventDispatcher().removeEventListener(RoomObjectSoundMachineEvent.SOUND_MACHINE_INIT, this.onSoundMachineInit);

View File

@ -0,0 +1,4 @@
import { AdjustmentFilter } from 'pixi-filters';
export class NitroAdjustmentFilter extends AdjustmentFilter
{}

View File

@ -0,0 +1,3 @@
import { Ticker } from 'pixi.js';
export type NitroTicker = Ticker;

View File

@ -1,3 +1,4 @@
export * from './NitroAdjustmentFilter';
export * from './NitroAlphaFilter';
export * from './NitroContainer';
export * from './NitroFilter';
@ -5,3 +6,4 @@ export * from './NitroRectangle';
export * from './NitroRenderTexture';
export * from './NitroSprite';
export * from './NitroTexture';
export * from './NitroTicker';