Commit 38573477 authored by rockyl's avatar rockyl

整理结构

parent 96ca6c5a
...@@ -2172,8 +2172,9 @@ ...@@ -2172,8 +2172,9 @@
function VM() { function VM() {
} }
VM.prototype.setup = function (context) { VM.prototype.setup = function (context) {
var processMetaContexts = context.processMetaContexts; var processMetaLibs = context.processMetaLibs, globalContext = context.globalContext;
this._processMetaContexts = processMetaContexts; this._processMetaLibs = processMetaLibs;
this._globalContext = globalContext;
}; };
VM.prototype.executeProcess = function (sequence, id, parentProcess, args) { VM.prototype.executeProcess = function (sequence, id, parentProcess, args) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
...@@ -2195,7 +2196,7 @@ ...@@ -2195,7 +2196,7 @@
}); });
}; };
VM.prototype.getMeta = function (id) { VM.prototype.getMeta = function (id) {
for (var _i = 0, _a = this._processMetaContexts; _i < _a.length; _i++) { for (var _i = 0, _a = this._processMetaLibs; _i < _a.length; _i++) {
var context = _a[_i]; var context = _a[_i];
var meta = arrayFind(context, function (item) { return item.id === id; }); var meta = arrayFind(context, function (item) { return item.id === id; });
if (meta) { if (meta) {
...@@ -2203,25 +2204,36 @@ ...@@ -2203,25 +2204,36 @@
} }
} }
}; };
VM.prototype.getGlobal = function () {
return this._globalContext;
};
return VM; return VM;
}()); }());
var processMetaContexts = []; var processMetaLibs = [];
function setProcessMetaContexts() { var globalContext = {};
function setProcessMetaLibs() {
var metaContexts = []; var metaContexts = [];
for (var _i = 0; _i < arguments.length; _i++) { for (var _i = 0; _i < arguments.length; _i++) {
metaContexts[_i] = arguments[_i]; metaContexts[_i] = arguments[_i];
} }
for (var _a = 0, metaContexts_1 = metaContexts; _a < metaContexts_1.length; _a++) { for (var _a = 0, metaContexts_1 = metaContexts; _a < metaContexts_1.length; _a++) {
var context = metaContexts_1[_a]; var context = metaContexts_1[_a];
processMetaContexts.push(context); processMetaLibs.push(context);
}
}
function setGlobalContext(context) {
globalContext = context;
for (var key in context) {
globalContext[key] = context[key];
} }
} }
function executeBehavior(sequence, subEntry, args) { function executeBehavior(sequence, subEntry, args) {
if (subEntry === void 0) { subEntry = 'main'; } if (subEntry === void 0) { subEntry = 'main'; }
var vm = new VM(); var vm = new VM();
vm.setup({ vm.setup({
processMetaContexts: processMetaContexts, processMetaLibs: processMetaLibs,
globalContext: globalContext,
}); });
vm.executeProcess(sequence, subEntry, null, args) vm.executeProcess(sequence, subEntry, null, args)
.then(function (result) { .then(function (result) {
...@@ -2259,7 +2271,7 @@ ...@@ -2259,7 +2271,7 @@
if (eventConfig) { if (eventConfig) {
executeBehavior({ executeBehavior({
main: eventConfig.behaviors[0], main: eventConfig.behaviors[0],
}, 'main', 'aaa'); }, 'main');
} }
} }
}; };
...@@ -11471,7 +11483,7 @@ ...@@ -11471,7 +11483,7 @@
GameStage.prototype.start = function () { GameStage.prototype.start = function () {
var _a = this._config, launchOptions = _a.launchOptions, dataMapping = _a.dataMapping, processes = _a.processes, globalProcesses = _a.globalProcesses; var _a = this._config, launchOptions = _a.launchOptions, dataMapping = _a.dataMapping, processes = _a.processes, globalProcesses = _a.globalProcesses;
this.dataCenter.registerDataMapping(dataMapping); this.dataCenter.registerDataMapping(dataMapping);
setProcessMetaContexts(processes, globalProcesses); setProcessMetaLibs(processes, globalProcesses);
var entryViewName = launchOptions.entrySceneView; var entryViewName = launchOptions.entrySceneView;
var entryViewConfig = this.getViewConfigByName(entryViewName); var entryViewConfig = this.getViewConfigByName(entryViewName);
if (entryViewConfig) { if (entryViewConfig) {
...@@ -11493,6 +11505,9 @@ ...@@ -11493,6 +11505,9 @@
var stage = window['stage'] = new Stage(containerID || "game-container", designWidth || 750, designHeight || 1334, frameRate || 60, scaleMode || StageScaleMode.FIXED_WIDTH, rendererType || exports.RENDERER_TYPE.WEBGL); var stage = window['stage'] = new Stage(containerID || "game-container", designWidth || 750, designHeight || 1334, frameRate || 60, scaleMode || StageScaleMode.FIXED_WIDTH, rendererType || exports.RENDERER_TYPE.WEBGL);
Stage.flushAll(); Stage.flushAll();
var gameStage = new GameStage(stage); var gameStage = new GameStage(stage);
setGlobalContext({
gameStage: gameStage
});
stage.addChild(gameStage); stage.addChild(gameStage);
setTimeout(function () { setTimeout(function () {
gameStage.launch(config, onAssetsProgress, onAssetsComplete); gameStage.launch(config, onAssetsProgress, onAssetsComplete);
...@@ -11502,7 +11517,6 @@ ...@@ -11502,7 +11517,6 @@
exports.BaseTexture = BaseTexture; exports.BaseTexture = BaseTexture;
exports.Button = Button; exports.Button = Button;
exports.Circle = Circle$1;
exports.Component = Component; exports.Component = Component;
exports.Container = Container; exports.Container = Container;
exports.DATA_URI = DATA_URI; exports.DATA_URI = DATA_URI;
...@@ -11513,24 +11527,19 @@ ...@@ -11513,24 +11527,19 @@
exports.EventDispatcher = EventDispatcher; exports.EventDispatcher = EventDispatcher;
exports.FloatDisplay = FloatDisplay; exports.FloatDisplay = FloatDisplay;
exports.GDispatcher = GDispatcher; exports.GDispatcher = GDispatcher;
exports.GameStage = GameStage;
exports.Graphics = Graphics; exports.Graphics = Graphics;
exports.Image = Image$1;
exports.InputText = InputText; exports.InputText = InputText;
exports.Label = Label;
exports.Loader = Loader; exports.Loader = Loader;
exports.Matrix = Matrix; exports.Matrix = Matrix;
exports.MouseEvent = MouseEvent; exports.MouseEvent = MouseEvent;
exports.PI_2 = PI_2; exports.PI_2 = PI_2;
exports.Point = Point; exports.Point = Point;
exports.RAD_TO_DEG = RAD_TO_DEG; exports.RAD_TO_DEG = RAD_TO_DEG;
exports.Rect = Rect;
exports.Rectangle = Rectangle; exports.Rectangle = Rectangle;
exports.ScrollList = ScrollList; exports.ScrollList = ScrollList;
exports.ScrollPage = ScrollPage; exports.ScrollPage = ScrollPage;
exports.Shape = Shape; exports.Shape = Shape;
exports.Sprite = Sprite; exports.Sprite = Sprite;
exports.StackContainer = StackContainer;
exports.Stage = Stage; exports.Stage = Stage;
exports.StageScaleMode = StageScaleMode; exports.StageScaleMode = StageScaleMode;
exports.TextField = TextField; exports.TextField = TextField;
...@@ -11538,18 +11547,12 @@ ...@@ -11538,18 +11547,12 @@
exports.TextureSheet = TextureSheet; exports.TextureSheet = TextureSheet;
exports.URL_FILE_EXTENSION = URL_FILE_EXTENSION; exports.URL_FILE_EXTENSION = URL_FILE_EXTENSION;
exports.VERSION = VERSION; exports.VERSION = VERSION;
exports.applyAutoAdjust = applyAutoAdjust;
exports.applyEvents = applyEvents;
exports.applyScript = applyScript; exports.applyScript = applyScript;
exports.cos = cos; exports.cos = cos;
exports.devicePixelRatio = devicePixelRatio; exports.devicePixelRatio = devicePixelRatio;
exports.getAssetByName = getAssetByName;
exports.getAssetByUUID = getAssetByUUID;
exports.getTexture = getTexture; exports.getTexture = getTexture;
exports.inputFeildIosEnable = inputFeildIosEnable; exports.inputFeildIosEnable = inputFeildIosEnable;
exports.instantiate = instantiate;
exports.launch = launch; exports.launch = launch;
exports.loadAssets = loadAssets;
exports.osType = osType; exports.osType = osType;
exports.registerScriptDef = registerScriptDef; exports.registerScriptDef = registerScriptDef;
exports.sin = sin; exports.sin = sin;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -5,25 +5,3 @@ ...@@ -5,25 +5,3 @@
engine.registerScriptDef(ScriptDemo); engine.registerScriptDef(ScriptDemo);
const gameStage = engine.launch(data); const gameStage = engine.launch(data);
/*const dataCenter = gameStage.dataCenter;
dataCenter.registerGroup('test', {
hello: {
aaa: {
name: 'tom',
id: 1001,
age: 29,
avatar: 'face',
}
}
});
/!*console.log(dataCenter.getDataByPath('test.hello.aaa.name'));*!/
let i = 0;
setInterval(()=>{
let asset = data.assets[i % data.assets.length];
dataCenter.mutate('test', asset.name, 'hello.aaa.name');
dataCenter.mutate('test', asset.name, 'hello.aaa.avatar');
i++;
}, 1000);*/
...@@ -6,12 +6,14 @@ import {Process} from "./Process"; ...@@ -6,12 +6,14 @@ import {Process} from "./Process";
import {arrayFind} from "../utils"; import {arrayFind} from "../utils";
export class VM { export class VM {
_processMetaContexts; _processMetaLibs;
_globalContext;
setup(context) { setup(context) {
const {processMetaContexts} = context; const {processMetaLibs, globalContext} = context;
this._processMetaContexts = processMetaContexts; this._processMetaLibs = processMetaLibs;
this._globalContext = globalContext;
} }
async executeProcess(sequence, id, parentProcess, args) { async executeProcess(sequence, id, parentProcess, args) {
...@@ -27,11 +29,15 @@ export class VM { ...@@ -27,11 +29,15 @@ export class VM {
} }
getMeta(id) { getMeta(id) {
for (let context of this._processMetaContexts) { for (let context of this._processMetaLibs) {
let meta = arrayFind(context, item => item.id === id); let meta = arrayFind(context, item => item.id === id);
if (meta) { if (meta) {
return meta; return meta;
} }
} }
} }
getGlobal(){
return this._globalContext;
}
} }
...@@ -4,18 +4,27 @@ ...@@ -4,18 +4,27 @@
import {VM} from "./VM"; import {VM} from "./VM";
let processMetaContexts = []; let processMetaLibs = [];
let globalContext = {};
export function setProcessMetaContexts(...metaContexts) { export function setProcessMetaLibs(...metaContexts) {
for(let context of metaContexts){ for (let context of metaContexts) {
processMetaContexts.push(context); processMetaLibs.push(context);
}
}
export function setGlobalContext(context) {
globalContext = context;
for (let key in context) {
globalContext[key] = context[key];
} }
} }
export function executeBehavior(sequence, subEntry = 'main', args?) { export function executeBehavior(sequence, subEntry = 'main', args?) {
const vm = new VM(); const vm = new VM();
vm.setup({ vm.setup({
processMetaContexts, processMetaLibs,
globalContext,
}); });
vm.executeProcess(sequence, subEntry, null, args) vm.executeProcess(sequence, subEntry, null, args)
.then(result => { .then(result => {
......
...@@ -42,7 +42,7 @@ class EventsProxy extends HashObject { ...@@ -42,7 +42,7 @@ class EventsProxy extends HashObject {
if (eventConfig) { if (eventConfig) {
executeBehavior({ executeBehavior({
main: eventConfig.behaviors[0], main: eventConfig.behaviors[0],
}, 'main', 'aaa') }, 'main')
} }
} }
} }
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
* Created by rockyl on 2019-11-05. * Created by rockyl on 2019-11-05.
*/ */
import {Container, Stage} from "../2d/display"; import {Container, Stage} from "../../2d/display";
import {StackContainer} from "./StackContainer"; import {StackContainer} from "./StackContainer";
import {loadAssets} from "./assets-manager"; import {loadAssets} from "./assets-manager";
import {instantiate} from "./view-interpreter"; import {instantiate} from "./view-interpreter";
import {dataCenter, DataCenter} from "./data-center"; import {dataCenter, DataCenter} from "./data-center";
import {setProcessMetaContexts} from "./behavior-runtime"; import {setProcessMetaLibs} from "../behavior-runtime";
/** /**
* 游戏舞台 * 游戏舞台
...@@ -83,7 +83,7 @@ export class GameStage extends Container { ...@@ -83,7 +83,7 @@ export class GameStage extends Container {
start() { start() {
const {launchOptions, dataMapping, processes, globalProcesses} = this._config; const {launchOptions, dataMapping, processes, globalProcesses} = this._config;
this.dataCenter.registerDataMapping(dataMapping); this.dataCenter.registerDataMapping(dataMapping);
setProcessMetaContexts(processes, globalProcesses); setProcessMetaLibs(processes, globalProcesses);
const entryViewName = launchOptions.entrySceneView; const entryViewName = launchOptions.entrySceneView;
let entryViewConfig = this.getViewConfigByName(entryViewName); let entryViewConfig = this.getViewConfigByName(entryViewName);
if (entryViewConfig) { if (entryViewConfig) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-05. * Created by rockyl on 2019-11-05.
*/ */
import {Container, DisplayObject} from "../2d/display"; import {Container, DisplayObject} from "../../2d/display";
/** /**
* 栈式视图容器 * 栈式视图容器
......
/** /**
* Created by rockyl on 2019-11-07. * Created by rockyl on 2019-11-07.
*/ */
import {Loader} from ".."; import {Loader} from "../..";
let assetsConfig; let assetsConfig;
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
* *
* 数据中心 * 数据中心
*/ */
import {EventDispatcher} from "../2d/events"; import {EventDispatcher} from "../../2d/events";
import {arrayFind} from "./utils"; import {arrayFind} from "../utils";
/** /**
* 数据中心 * 数据中心
......
/**
* Created by rockyl on 2019-11-12.
*/
export * from './GameStage'
/** /**
* Created by rockyl on 2019-11-07. * Created by rockyl on 2019-11-07.
*/ */
import {Sprite} from "../../2d/display"; import {Sprite} from "../../../2d/display";
import Texture from "../../2d/texture/Texture"; import Texture from "../../../2d/texture/Texture";
import {getAssetByName, getAssetByUUID} from "../assets-manager"; import {getAssetByName, getAssetByUUID} from "../assets-manager";
import {dataCenter} from "../data-center"; import {dataCenter} from "../data-center";
import {ESCAPE_REG_EXP} from "../utils"; import {ESCAPE_REG_EXP} from "../../utils";
const assetScheme = 'asset://'; const assetScheme = 'asset://';
......
/** /**
* Created by rockyl on 2019-11-08. * Created by rockyl on 2019-11-08.
*/ */
import {TextField} from "../../2d/text"; import {TextField} from "../../../2d/text";
import {dataCenter} from "../data-center"; import {dataCenter} from "../data-center";
import {ESCAPE_REG_EXP} from "../utils"; import {ESCAPE_REG_EXP} from "../../utils";
/** /**
* 文本 * 文本
......
/** /**
* Created by rockyl on 2019-11-06. * Created by rockyl on 2019-11-06.
*/ */
import {Shape} from "../../"; import {Shape} from "../../../";
import {Event} from "../../2d/events"; import {Event} from "../../../2d/events";
import {dirtyFieldDetector} from "../decorators"; import {dirtyFieldDetector} from "../../decorators";
/** /**
* 图形基类 * 图形基类
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-08. * Created by rockyl on 2019-11-08.
*/ */
import {Container} from "../2d/display"; import {Container} from "../../2d/display";
import {Rect, Image, Label} from "./nodes"; import {Rect, Image, Label} from "./nodes";
const nodeTypeMapping = { const nodeTypeMapping = {
......
...@@ -2,12 +2,5 @@ ...@@ -2,12 +2,5 @@
* Created by rockyl on 2019-11-06. * Created by rockyl on 2019-11-06.
*/ */
export * from './GameStage'
export * from './StackContainer'
export * from './nodes'
export * from './assets-manager'
export * from './view-interpreter'
export * from './launcher' export * from './launcher'
export * from './decorators/auto-adjust'
export * from './decorators/scripts' export * from './decorators/scripts'
export * from './decorators/events'
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
*/ */
import {Stage} from "../2d/display"; import {Stage} from "../2d/display";
import {GameStage, Rect, RENDERER_TYPE, StageScaleMode} from ".."; import { RENDERER_TYPE, StageScaleMode} from "..";
import {GameStage} from "./game-warpper";
import {setGlobalContext} from "./behavior-runtime";
export function launch(config, onAssetsProgress, onAssetsComplete) { export function launch(config, onAssetsProgress, onAssetsComplete) {
const {containerID, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.launchOptions; const {containerID, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.launchOptions;
...@@ -18,6 +20,9 @@ export function launch(config, onAssetsProgress, onAssetsComplete) { ...@@ -18,6 +20,9 @@ export function launch(config, onAssetsProgress, onAssetsComplete) {
Stage.flushAll(); Stage.flushAll();
let gameStage = new GameStage(stage); let gameStage = new GameStage(stage);
setGlobalContext({
gameStage
});
stage.addChild(gameStage); stage.addChild(gameStage);
setTimeout(() => { setTimeout(() => {
......
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