Commit 88b0d47d authored by rockyl's avatar rockyl

内联过程实现

parent 977e31bb
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
* 过程 * 过程
*/ */
import {VM} from "./VM"; import {VM} from "./VM";
import {linkedFlag, nodeScheme, objClone} from "../utils"; import {getDataByPath, linkedFlag, nodeScheme, objClone} from "../utils";
import {findNodeByUUID} from "../node-utils"; import {findNodeByUUID} from "../node-utils";
import {dataCenter} from "../game-warpper/data-center";
const log = true; const log = true;
...@@ -92,7 +93,7 @@ export class Process { ...@@ -92,7 +93,7 @@ export class Process {
if (metaConfig) { if (metaConfig) {
if (metaConfig.script) { if (metaConfig.script) {
let func = new Function('args', 'props', 'target', 'global', warpAsyncScript(metaConfig.script)); let func = new Function('args', 'props', 'target', 'global', warpAsyncScript(metaConfig.script));
this.updateProps(); this.updateProps(payload);
result = await func(payload, this._config.props, this._target, this._vm.getGlobalContext()); result = await func(payload, this._config.props, this._target, this._vm.getGlobalContext());
} }
} else { } else {
...@@ -138,7 +139,15 @@ export class Process { ...@@ -138,7 +139,15 @@ export class Process {
* @return {null} * @return {null}
*/ */
getProcessMeta(id) { getProcessMeta(id) {
let meta = this._meta && this._meta.metas ? this._meta.metas[id] : null; let meta;
if (this._meta && this._meta.metas) { //如果有内联过程
for (let temp of this._meta.metas) {
if (temp.id === id) {
meta = temp;
break;
}
}
}
if (!meta) { if (!meta) {
meta = this._parent ? this._parent.getProcessMeta(id) : null; meta = this._parent ? this._parent.getProcessMeta(id) : null;
} }
...@@ -161,15 +170,29 @@ export class Process { ...@@ -161,15 +170,29 @@ export class Process {
/** /**
* 更新props * 更新props
*/ */
updateProps() { updateProps(args) {
if (this._originProps) { if (this._originProps) {
let props = this._config.props; let props = this._config.props;
for (let key in props) { for (let key in props) {
let value = this._originProps[key]; let value = this._originProps[key];
if (typeof value == 'object') { const valueType = typeof value;
let linkedValue = this.resolveLinkedProp(value, key); if (valueType == 'object') {
if (linkedValue !== undefined) { switch (value.type) {
props[key] = linkedValue; case 'link':
let linkedValue = this.resolveLinkedProp(value, key);
if (linkedValue !== undefined) {
props[key] = linkedValue;
}
break;
case 'static':
props[key] = value.value;
break;
case 'arguments':
props[key] = args ? getDataByPath(args, value.value) : undefined;
break;
case 'data-center':
props[key] = dataCenter.getDataByPath(value.value);
break;
} }
} else if (value && value.indexOf && value.indexOf(nodeScheme) === 0) { } else if (value && value.indexOf && value.indexOf(nodeScheme) === 0) {
let uuid = value.replace(nodeScheme, ''); let uuid = value.replace(nodeScheme, '');
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* 数据中心 * 数据中心
*/ */
import {EventDispatcher} from "../../2d/events"; import {EventDispatcher} from "../../2d/events";
import {arrayFind} from "../utils"; import {arrayFind, getDataByPath} from "../utils";
import {DATA_CENTER_EVENT, globalEvent} from "../decorators/events"; import {DATA_CENTER_EVENT, globalEvent} from "../decorators/events";
/** /**
...@@ -49,15 +49,7 @@ export class DataCenter extends EventDispatcher { ...@@ -49,15 +49,7 @@ export class DataCenter extends EventDispatcher {
* @param throwException * @param throwException
*/ */
getDataByPath(path, throwException?) { getDataByPath(path, throwException?) {
let func = new Function('scope', `return scope.${path}`); return getDataByPath(this.store, path, throwException);
try {
return func(this.store);
} catch (e) {
//console.warn(e);
if (throwException) {
throw e;
}
}
} }
/** /**
......
...@@ -35,3 +35,21 @@ export function propertyParse(key, node, properties) { ...@@ -35,3 +35,21 @@ export function propertyParse(key, node, properties) {
} }
node[targetKey] = value; node[targetKey] = value;
} }
/**
* 根据路径获取数据
* @param scope
* @param path
* @param throwException
*/
export function getDataByPath(scope, path, throwException?){
let func = new Function('scope', `return scope.${path}`);
try {
return func(scope);
} catch (e) {
//console.warn(e);
if (throwException) {
throw e;
}
}
}
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