import Frame from './Frame'; import Button from './Button'; import Event from './../utils/Event'; import * as PIXI from './../com/pixi.min'; import Controller from "../core/Controller"; const {utils} = PIXI; class App extends Frame { scenes: any[]; assets: any[]; control: Controller; _assetsPath: string; _options: any; _version: string; isInitiated: boolean; b_resizeFull: Button; b_resizeBack: Button; constructor(name, soul, assets = [], _options) { super(soul); this.scenes = []; this.assets = assets; this.name = name; this._assetsPath = _options.assetsPath; this._options = _options; this._version = soul._version; this.preload(); } removeChild(child) { this.scenes.splice(this.scenes.indexOf(child), 1); super.removeChild(child); } addScene(child) { if (this.control) { this.control.addView(child); } this.scenes.push(child); this.addChild(child) } update(delta) { this.scenes.forEach(scene => { scene.update(delta); }) } preload() { let loaded = 0; let loader = PIXI.Loader.shared; this.assets.forEach(item => { // info(this._assetsPath + item.file, PIXI.loader.resources[item.name], PIXI.loader.resources[this.assetsPath + item.file]); if (loader.resources[this._assetsPath + item.file] || loader.resources[item.name]) { loaded++; } else { if (item.type === 'font') { // info(item.name, this.assetsPath + item.file); loader.add(item.name, this._assetsPath + item.file); } else { if (item.type === 'image') { loader.add(item.name, this._assetsPath + item.file); } else { loader.add(this._assetsPath + item.file); } } } }); loader.load((e) => { if (e.progress === 100) { this.init(); e.destroy(); } }); } resizeForce() { this.resize(this.W, this.H, true); } resize(w, h, force = false) { if (this.W !== w || this.H !== h || force) { const ow = this.soul.OW; const oh = this.soul.OH; super.resize(ow, oh); if (this.scenes) { this.scenes.forEach(scene => { scene.resize(ow, oh); }); } if (this.isInitiated) { if (this.b_resizeFull) { let w = this.b_resizeFull.width * .9; this.b_resizeFull.move(this.W - w * .9, this.H - w); this.b_resizeBack.move(this.W - w * .9, this.H - w); } } } } init() { this.isInitiated = true; console.log({textures: utils.TextureCache}); console.log('----------------------------------------------'); } destroy() { console.log('DELETE', window['PIXI']); } /// resize button initResizeButton(fullImg = 'i_full', windowImg = 'i_full_exit') { const alpha = .8; const size = .4; this.addChild(this.b_resizeFull = new Button({tex: fullImg, s: .8 * size, a: alpha})); this.addChild(this.b_resizeBack = new Button({tex: windowImg, s: .8 * size, a: alpha})); this.b_resizeFull.visible = !this.soul.isFullScreen; this.b_resizeBack.visible = this.soul.isFullScreen; this.b_resizeFull.on(Event.BUTTON_CLICK, this.h_buttons); this.b_resizeBack.on(Event.BUTTON_CLICK, this.h_buttons); } // events --------------- h_buttons() { let app = this.parent; switch (this) { case app.b_resizeBack: app.b_resizeBack.visible = false; app.b_resizeFull.visible = true; app.soul.fullscreen(); break; case app.b_resizeFull: app.b_resizeBack.visible = true; app.b_resizeFull.visible = false; app.soul.fullscreen(); break; } } } export default App;