Browse Source

Added url params

Nikatlas 6 years ago
parent
commit
64d1aab320

BIN
public/files/assets/board.png


BIN
src/Game/assets/board.png


+ 23 - 1
src/Game/misc/Button.js

@@ -1,25 +1,47 @@
 import * as PIXI from 'pixi.js';
 import Text from './Text.js';
+import { getParam } from '../../helpers/url';
+
+
+const DefaultImageUrl = '/files/assets/ui/woodenbutton.png';
+const DefaultImage = PIXI.Texture.fromImage(DefaultImageUrl);
 
 class Button extends PIXI.Sprite{
     constructor(props) {
-        super(PIXI.Texture.fromImage('/files/assets/ui/woodenbutton.png'));
+        super(DefaultImage);
         let {
             image,
             text,
             Gui
         } = props;
 
+        this.imageURL = image || getParam('imageURL') || DefaultImageUrl;
+        if(Gui) {
+            this.Gui = Gui;
+            this.controller = Gui.add(this, 'imageURL').onFinishChange((v) => this.loadImage(v));
+        }
+
         this.anchor.set(0.5,0.5);
         this.interactive = true;
         this.buttonMode = true;
 
         this.textNode = new Text(props);
         this.addChild(this.textNode);
+
+        this.loadImage(this.imageURL);
     }
 
+    loadImage(img) {
+        this.imageURL = img;
+        this.setTexture(PIXI.Texture.fromImage(img));
+    }
+
+    setTexture(texture) {
+        this.texture = texture;
+    }
 
     _kill() {
+        this.controller.remove();
         this.textNode._kill();
         this.destroy();
     }

+ 10 - 4
src/Playground/Loader.js

@@ -1,4 +1,5 @@
 import * as PIXI from 'pixi.js';
+import { getParam } from '../helpers/url.js';
 
 class Loader extends PIXI.Container{
 
@@ -7,16 +8,21 @@ class Loader extends PIXI.Container{
 
         this.GameLayer = GameLayer;
 
-        this.component = '';
+        var comp = getParam('component');
+        this.component = comp || '';
+
 
         let app = GameLayer.app;
         this.gui = GameLayer.gui();
         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));
+
+        if(this.component)
+            this.loadComponent(this.component);
     }
 
     destroy() {
@@ -24,12 +30,12 @@ class Loader extends PIXI.Container{
     }
 
     loadComponent = (component) => {
-    	if(this.instance) {
+    	if (this.instance) {
     		this.removeChild(this.instance);
     		this.instance._kill();
     	}
     	try {
-    		if(component.length < 3)return;
+    		if (component.length < 3) return;
     		let ctor = require('../Game/misc/' + component).default;
     		this.instance = new ctor({GameLayer: this.GameLayer, Router: this.router, Gui: this.gui});
     		this.addChild(this.instance);

+ 4 - 0
src/helpers/url.js

@@ -0,0 +1,4 @@
+export function getParam(p) {
+    var url = new URL(window.location.href);
+    return url.searchParams.get(p);
+}