Update framework
This commit is contained in:
0
framework/game/game.d.ts
vendored
Normal file
0
framework/game/game.d.ts
vendored
Normal file
0
framework/game/game.js
Normal file
0
framework/game/game.js
Normal file
26
framework/game/index.d.ts
vendored
Normal file
26
framework/game/index.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { AssetManager } from '../asset-manager';
|
||||
import { Input } from '../input';
|
||||
import Resonator from '../resonator';
|
||||
import { Scene } from '../scene/scene';
|
||||
import { SceneManager } from '../scene/manager';
|
||||
import { Scheduler } from '../scheduler';
|
||||
import { TTS } from '../tts';
|
||||
import { HTTPLoader } from '../resonator/loaders/http-loader';
|
||||
import { EventBus } from '../event-bus';
|
||||
import { World } from '../world';
|
||||
export declare class Game extends EventBus {
|
||||
assetLoader: HTTPLoader;
|
||||
assetManager: AssetManager;
|
||||
resonator: Resonator;
|
||||
input: Input;
|
||||
tts: TTS;
|
||||
sceneManager: SceneManager;
|
||||
scheduler: Scheduler;
|
||||
world: World;
|
||||
constructor();
|
||||
init(): void;
|
||||
start(): void;
|
||||
addScene(scene: Scene): void;
|
||||
addDefaultScene(scene: Scene): void;
|
||||
setWorld(world: World): void;
|
||||
}
|
44
framework/game/index.js
Normal file
44
framework/game/index.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { AssetManager } from '../asset-manager';
|
||||
import { Input } from '../input';
|
||||
import Resonator from '../resonator';
|
||||
import { SceneManager } from '../scene/manager';
|
||||
import { Scheduler } from '../scheduler';
|
||||
import { TTS } from '../tts';
|
||||
import { AriaOutput } from '../tts/outputs/aria';
|
||||
import { HTTPLoader } from '../resonator/loaders/http-loader';
|
||||
import { EventBus } from '../event-bus';
|
||||
export class Game extends EventBus {
|
||||
constructor() {
|
||||
super();
|
||||
this.init();
|
||||
}
|
||||
init() {
|
||||
this.assetManager = new AssetManager('game', '');
|
||||
this.assetLoader = new HTTPLoader();
|
||||
this.resonator = new Resonator(this.assetLoader);
|
||||
this.input = new Input(['keyboard'], document.body);
|
||||
this.tts = new TTS(new AriaOutput());
|
||||
this.sceneManager = new SceneManager();
|
||||
this.scheduler = new Scheduler(60);
|
||||
this.emit('ready');
|
||||
}
|
||||
start() {
|
||||
this.scheduler.start();
|
||||
this.scheduler.subscribe('update.logic', (dt) => {
|
||||
this.sceneManager.currentScene.update(dt);
|
||||
this.world.update(dt);
|
||||
});
|
||||
this.scheduler.subscribe('update.draw', (dt) => this.sceneManager.currentScene.updateDraw());
|
||||
this.sceneManager.init();
|
||||
}
|
||||
addScene(scene) {
|
||||
this.sceneManager.addScene(scene);
|
||||
}
|
||||
addDefaultScene(scene) {
|
||||
this.sceneManager.addScene(scene);
|
||||
this.sceneManager.setDefaultScene(scene);
|
||||
}
|
||||
setWorld(world) {
|
||||
this.world = world;
|
||||
}
|
||||
}
|
29
framework/game/scenes/ecs-scene.d.ts
vendored
Normal file
29
framework/game/scenes/ecs-scene.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Scene } from '../../scene/scene';
|
||||
import { World } from '../../ecs/index';
|
||||
import { Game } from '..';
|
||||
import { Component } from '../../ecs/component';
|
||||
import { System } from '../../ecs/system';
|
||||
import { Entity } from '../../ecs/entity';
|
||||
import { Query } from '../../ecs/query';
|
||||
import { SceneManager } from '../../scene/manager';
|
||||
export declare class ECSScene implements Scene {
|
||||
instance: Game;
|
||||
id: string;
|
||||
world: World;
|
||||
running: boolean;
|
||||
data: any;
|
||||
constructor(instance: Game);
|
||||
update(): void;
|
||||
updateDraw(): boolean;
|
||||
onActivate(manager: SceneManager): void;
|
||||
onDeactivate(): void;
|
||||
onSwitch(): void;
|
||||
createEntity(components: Array<Component<any>>): Entity;
|
||||
createComponent<T>(props: T): Component<T>;
|
||||
createSystem(systemExecutor: Function): void;
|
||||
addSystem(system: System): void;
|
||||
addEntity(entity: Entity): void;
|
||||
removeEntity(entity: Entity): void;
|
||||
createQuery(include: Array<Component<any>>, exclude: Array<Component<any>>): Query;
|
||||
extendEntity(entity: Entity, components: Array<Component<any>>): Entity;
|
||||
}
|
49
framework/game/scenes/ecs-scene.js
Normal file
49
framework/game/scenes/ecs-scene.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import { World } from '../../ecs/index';
|
||||
export class ECSScene {
|
||||
constructor(instance) {
|
||||
this.instance = instance;
|
||||
this.running = true;
|
||||
this.id = 'ECSScene';
|
||||
this.world = new World();
|
||||
}
|
||||
update() {
|
||||
if (this.running)
|
||||
this.world.run();
|
||||
}
|
||||
updateDraw() {
|
||||
return true;
|
||||
}
|
||||
onActivate(manager) {
|
||||
this.running = true;
|
||||
}
|
||||
onDeactivate() {
|
||||
this.running = false;
|
||||
}
|
||||
onSwitch() {
|
||||
return;
|
||||
}
|
||||
createEntity(components) {
|
||||
return this.world.createEntity(components);
|
||||
}
|
||||
createComponent(props) {
|
||||
return this.world.createComponent(props);
|
||||
}
|
||||
createSystem(systemExecutor) {
|
||||
return this.world.createSystem(systemExecutor);
|
||||
}
|
||||
addSystem(system) {
|
||||
return this.world.addSystem(system);
|
||||
}
|
||||
addEntity(entity) {
|
||||
return this.world.addEntity(entity);
|
||||
}
|
||||
removeEntity(entity) {
|
||||
return this.world.removeEntity(entity);
|
||||
}
|
||||
createQuery(include, exclude) {
|
||||
return this.world.createQuery(include, exclude);
|
||||
}
|
||||
extendEntity(entity, components) {
|
||||
return this.world.extendEntity(entity, components);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user