Commit 38573477 authored by rockyl's avatar rockyl

整理结构

parent 96ca6c5a
......@@ -2172,8 +2172,9 @@
function VM() {
}
VM.prototype.setup = function (context) {
var processMetaContexts = context.processMetaContexts;
this._processMetaContexts = processMetaContexts;
var processMetaLibs = context.processMetaLibs, globalContext = context.globalContext;
this._processMetaLibs = processMetaLibs;
this._globalContext = globalContext;
};
VM.prototype.executeProcess = function (sequence, id, parentProcess, args) {
return __awaiter(this, void 0, void 0, function () {
......@@ -2195,7 +2196,7 @@
});
};
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 meta = arrayFind(context, function (item) { return item.id === id; });
if (meta) {
......@@ -2203,25 +2204,36 @@
}
}
};
VM.prototype.getGlobal = function () {
return this._globalContext;
};
return VM;
}());
var processMetaContexts = [];
function setProcessMetaContexts() {
var processMetaLibs = [];
var globalContext = {};
function setProcessMetaLibs() {
var metaContexts = [];
for (var _i = 0; _i < arguments.length; _i++) {
metaContexts[_i] = arguments[_i];
}
for (var _a = 0, metaContexts_1 = metaContexts; _a < metaContexts_1.length; _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) {
if (subEntry === void 0) { subEntry = 'main'; }
var vm = new VM();
vm.setup({
processMetaContexts: processMetaContexts,
processMetaLibs: processMetaLibs,
globalContext: globalContext,
});
vm.executeProcess(sequence, subEntry, null, args)
.then(function (result) {
......@@ -2259,7 +2271,7 @@
if (eventConfig) {
executeBehavior({
main: eventConfig.behaviors[0],
}, 'main', 'aaa');
}, 'main');
}
}
};
......@@ -11471,7 +11483,7 @@
GameStage.prototype.start = function () {
var _a = this._config, launchOptions = _a.launchOptions, dataMapping = _a.dataMapping, processes = _a.processes, globalProcesses = _a.globalProcesses;
this.dataCenter.registerDataMapping(dataMapping);
setProcessMetaContexts(processes, globalProcesses);
setProcessMetaLibs(processes, globalProcesses);
var entryViewName = launchOptions.entrySceneView;
var entryViewConfig = this.getViewConfigByName(entryViewName);
if (entryViewConfig) {
......@@ -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);
Stage.flushAll();
var gameStage = new GameStage(stage);
setGlobalContext({
gameStage: gameStage
});
stage.addChild(gameStage);
setTimeout(function () {
gameStage.launch(config, onAssetsProgress, onAssetsComplete);
......@@ -11502,7 +11517,6 @@
exports.BaseTexture = BaseTexture;
exports.Button = Button;
exports.Circle = Circle$1;
exports.Component = Component;
exports.Container = Container;
exports.DATA_URI = DATA_URI;
......@@ -11513,24 +11527,19 @@
exports.EventDispatcher = EventDispatcher;
exports.FloatDisplay = FloatDisplay;
exports.GDispatcher = GDispatcher;
exports.GameStage = GameStage;
exports.Graphics = Graphics;
exports.Image = Image$1;
exports.InputText = InputText;
exports.Label = Label;
exports.Loader = Loader;
exports.Matrix = Matrix;
exports.MouseEvent = MouseEvent;
exports.PI_2 = PI_2;
exports.Point = Point;
exports.RAD_TO_DEG = RAD_TO_DEG;
exports.Rect = Rect;
exports.Rectangle = Rectangle;
exports.ScrollList = ScrollList;
exports.ScrollPage = ScrollPage;
exports.Shape = Shape;
exports.Sprite = Sprite;
exports.StackContainer = StackContainer;
exports.Stage = Stage;
exports.StageScaleMode = StageScaleMode;
exports.TextField = TextField;
......@@ -11538,18 +11547,12 @@
exports.TextureSheet = TextureSheet;
exports.URL_FILE_EXTENSION = URL_FILE_EXTENSION;
exports.VERSION = VERSION;
exports.applyAutoAdjust = applyAutoAdjust;
exports.applyEvents = applyEvents;
exports.applyScript = applyScript;
exports.cos = cos;
exports.devicePixelRatio = devicePixelRatio;
exports.getAssetByName = getAssetByName;
exports.getAssetByUUID = getAssetByUUID;
exports.getTexture = getTexture;
exports.inputFeildIosEnable = inputFeildIosEnable;
exports.instantiate = instantiate;
exports.launch = launch;
exports.loadAssets = loadAssets;
exports.osType = osType;
exports.registerScriptDef = registerScriptDef;
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 @@
engine.registerScriptDef(ScriptDemo);
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";
import {arrayFind} from "../utils";
export class VM {
_processMetaContexts;
_processMetaLibs;
_globalContext;
setup(context) {
const {processMetaContexts} = context;
const {processMetaLibs, globalContext} = context;
this._processMetaContexts = processMetaContexts;
this._processMetaLibs = processMetaLibs;
this._globalContext = globalContext;
}
async executeProcess(sequence, id, parentProcess, args) {
......@@ -27,11 +29,15 @@ export class VM {
}
getMeta(id) {
for (let context of this._processMetaContexts) {
for (let context of this._processMetaLibs) {
let meta = arrayFind(context, item => item.id === id);
if (meta) {
return meta;
}
}
}
getGlobal(){
return this._globalContext;
}
}
......@@ -4,18 +4,27 @@
import {VM} from "./VM";
let processMetaContexts = [];
let processMetaLibs = [];
let globalContext = {};
export function setProcessMetaContexts(...metaContexts) {
for(let context of metaContexts){
processMetaContexts.push(context);
export function setProcessMetaLibs(...metaContexts) {
for (let context of metaContexts) {
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?) {
const vm = new VM();
vm.setup({
processMetaContexts,
processMetaLibs,
globalContext,
});
vm.executeProcess(sequence, subEntry, null, args)
.then(result => {
......
......@@ -42,7 +42,7 @@ class EventsProxy extends HashObject {
if (eventConfig) {
executeBehavior({
main: eventConfig.behaviors[0],
}, 'main', 'aaa')
}, 'main')
}
}
}
......
......@@ -2,12 +2,12 @@
* Created by rockyl on 2019-11-05.
*/
import {Container, Stage} from "../2d/display";
import {Container, Stage} from "../../2d/display";
import {StackContainer} from "./StackContainer";
import {loadAssets} from "./assets-manager";
import {instantiate} from "./view-interpreter";
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 {
start() {
const {launchOptions, dataMapping, processes, globalProcesses} = this._config;
this.dataCenter.registerDataMapping(dataMapping);
setProcessMetaContexts(processes, globalProcesses);
setProcessMetaLibs(processes, globalProcesses);
const entryViewName = launchOptions.entrySceneView;
let entryViewConfig = this.getViewConfigByName(entryViewName);
if (entryViewConfig) {
......
......@@ -2,7 +2,7 @@
* 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.
*/
import {Loader} from "..";
import {Loader} from "../..";
let assetsConfig;
......
......@@ -3,8 +3,8 @@
*
* 数据中心
*/
import {EventDispatcher} from "../2d/events";
import {arrayFind} from "./utils";
import {EventDispatcher} from "../../2d/events";
import {arrayFind} from "../utils";
/**
* 数据中心
......
/**
* Created by rockyl on 2019-11-12.
*/
export * from './GameStage'
/**
* Created by rockyl on 2019-11-07.
*/
import {Sprite} from "../../2d/display";
import Texture from "../../2d/texture/Texture";
import {Sprite} from "../../../2d/display";
import Texture from "../../../2d/texture/Texture";
import {getAssetByName, getAssetByUUID} from "../assets-manager";
import {dataCenter} from "../data-center";
import {ESCAPE_REG_EXP} from "../utils";
import {ESCAPE_REG_EXP} from "../../utils";
const assetScheme = 'asset://';
......
/**
* Created by rockyl on 2019-11-08.
*/
import {TextField} from "../../2d/text";
import {TextField} from "../../../2d/text";
import {dataCenter} from "../data-center";
import {ESCAPE_REG_EXP} from "../utils";
import {ESCAPE_REG_EXP} from "../../utils";
/**
* 文本
......
/**
* Created by rockyl on 2019-11-06.
*/
import {Shape} from "../../";
import {Event} from "../../2d/events";
import {dirtyFieldDetector} from "../decorators";
import {Shape} from "../../../";
import {Event} from "../../../2d/events";
import {dirtyFieldDetector} from "../../decorators";
/**
* 图形基类
......
......@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-08.
*/
import {Container} from "../2d/display";
import {Container} from "../../2d/display";
import {Rect, Image, Label} from "./nodes";
const nodeTypeMapping = {
......
......@@ -2,12 +2,5 @@
* 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 './decorators/auto-adjust'
export * from './decorators/scripts'
export * from './decorators/events'
......@@ -3,7 +3,9 @@
*/
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) {
const {containerID, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.launchOptions;
......@@ -18,6 +20,9 @@ export function launch(config, onAssetsProgress, onAssetsComplete) {
Stage.flushAll();
let gameStage = new GameStage(stage);
setGlobalContext({
gameStage
});
stage.addChild(gameStage);
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