Commit 88b0d47d authored by rockyl's avatar rockyl

内联过程实现

parent 977e31bb
......@@ -4,8 +4,9 @@
* 过程
*/
import {VM} from "./VM";
import {linkedFlag, nodeScheme, objClone} from "../utils";
import {getDataByPath, linkedFlag, nodeScheme, objClone} from "../utils";
import {findNodeByUUID} from "../node-utils";
import {dataCenter} from "../game-warpper/data-center";
const log = true;
......@@ -92,7 +93,7 @@ export class Process {
if (metaConfig) {
if (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());
}
} else {
......@@ -138,7 +139,15 @@ export class Process {
* @return {null}
*/
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) {
meta = this._parent ? this._parent.getProcessMeta(id) : null;
}
......@@ -161,16 +170,30 @@ export class Process {
/**
* 更新props
*/
updateProps() {
updateProps(args) {
if (this._originProps) {
let props = this._config.props;
for (let key in props) {
let value = this._originProps[key];
if (typeof value == 'object') {
const valueType = typeof value;
if (valueType == 'object') {
switch (value.type) {
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) {
let uuid = value.replace(nodeScheme, '');
if (uuid) {
......
......@@ -4,7 +4,7 @@
* 数据中心
*/
import {EventDispatcher} from "../../2d/events";
import {arrayFind} from "../utils";
import {arrayFind, getDataByPath} from "../utils";
import {DATA_CENTER_EVENT, globalEvent} from "../decorators/events";
/**
......@@ -49,15 +49,7 @@ export class DataCenter extends EventDispatcher {
* @param throwException
*/
getDataByPath(path, throwException?) {
let func = new Function('scope', `return scope.${path}`);
try {
return func(this.store);
} catch (e) {
//console.warn(e);
if (throwException) {
throw e;
}
}
return getDataByPath(this.store, path, throwException);
}
/**
......
......@@ -35,3 +35,21 @@ export function propertyParse(key, node, properties) {
}
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