Commit 6fd2ea06 authored by rockyl's avatar rockyl

提交一波

parent 5753aeeb
This diff is collapsed.
This diff is collapsed.
......@@ -61,9 +61,7 @@ export function executeBehavior(sequence, subEntry = 'main', target, args?) {
return result;
},
e => {
if(log){
console.log(`[${vm.id}] terminate:`, e);
}
console.log(`[${vm.id}] terminate:`, e);
}
);
}
/**
* Created by rockyl on 2019-11-05.
*/
import {Stage} from "../../2d/display/index";
import {Node} from "./nodes/Node";
import {instantiate} from "./view-interpreter";
import {injectProperties} from "../utils/utils";
/**
* 编辑器舞台
*/
export class EditorStage extends Node {
private _view: Node;
constructor(stage: Stage) {
super();
this.name = 'editor-stage';
this.addEventListener('modify-props', this.onModifyProps, this);
}
launch(onStart) {
onStart();
}
showView(viewConfig) {
if (this._view) {
this.removeChild(this._view);
}
let view = this._view = instantiate(viewConfig);
this.addChild(view);
}
getNodeProps(nodePath) {
return this._view.getChildByIndexPath(nodePath);
}
private onModifyProps(e) {
console.log(e.data);
const {nodePath, props} = e.data;
let node = this._view.getChildByIndexPath(nodePath);
if (node) {
injectProperties(node, props);
} else {
console.warn('node not found:', nodePath);
}
}
}
......@@ -100,6 +100,7 @@ export class GameStage extends Node {
* @param config
* @param onAssetsProgress
* @param onAssetsComplete
* @param onStart
*/
async launch(config, onAssetsProgress?, onAssetsComplete?, onStart?) {
this._config = config;
......
......@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-08.
*/
import {Stage} from "../2d/display";
import {Stage} from "../2d/display/index";
import {registerCustomModuleFromConfig, registerScripts, RENDERER_TYPE, setProcessMetaLibs, StageScaleMode} from "..";
import {GameStage} from "./game-warpper/index";
import {setGlobalContext} from "./behavior-runtime";
......@@ -11,8 +11,12 @@ import {Event} from "../2d/events/Event";
import builtinLoadingView from "./game-warpper/LoadingView";
import {queryParams} from "./web";
import {initAutoLayout} from "./game-warpper/auto-layout";
import {EditorStage} from "./game-warpper/EditorStage";
export let gameStage: GameStage;
export let editorStage: EditorStage;
export let editorMode = false;
export function launch(url, loadingDelegate?, onStart?) {
if (queryParams.__proxy_mode__) {
......@@ -51,7 +55,9 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
setTimeout(resolve, 300);
});
return await new Promise(resolve => {
const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.options;
const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType, editorMode: _editorMode,} = config.options;
editorMode = _editorMode;
let stage = window['stage'] = new Stage(
containerId || "game-container",
designWidth || 750,
......@@ -64,21 +70,27 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
Stage.flushAll();
stage.addEventListener(Event.ON_INIT_STAGE, () => {
gameStage = new GameStage(stage);
setGlobalContext({
gameStage
});
stage.addChild(gameStage);
let delegate = loadingDelegate || builtinLoadingView;
gameStage.launch(config, function (done, total) {
delegate.onProgress && delegate.onProgress(done, total)
}, function () {
delegate.onComplete && delegate.onComplete();
}, onStart);
if (editorMode) {
editorStage = new EditorStage(stage);
stage.addChild(editorStage);
editorStage.launch(onStart)
} else {
gameStage = new GameStage(stage);
setGlobalContext({
gameStage
});
stage.addChild(gameStage);
let delegate = loadingDelegate || builtinLoadingView;
gameStage.launch(config, function (done, total) {
delegate.onProgress && delegate.onProgress(done, total)
}, function () {
delegate.onComplete && delegate.onComplete();
}, onStart);
}
});
resolve(gameStage);
resolve();
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment