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?) { ...@@ -61,9 +61,7 @@ export function executeBehavior(sequence, subEntry = 'main', target, args?) {
return result; return result;
}, },
e => { 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 { ...@@ -100,6 +100,7 @@ export class GameStage extends Node {
* @param config * @param config
* @param onAssetsProgress * @param onAssetsProgress
* @param onAssetsComplete * @param onAssetsComplete
* @param onStart
*/ */
async launch(config, onAssetsProgress?, onAssetsComplete?, onStart?) { async launch(config, onAssetsProgress?, onAssetsComplete?, onStart?) {
this._config = config; this._config = config;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-08. * 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 {registerCustomModuleFromConfig, registerScripts, RENDERER_TYPE, setProcessMetaLibs, StageScaleMode} from "..";
import {GameStage} from "./game-warpper/index"; import {GameStage} from "./game-warpper/index";
import {setGlobalContext} from "./behavior-runtime"; import {setGlobalContext} from "./behavior-runtime";
...@@ -11,8 +11,12 @@ import {Event} from "../2d/events/Event"; ...@@ -11,8 +11,12 @@ import {Event} from "../2d/events/Event";
import builtinLoadingView from "./game-warpper/LoadingView"; import builtinLoadingView from "./game-warpper/LoadingView";
import {queryParams} from "./web"; import {queryParams} from "./web";
import {initAutoLayout} from "./game-warpper/auto-layout"; import {initAutoLayout} from "./game-warpper/auto-layout";
import {EditorStage} from "./game-warpper/EditorStage";
export let gameStage: GameStage; export let gameStage: GameStage;
export let editorStage: EditorStage;
export let editorMode = false;
export function launch(url, loadingDelegate?, onStart?) { export function launch(url, loadingDelegate?, onStart?) {
if (queryParams.__proxy_mode__) { if (queryParams.__proxy_mode__) {
...@@ -51,7 +55,9 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) { ...@@ -51,7 +55,9 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
setTimeout(resolve, 300); setTimeout(resolve, 300);
}); });
return await new Promise(resolve => { 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( let stage = window['stage'] = new Stage(
containerId || "game-container", containerId || "game-container",
designWidth || 750, designWidth || 750,
...@@ -64,6 +70,11 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) { ...@@ -64,6 +70,11 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
Stage.flushAll(); Stage.flushAll();
stage.addEventListener(Event.ON_INIT_STAGE, () => { stage.addEventListener(Event.ON_INIT_STAGE, () => {
if (editorMode) {
editorStage = new EditorStage(stage);
stage.addChild(editorStage);
editorStage.launch(onStart)
} else {
gameStage = new GameStage(stage); gameStage = new GameStage(stage);
setGlobalContext({ setGlobalContext({
gameStage gameStage
...@@ -77,8 +88,9 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) { ...@@ -77,8 +88,9 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
}, function () { }, function () {
delegate.onComplete && delegate.onComplete(); delegate.onComplete && delegate.onComplete();
}, onStart); }, 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