59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
|
import { Renderer } from '../core/renderer';
|
||
|
import { EngineComponent } from '../types/engine-component';
|
||
|
import { EngineEvents } from '../types/events';
|
||
|
import { EventEmitter } from '../utils/events';
|
||
|
import { Environment } from '../gameobjects/environment.object';
|
||
|
import { assetManager } from '../assets/manager';
|
||
|
import { WorldFile } from '../types/world-file';
|
||
|
import { World } from '../gameobjects/world.object';
|
||
|
|
||
|
export class LevelComponent extends EngineComponent {
|
||
|
private world!: World;
|
||
|
private environment!: Environment;
|
||
|
private cleanUpEvents?: Function;
|
||
|
|
||
|
constructor(
|
||
|
protected renderer: Renderer,
|
||
|
protected events: EventEmitter<EngineEvents>
|
||
|
) {
|
||
|
super(renderer, events);
|
||
|
}
|
||
|
|
||
|
initialize(): void {
|
||
|
this.world = this.renderer.scene.getObjectByName('World') as World;
|
||
|
this.environment = this.renderer.scene.getObjectByName(
|
||
|
'Environment'
|
||
|
) as Environment;
|
||
|
this.cleanUpEvents = this.bindEvents();
|
||
|
}
|
||
|
|
||
|
update(delta: number): void {}
|
||
|
|
||
|
cleanUp(): void {
|
||
|
this.cleanUpEvents?.call(this);
|
||
|
}
|
||
|
|
||
|
public getSceneTree() {
|
||
|
return {
|
||
|
world: this.world,
|
||
|
environment: this.environment,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public serializeLevelSave(name: string): WorldFile {
|
||
|
const world = this.world.serialize();
|
||
|
const environment = this.environment.serialize();
|
||
|
const assets = assetManager.serialize();
|
||
|
return {
|
||
|
name,
|
||
|
world,
|
||
|
environment,
|
||
|
assets,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
private bindEvents() {
|
||
|
return () => {};
|
||
|
}
|
||
|
}
|