|
@@ -13,23 +13,51 @@ class Loader extends PIXI.Container{
|
|
|
|
|
|
|
|
|
|
let app = GameLayer.app;
|
|
let app = GameLayer.app;
|
|
|
|
+ GameLayer.toggleGui();
|
|
this.gui = GameLayer.gui();
|
|
this.gui = GameLayer.gui();
|
|
this.router = GameLayer.router();
|
|
this.router = GameLayer.router();
|
|
this.position.set(app.screen.width/2, app.screen.height/2);
|
|
this.position.set(app.screen.width/2, app.screen.height/2);
|
|
|
|
|
|
|
|
|
|
- this.controller = this.gui.add(this, 'component');
|
|
|
|
- this.controller.onFinishChange((value) => this.loadComponent(value));
|
|
|
|
|
|
+ this.controller = this.gui.add(this, 'component').listen();
|
|
|
|
+ this.controller.onFinishChange((value) => this.loadComponent({component: value}));
|
|
|
|
+
|
|
|
|
+ this.gui.add(this, 'save');
|
|
|
|
+ this.gui.add(this, 'load');
|
|
|
|
|
|
if(this.component)
|
|
if(this.component)
|
|
- this.loadComponent(this.component);
|
|
|
|
|
|
+ this.loadComponent({component: this.component});
|
|
}
|
|
}
|
|
|
|
|
|
destroy() {
|
|
destroy() {
|
|
this.controller.remove();
|
|
this.controller.remove();
|
|
|
|
+ this.GameLayer.toggleGui();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ load = () => {
|
|
|
|
+ var loadJSON = prompt("Enter load info...", "");
|
|
|
|
+
|
|
|
|
+ let jsonData = null;
|
|
|
|
+ try {
|
|
|
|
+ jsonData = JSON.parse(loadJSON);
|
|
|
|
+ } catch (e) {
|
|
|
|
+ alert("Error parsing input data!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.loadComponent(jsonData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ save = () => {
|
|
|
|
+ let data = JSON.stringify(this.instance.getAsJSON());
|
|
|
|
+ alert(data);
|
|
}
|
|
}
|
|
|
|
|
|
- loadComponent = (component) => {
|
|
|
|
|
|
+ loadComponent = (params) => {
|
|
|
|
+ let {
|
|
|
|
+ component,
|
|
|
|
+ ...props
|
|
|
|
+ } = params;
|
|
|
|
+ this.component = component;
|
|
if (this.instance) {
|
|
if (this.instance) {
|
|
this.removeChild(this.instance);
|
|
this.removeChild(this.instance);
|
|
this.instance._kill();
|
|
this.instance._kill();
|
|
@@ -37,7 +65,7 @@ class Loader extends PIXI.Container{
|
|
try {
|
|
try {
|
|
if (component.length < 3) return;
|
|
if (component.length < 3) return;
|
|
let ctor = require('../Game/misc/' + component).default;
|
|
let ctor = require('../Game/misc/' + component).default;
|
|
- this.instance = new ctor({GameLayer: this.GameLayer, Router: this.router, Gui: this.gui});
|
|
|
|
|
|
+ this.instance = new ctor({GameLayer: this.GameLayer, Router: this.router, Gui: this.gui, ...props});
|
|
this.addChild(this.instance);
|
|
this.addChild(this.instance);
|
|
} catch(e) {
|
|
} catch(e) {
|
|
throw e;
|
|
throw e;
|