Commit a8f6f07e authored by rockyl's avatar rockyl

增加加点拷贝功能

修复过程污染的问题
parent 3f014a42
......@@ -1776,6 +1776,11 @@
this._host.parent.removeEventListener(Event.RESIZE, this.onResize);
this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
};
AdjustProxy.prototype.setFrom = function (adjustProxy) {
for (var k in adjustProxy.data) {
this.data[k] = adjustProxy.data[k];
}
};
AdjustProxy.prototype.onResize = function (e) {
this._sizeDirty = true;
};
......@@ -1957,6 +1962,7 @@
var ESCAPE_REG_EXP = /\$\{[_a-zA-Z]\w*\}/g;
var linkedFlag = '$_linked_$';
var nodeScheme = 'node://';
function arrayFind(arr, callback) {
for (var i = 0, li = arr.length; i < li; i++) {
var item = arr[i];
......@@ -1965,10 +1971,39 @@
}
}
}
function objClone(obj) {
return JSON.parse(JSON.stringify(obj));
}
var percentKeys = ['width', 'height'];
function propertyParse(key, node, properties) {
var value = properties[key];
var targetKey = key;
if (percentKeys.indexOf(key) >= 0) {
if (typeof value === 'string') {
if (value[value.length - 1] === '%') {
targetKey = 'percent' + key[0].toUpperCase() + key.substr(1);
}
value = parseInt(value);
}
}
node[targetKey] = value;
}
function findNodeByUUID(node, uuid) {
if (node.uuid === uuid) {
return node;
}
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
var child = _a[_i];
var target = findNodeByUUID(child, uuid);
if (target) {
return target;
}
}
}
var Process = (function () {
function Process() {
this._heap = {};
}
Object.defineProperty(Process.prototype, "processConfig", {
get: function () {
......@@ -1984,13 +2019,6 @@
enumerable: true,
configurable: true
});
Object.defineProperty(Process.prototype, "heap", {
get: function () {
return this._heap;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Process.prototype, "sequence", {
get: function () {
return this._sequence;
......@@ -1999,11 +2027,15 @@
configurable: true
});
Process.prototype.init = function (context) {
var vm = context.vm, parent = context.parent, sequence = context.sequence, id = context.id;
var vm = context.vm, parent = context.parent, sequence = context.sequence, id = context.id, target = context.target;
this._vm = vm;
this._parent = parent;
this._config = sequence[id];
this._sequence = sequence;
this._target = target;
if (!this._originProps && this._config.props) {
this._originProps = objClone(this._config.props);
}
};
Process.prototype.execute = function (args) {
return __awaiter(this, void 0, void 0, function () {
......@@ -2019,9 +2051,6 @@
console.warn("meta [" + metaConfig + "] is not found");
return [2];
}
{
console.log("execute process [" + (this._config.alias || meta.name || meta.id) + "]");
}
if (!meta.isDivider) return [3, 6];
p = void 0;
i = 0, li = meta.output.length;
......@@ -2050,9 +2079,6 @@
return [4, this._executeSubProcess(scriptResult.type, scriptResult.payload)];
case 8:
subProcessResult = _a.sent();
if (!subProcessResult) {
console.log();
}
return [4, this._executeNextProcess(subProcessResult.type, subProcessResult.payload)];
case 9:
result = _a.sent();
......@@ -2075,9 +2101,9 @@
metaConfig = this._meta;
if (!metaConfig) return [3, 3];
if (!metaConfig.script) return [3, 2];
func = new Function('args', 'props', 'global', warpAsyncScript(metaConfig.script));
func = new Function('args', 'props', 'target', 'global', warpAsyncScript(metaConfig.script));
this.updateProps();
return [4, func(payload, this._config.props, this._vm.getGlobalContext())];
return [4, func(payload, this._config.props, this._target, this._vm.getGlobalContext())];
case 1:
result = _a.sent();
_a.label = 2;
......@@ -2102,7 +2128,7 @@
if (!this._meta) return [3, 2];
_a = this._meta, sub = _a.sub, subEntry = _a.subEntry;
if (!sub) return [3, 2];
return [4, this._vm.executeProcess(sub, subEntry, this, payload)];
return [4, this._vm.executeProcess(objClone(sub), subEntry, this, payload)];
case 1:
result = _b.sent();
_b.label = 2;
......@@ -2149,14 +2175,19 @@
return this._config.props;
};
Process.prototype.updateProps = function () {
var props = this._config.props;
for (var key in props) {
var value = props[key];
if (value === linkedFlag) {
if (this._parent) {
var pProp = this._parent.getProps(key);
if (pProp !== undefined) {
props[key] = pProp;
if (this._originProps) {
var props = this._config.props;
for (var key in props) {
var value = this._originProps[key];
if (value === linkedFlag) {
if (this._parent) {
props[key] = this._parent.getProps(key);
}
}
else if (value.indexOf(nodeScheme) === 0) {
var uuid = value.replace(nodeScheme, '');
if (uuid) {
props[key] = findNodeByUUID(this._vm.getGlobalContext().gameStage, uuid);
}
}
}
......@@ -2172,9 +2203,10 @@
function VM() {
}
VM.prototype.setup = function (context) {
var processMetaLibs = context.processMetaLibs, globalContext = context.globalContext;
var processMetaLibs = context.processMetaLibs, globalContext = context.globalContext, target = context.target;
this._processMetaLibs = processMetaLibs;
this._globalContext = globalContext;
this._target = target;
};
VM.prototype.executeProcess = function (sequence, id, parentProcess, args) {
return __awaiter(this, void 0, void 0, function () {
......@@ -2188,6 +2220,7 @@
id: id,
vm: this,
parent: parentProcess,
target: this._target,
});
return [4, process.execute(args)];
case 1: return [2, _a.sent()];
......@@ -2228,12 +2261,13 @@
globalContext[key] = context[key];
}
}
function executeBehavior(sequence, subEntry, args) {
function executeBehavior(sequence, subEntry, target, args) {
if (subEntry === void 0) { subEntry = 'main'; }
var vm = new VM();
vm.setup({
processMetaLibs: processMetaLibs,
globalContext: globalContext,
target: target,
});
vm.executeProcess(sequence, subEntry, null, args)
.then(function (result) {
......@@ -2271,7 +2305,7 @@
if (eventConfig) {
executeBehavior({
main: eventConfig.behaviors[0],
}, 'main');
}, 'main', e.target);
}
}
};
......@@ -2286,6 +2320,28 @@
return EventsProxy;
}(HashObject));
function afterConstructor(ctor) {
ctor.prototype.afterConstructor = function () {
this.applyAutoAdjust();
this.applyScripts();
this.applyEvents();
};
ctor.prototype.clone = function () {
var target = this.constructor.apply(Object.create(this.constructor.prototype));
var originConfig = this.__originConfig;
target.name = originConfig.name;
for (var field in originConfig.properties) {
propertyParse(field, target, originConfig.properties);
}
for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
var child = _a[_i];
var childCopy = child.clone();
target.addChild(childCopy);
}
return target;
};
}
var Container = (function (_super) {
__extends(Container, _super);
function Container() {
......@@ -2293,17 +2349,11 @@
_this.mouseChildren = true;
_this._instanceType = "Container";
_this.children = [];
_this.applyAutoAdjust();
_this.applyScripts();
_this.applyEvents();
_this.afterConstructor();
return _this;
}
Container_1 = Container;
Container.prototype.applyAutoAdjust = function () {
};
Container.prototype.applyScripts = function () {
};
Container.prototype.applyEvents = function () {
Container.prototype.afterConstructor = function () {
};
Container.prototype.onChildrenChange = function (index) {
};
......@@ -2672,6 +2722,7 @@
};
var Container_1;
Container = Container_1 = __decorate([
afterConstructor,
applyAutoAdjust,
applyScript,
applyEvents
......@@ -11027,7 +11078,6 @@
'.svga': 'Svga',
'.sht': 'Sheet',
};
var loader = new Loader();
function loadAssets(config, onProgress, onComplete) {
assetsConfig = config;
var total = assetsConfig.length;
......@@ -11036,7 +11086,7 @@
return Promise.all(assetsConfig.map(function (assetConfig) {
return new Promise(function (resolve) {
var loadFunc = loaderMapping[assetConfig.ext] || 'Raw';
loader['load' + loadFunc](function (result, payload) {
globalLoader['load' + loadFunc](function (result, payload) {
if (result) {
loaded++;
onProgress && onProgress(loaded, total);
......@@ -11380,18 +11430,6 @@
function instantiate(config) {
return instantiateView(config);
}
var percentKeys = ['width', 'height'];
function propertyParse(key, node, properties) {
var value = properties[key];
var targetKey = key;
if (percentKeys.indexOf(key) >= 0) {
if (typeof value === 'string') {
targetKey = 'percent' + key[0].toUpperCase() + key.substr(1);
value = parseInt(value);
}
}
node[targetKey] = value;
}
function instantiateView(config) {
var type = config.type, scripts = config.scripts;
var nodeTypeDef = nodeTypeMapping[type];
......@@ -11403,6 +11441,7 @@
var name = config.name, uuid = config.uuid, properties = config.properties, children = config.children, events = config.events;
node.name = name;
node.uuid = uuid;
node.__originConfig = config;
injectProperties(node, properties);
if (scripts && scripts.length > 0) {
for (var _i = 0, scripts_1 = scripts; _i < scripts_1.length; _i++) {
......@@ -11426,7 +11465,7 @@
}
function instantiateScript(node, ScriptConfig) {
var scriptName = ScriptConfig.script, properties = ScriptConfig.properties, disabled = ScriptConfig.disabled;
var script = node.scripts.add(scriptName, properties, disabled);
var script = node.scriptsProxy.add(scriptName, properties, disabled);
}
function injectProperties(target, source) {
for (var key in source) {
......@@ -11500,19 +11539,35 @@
return GameStage;
}(Container));
function launch(config, onAssetsProgress, onAssetsComplete) {
var _a = config.launchOptions, containerID = _a.containerID, designWidth = _a.designWidth, designHeight = _a.designHeight, frameRate = _a.frameRate, scaleMode = _a.scaleMode, rendererType = _a.rendererType;
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
function launch(url, onAssetsProgress, onAssetsComplete) {
return new Promise(function (resolve, reject) {
globalLoader.loadJson(function (s, payload) {
if (s) {
resolve(payload);
}
else {
reject(payload);
}
}, url);
}).then(function (config) {
return launchWithConfig(config, onAssetsProgress, onAssetsComplete);
});
stage.addChild(gameStage);
setTimeout(function () {
gameStage.launch(config, onAssetsProgress, onAssetsComplete);
}
function launchWithConfig(config, onAssetsProgress, onAssetsComplete) {
return new Promise(function (resolve) {
var _a = config.launchOptions, containerID = _a.containerID, designWidth = _a.designWidth, designHeight = _a.designHeight, frameRate = _a.frameRate, scaleMode = _a.scaleMode, rendererType = _a.rendererType;
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);
});
resolve(gameStage);
});
return gameStage;
}
exports.BaseTexture = BaseTexture;
......@@ -11553,6 +11608,7 @@
exports.getTexture = getTexture;
exports.inputFeildIosEnable = inputFeildIosEnable;
exports.launch = launch;
exports.launchWithConfig = launchWithConfig;
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.
......@@ -33,7 +33,7 @@
<script type="text/javascript" src="../dist/index.js"></script>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script src="scripts/ScriptDemo.js"></script>
<script src="view-data.js"></script>
<script src="scripts/ZoomButton.js"></script>
<script src="game-stage.js"></script>
......
......@@ -3,5 +3,6 @@
*/
engine.registerScriptDef(ScriptDemo);
engine.registerScriptDef(ZoomButton);
const gameStage = engine.launch(data);
engine.launch('http://localhost:63342/VisualEditor/renderingengine/examples/mock/test.json');
{
"launchOptions": {
"entrySceneView": "view1",
"containerID": "game-container",
"designWidth": 750,
"designHeight": 1334,
"frameRate": 60,
"scaleMode": "fixedWidth",
"rendererType": "webgl"
},
"views": [
{
"name": "view1",
"type": "node",
"properties": {
"width": "100%",
"height": "100%",
"mouseEnabled": false
},
"uuid": "3a357816-5581-41ba-aa6f-4a6cc40ae396",
"children": [
{
"name": "bg",
"type": "rect",
"uuid": "f97bbf76-6923-4669-b5a3-e6382753e49a",
"properties": {
"width": "100%",
"height": "100%",
"fillColor": "#1E2127",
"mouseEnabled": false
}
},
{
"name": "button",
"type": "rect",
"uuid": "aaaa",
"properties": {
"y": 20,
"width": 150,
"height": 50,
"horizonCenter": 0,
"borderRadius": 10,
"fillColor": "#27ADB8",
"mouseChildren": false
},
"children": [
{
"name": "label",
"type": "label",
"uuid": "bbbb",
"properties": {
"width": "100%",
"height": "100%",
"fillColor": "white",
"text": "Button",
"size": 30,
"textAlign": "center",
"verticalAlign": "middle"
}
}
],
"events": {
"click": {
"once": false,
"behaviors": [
{
"uuid": "aa1",
"alias": "主过程",
"meta": "main",
"props": {
"text": "linked_text"
}
}
]
}
},
"scripts": [
{
"script": "ZoomButton",
"disabled": false,
"properties": {
"duration": 1000
}
}
]
}
]
},
{
"name": "view2",
"type": "node",
"properties": {
"horizonCenter": 0,
"verticalCenter": 0,
"width": "80%",
"height": 400
},
"uuid": "3a357816-5581-41ba-aa6f-4a6cc40ae396",
"children": [
{
"name": "bg",
"type": "rect",
"properties": {
"width": "100%",
"height": "100%",
"borderRadius": 10,
"fillColor": "orange"
},
"uuid": "f97bbf76-6923-4669-b5a3-e6382753e49a"
},
{
"name": "img",
"type": "image",
"properties": {
"source": "asset://0a5f2064-f5b4-41a9-8a54-2085e208d20f"
},
"uuid": "f97bbf76-6923-4669-b5a3-e6382753e49a"
}
]
}
],
"assets": [
{
"name": "face",
"ext": ".png",
"url": "//yun.duiba.com.cn/aurora/58323a0469a7467c99b34f8933ea65b507a0c655.png",
"uuid": "3e496939-5fe6-42f2-b8fa-42c7a742e880"
},
{
"name": "还以是bug",
"ext": ".jpg",
"url": "//yun.duiba.com.cn/aurora/094832ace87c94bdb9e4a7821b3a3ebca0df2cd7.jpg",
"uuid": "ec67a8a0-8708-43a4-888e-efb0fe7c2bd6"
},
{
"name": "嘿嘿",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/1ad10a4cf3488ef1400af1d6f353d9c577fe1049.gif",
"uuid": "429803eb-0f68-4071-b68c-468980883ac4"
},
{
"name": "1643017",
"ext": ".jpg",
"url": "//yun.duiba.com.cn/aurora/2e4adf3d8646ffbd027038cb2c6627a6bca44e44.jpg",
"uuid": "cc1ad757-ff4c-4cb9-b629-be355119d018"
},
{
"name": "0",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/616a413facbd406b81daac809a52bd0b648a7f4c.gif",
"uuid": "0a5f2064-f5b4-41a9-8a54-2085e208d20f"
},
{
"name": "3",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/e052cb4a88d63330c37ecaf55ae8e7eb2246c433.gif",
"uuid": "e4dacdd2-064f-413e-a8f0-6425ce6dcf12"
},
{
"name": "5",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/881193ea1bd975c8a59f38f2d1f0d0094db6ec7a.gif",
"uuid": "bf822d51-a1b1-4ab6-8f49-a821863731d0"
},
{
"name": "4",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/2df4a5c5238f86704388517d2ba0faa6782fea1e.gif",
"uuid": "9c1d46b4-d2f1-4733-8b93-39b2bb4db9d1"
},
{
"name": "1",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/0bc24c7bb68e3691bad89c8ae096b253af874a73.gif",
"uuid": "db076340-e1db-4e2d-8bb2-7cc32ccdee43"
},
{
"name": "7",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/3e218541244d1ed1192274ad49ea70588b6cd0dc.gif",
"uuid": "02aa47c3-dbdf-43d2-8cdc-869cab544bcc"
},
{
"name": "2",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/1e1344fabf25cf2ea6f1407cd42afc1f1de0bb07.gif",
"uuid": "264f7a8d-475e-4fd0-ac83-96e13a7702f3"
},
{
"name": "8",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/90080b186e0507b70f64c2020880dd1ddd3b7cd8.gif",
"uuid": "ec63930b-8aff-4108-9ceb-ddf9353d4412"
},
{
"name": "0",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/616a413facbd406b81daac809a52bd0b648a7f4c.gif",
"uuid": "7c475d4d-0ae2-4b9a-81ff-76fb8264721f"
},
{
"name": "9",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/f41b70c1003ff703386a5a80ed7092db5fdc11f4.gif",
"uuid": "473b82ec-c9b9-43d7-b2e5-b5399a55d239"
},
{
"name": "12",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/99660ca0a9a578cd6c5eb38b1f35aee9a77849b3.gif",
"uuid": "84f549d3-9bb1-4066-9668-3705e94b5891"
},
{
"name": "11",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/f88c5de6bb6ab80f24cc56978e92cedf4af201f0.gif",
"uuid": "a4470420-60bd-4578-a2dc-100663ba6256"
},
{
"name": "13",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/c5c446eba840899d364bcdb010a2aea8d2ae02ab.gif",
"uuid": "7383d2db-43dd-408a-aa69-261bd39865ac"
},
{
"name": "6",
"ext": ".gif",
"url": "//yun.duiba.com.cn/aurora/881193ea1bd975c8a59f38f2d1f0d0094db6ec7a.gif",
"uuid": "894a28f8-a814-4c8c-a5d9-619194b3073d"
},
{
"name": "btn-join",
"ext": ".png",
"url": "//yun.duiba.com.cn/aurora/e50e0fe70f4b2c96d2deee1d93a0a2444732be6a.png",
"uuid": "e3301bc4-7b51-4868-a613-26298f87988b"
},
{
"name": "bg",
"ext": ".jpg",
"url": "//yun.duiba.com.cn/aurora/7dbe10dba2a92d830f0f9ff72f3d82e07a4c4649.jpg",
"uuid": "bab58ec1-24b1-4d5d-9c95-7014b9915cb3"
},
{
"name": "1643017",
"ext": ".png",
"uuid": "54f7916f-dc10-49f7-b3b1-0bda9d4f5bcd",
"url": "//yun.duiba.com.cn/aurora/4090d0acf7dbf29cd6ab0690795e0b00b715280c.png"
},
{
"name": "bg",
"ext": ".png",
"uuid": "5fe14ca0-5b86-405e-98a6-54ca733f2180",
"url": "//yun.duiba.com.cn/aurora/070159098034ae2cd8c8e4bf4f47b1d45b87024a.png"
},
{
"name": "rule_button",
"ext": ".png",
"uuid": "82a9d493-078a-4b7c-8352-616abc99f24a",
"url": "//yun.duiba.com.cn/aurora/d0c3ed2bf9abc5748c01eb88abb7e0830669b1c5.png"
},
{
"name": "wheel_items",
"ext": ".png",
"uuid": "b899e2f0-36da-42dc-a9ac-c8f4093e4457",
"url": "//yun.duiba.com.cn/aurora/897ee802eb89999c2019c683c084f4b7e2d7f554.png"
},
{
"name": "wheel_bg",
"ext": ".png",
"uuid": "8f531f60-b48e-4a7a-bd7a-9488a3c3dd2d",
"url": "//yun.duiba.com.cn/aurora/479cbb31bfdaee48893bf34f7d0c8fc702b1459a.png"
},
{
"name": "start_bg",
"ext": ".png",
"uuid": "62fe5f9b-47ec-4c1e-b508-f566501caa72",
"url": "//yun.duiba.com.cn/aurora/3191ba684512b9e9391ab4a9d2a2df31cad4825d.png"
},
{
"name": "0",
"ext": ".png",
"uuid": "562af6d0-6b73-4de8-bed0-ed3a4507962c",
"url": "//yun.duiba.com.cn/aurora/be2fa0d9e91b58d9aafcd18f7934784742069cb6.png"
},
{
"name": "1",
"ext": ".png",
"uuid": "6cf1bc08-bcc8-4cec-88d8-3e979b35dd0f",
"url": "//yun.duiba.com.cn/aurora/3f64f753e272d17a1f5807ddf1a8965a0e2de9d5.png"
},
{
"name": "0",
"ext": ".png",
"uuid": "378851d3-6664-4b0e-8407-342f4ffaf334",
"url": "//yun.duiba.com.cn/aurora/3c292a9c6c5b1a3dab684e95d1f7b7cb4f369a8a.png"
},
{
"name": "1",
"ext": ".png",
"uuid": "dee35c49-db44-4722-a412-a8b7123d20b7",
"url": "//yun.duiba.com.cn/aurora/b22420f2322326359e2b3e1dae66dc7e34ce6978.png"
},
{
"name": "bg",
"ext": ".png",
"uuid": "2b0cc6bd-fc10-43ee-a217-aaf1c40a0ad3",
"url": "//yun.duiba.com.cn/aurora/93fbb49529a3b4617f4cdc41dba7c297989baa5e.png"
}
],
"dataMapping": [
{
"name": "nickname",
"path": "test.hello.aaa.name"
},
{
"name": "avatar",
"path": "test.hello.aaa.avatar"
}
],
"processes": [
{
"id": "main",
"name": "Main",
"props": {
"text": {
"alias": "文本",
"type": "string",
"default": "你好"
}
},
"subEntry": "a1",
"sub": {
"a1": {
"uuid": "a1",
"alias": "入口",
"meta": "entry",
"output": {
"success": [
"a2"
]
},
"design": {
"x": 10,
"y": 10
}
},
"a2": {
"uuid": "a2",
"meta": "divider1",
"output": {
"p0": [
"a3"
],
"p1": [
"a4"
]
}
},
"a3": {
"uuid": "a3",
"alias": "test",
"meta": "test",
"props": {
"text": "hello",
"node": "node://bbbb"
},
"output": {
"success": [],
"failed": []
},
"design": {
"x": 20,
"y": 100
}
},
"a4": {
"uuid": "a4",
"alias": "test2",
"meta": "test2",
"props": {
"text": "$_linked_$"
},
"output": {
"success": [],
"failed": []
},
"design": {
"x": 20,
"y": 100
}
}
}
},
{
"id": "test",
"name": "Test",
"props": {
"text": {
"alias": "文本",
"type": "string",
"default": "你好"
},
"num": {
"alias": "数字",
"type": "number",
"default": 1
},
"type": {
"alias": "类型",
"type": "enum",
"enum": [
"rotate",
"jump",
"breath"
],
"default": "rotate"
},
"autoPlay": {
"alias": "自动播放",
"type": "boolean",
"default": false
},
"color": {
"alias": "颜色",
"type": "color",
"default": "#123456"
},
"asset": {
"alias": "素材",
"type": "asset"
},
"node": {
"alias": "节点",
"type": "node"
}
},
"output": [
"success",
"failed"
],
"script": "console.log('test');resolve({type: 'success', payload: args})"
},
{
"id": "test2",
"name": "Test2",
"props": {
"text": {
"alias": "文本",
"type": "string",
"default": "你好"
}
},
"output": [
"success",
"failed"
],
"script": "console.log('test2', props);resolve({type: 'success', payload: args})"
},
{
"id": "divider1",
"name": "Divider1",
"isDivider": true,
"output": [
"p0",
"p1"
]
}
],
"globalProcesses": [
{
"id": "entry",
"name": "Entry",
"props": {},
"script": "resolve({type: 'success', payload: args});",
"output": [
"success"
]
},
{
"id": "wait",
"name": "Wait",
"props": {
"duration": {
"type": "number",
"default": 1000
}
},
"script": "setTimeout(function(){resolve({type: 'complete'})}, props.duration || 0);",
"output": [
"complete"
]
},
{
"id": "compare",
"name": "Compare",
"props": {
"left": {
"type": "any",
"default": ""
},
"right": {
"type": "any",
"default": ""
},
"operator": {
"type": "string",
"default": "=="
}
},
"script": "\nlet leftValue = typeof props.left === 'object' ? args[props.left.path] : props.left;\nlet rightValue = typeof props.right === 'object' ? args[props.right.path] : props.right;\nlet func = new Function('return '+leftValue+args.operator+rightValue);\nlet result = func();\nresolve({type: result ? 'equal' : 'unequal'});\n\t\t",
"output": [
"complete"
]
},
{
"id": "nestProc",
"name": "NestProc",
"metas": {
"print": {
"id": "print",
"name": "Print",
"props": {
"text": {
"type": "string",
"default": ""
}
},
"script": "console.log(props.text);resolve({type: 'success'});",
"output": [
"success"
]
}
},
"props": {},
"subEntry": "1",
"sub": {
"1": {
"uuid": "1",
"meta": "wait",
"alias": "等待",
"props": {
"duration": 500
},
"output": [
"2"
]
},
"2": {
"uuid": "2",
"alias": "打印",
"meta": "print",
"props": {
"text": "hello"
},
"output": []
}
}
}
]
}
\ No newline at end of file
/**
* Created by rockyl on 2019-11-07.
*/
class ZoomButton {
static name = 'ZoomButton';
mounted(){
console.log('mounted', this.duration);
this.host.anchorX = this.host.width / 2;
this.host.anchorY = this.host.height / 2;
this.host.addEventListener(engine.MouseEvent.MOUSE_DOWN, this._onMouseDown, this);
this.host.addEventListener(engine.MouseEvent.MOUSE_UP, this._onMouseUp, this);
}
destroy(){
console.log('destroy');
}
update(t){
//console.log('update', t);
//this.host.rotation = t * 0.1;
}
awake(){
console.log('awake');
}
sleep(){
console.log('sleep');
}
_onMouseDown(e){
this.host.scaleX = this.host.scaleY = 1.1;
}
_onMouseUp(e){
this.host.scaleX = this.host.scaleY = 1;
}
}
......@@ -37,10 +37,12 @@ const data = {
{
name: "button",
type: "rect",
uuid: "f97bbf76-6923-4669-b5a3-e6382753e49a",
uuid: "aaaa",
properties: {
y: 20,
width: 150,
height: 50,
horizonCenter: 0,
borderRadius: 10,
fillColor: "#27ADB8",
mouseChildren: false,
......@@ -49,7 +51,7 @@ const data = {
{
name: "label",
type: "label",
uuid: "f97bbf76-6923-4669-b5a3-e6382753e49a",
uuid: "bbbb",
properties: {
width: '100%',
height: '100%',
......@@ -76,6 +78,15 @@ const data = {
]
}
},
scripts: [
{
script: 'ZoomButton',
disabled: false,
properties: {
duration: 1000,
},
}
],
},
/*{
name: "img",
......@@ -326,6 +337,7 @@ const data = {
meta: 'test',
props: {
text: 'hello',
node: 'node://bbbb'
},
output: {
success: [],
......@@ -367,6 +379,7 @@ const data = {
node: {alias: '节点', type: 'node',},
},
output: ['success', 'failed'],
//script: "console.log('test');let b = target.clone();b.y = global.by = (global.by || 0) + 80; target.parent.addChild(b);resolve({type: 'success', payload: args})",
script: "console.log('test');resolve({type: 'success', payload: args})",
},
{
......@@ -458,3 +471,5 @@ resolve({type: result ? 'equal' : 'unequal'});
},
],
};
console.log(JSON.stringify(data));
import { DisplayObject } from './DisplayObject';
import { Rectangle } from "../math/Rectangle";
import { Point } from '../math';
import {DisplayObject} from './DisplayObject';
import {Rectangle} from "../math/Rectangle";
import {Point} from '../math';
import CanvasRenderer from '../renderers/CanvasRenderer';
import { Event } from "../events/Event"
import { WebglRenderer } from '../renderers/WebglRenderer';
import {Event} from "../events/Event"
import {WebglRenderer} from '../renderers/WebglRenderer';
import { applyAutoAdjust } from "../../zeroing/decorators/auto-adjust";
import { applyScript } from "../../zeroing/decorators/scripts";
import { applyEvents } from "../../zeroing/decorators/events";
import {applyAutoAdjust} from "../../zeroing/decorators/auto-adjust";
import {applyScript} from "../../zeroing/decorators/scripts";
import {applyEvents} from "../../zeroing/decorators/events";
import {afterConstructor} from "../../zeroing/decorators/after-constructor";
/**
* 容器类
* @class
* @extends DisplayObject
*/
@afterConstructor
@applyAutoAdjust
@applyScript
@applyEvents
......@@ -40,20 +42,10 @@ export default class Container extends DisplayObject {
super();
this._instanceType = "Container";
this.children = [];
this.applyAutoAdjust();
this.applyScripts();
this.applyEvents();
this.afterConstructor();
}
applyAutoAdjust() {
}
applyScripts() {
}
applyEvents() {
afterConstructor() {
}
......@@ -514,7 +506,8 @@ export default class Container extends DisplayObject {
let len = this.children.length;
for (let i = len - 1; i >= 0; i--) {
const child = this.children[i];
/*if (child.visible)*/ child.update(deltaTime);
/*if (child.visible)*/
child.update(deltaTime);
}
}
......
......@@ -4,17 +4,19 @@
* 过程
*/
import {VM} from "./VM";
import {linkedFlag} from "../utils";
import {linkedFlag, nodeScheme, objClone} from "../utils";
import {findNodeByUUID} from "../node-utils";
const log = true;
const log = false;
export class Process {
private _heap = {};
private _config;
private _parent: Process;
private _vm: VM;
private _sequence;
private _meta;
private _target;
private _originProps;
constructor() {
......@@ -28,20 +30,21 @@ export class Process {
return this._parent;
}
get heap() {
return this._heap;
}
get sequence() {
return this._sequence;
}
init(context) {
const {vm, parent, sequence, id} = context;
const {vm, parent, sequence, id, target} = context;
this._vm = vm;
this._parent = parent;
this._config = sequence[id];
this._sequence = sequence;
this._target = target;
if (!this._originProps && this._config.props) {
this._originProps = objClone(this._config.props)
}
}
async execute(args) {
......@@ -73,9 +76,6 @@ export class Process {
} else {
const scriptResult = await this._executeMetaScript('', args, metaConfig);
const subProcessResult = await this._executeSubProcess(scriptResult.type, scriptResult.payload);
if (!subProcessResult) {
console.log();
}
result = await this._executeNextProcess(subProcessResult.type, subProcessResult.payload);
}
......@@ -91,9 +91,9 @@ export class Process {
let metaConfig = this._meta;
if (metaConfig) {
if (metaConfig.script) {
let func = new Function('args', 'props', 'global', warpAsyncScript(metaConfig.script));
let func = new Function('args', 'props', 'target', 'global', warpAsyncScript(metaConfig.script));
this.updateProps();
result = await func(payload, this._config.props, this._vm.getGlobalContext());
result = await func(payload, this._config.props, this._target, this._vm.getGlobalContext());
}
} else {
console.warn(`process meta [${meta}] not found`)
......@@ -110,7 +110,7 @@ export class Process {
if (this._meta) {
let {sub, subEntry} = this._meta;
if (sub) {
result = await this._vm.executeProcess(sub, subEntry, this, payload);
result = await this._vm.executeProcess(objClone(sub), subEntry, this, payload);
}
}
......@@ -162,14 +162,18 @@ export class Process {
* 更新props
*/
updateProps() {
let props = this._config.props;
for (let key in props) {
let value = props[key];
if (value === linkedFlag) {
if (this._parent) {
let pProp = this._parent.getProps(key);
if (pProp !== undefined) {
props[key] = pProp;
if (this._originProps) {
let props = this._config.props;
for (let key in props) {
let value = this._originProps[key];
if (value === linkedFlag) {
if (this._parent) {
props[key] = this._parent.getProps(key);
}
} else if (value.indexOf(nodeScheme) === 0) {
let uuid = value.replace(nodeScheme, '');
if (uuid) {
props[key] = findNodeByUUID(this._vm.getGlobalContext().gameStage, uuid);
}
}
}
......
......@@ -8,12 +8,14 @@ import {arrayFind} from "../utils";
export class VM {
_processMetaLibs;
_globalContext;
_target;
setup(context) {
const {processMetaLibs, globalContext} = context;
const {processMetaLibs, globalContext, target} = context;
this._processMetaLibs = processMetaLibs;
this._globalContext = globalContext;
this._target = target;
}
async executeProcess(sequence, id, parentProcess, args) {
......@@ -23,6 +25,7 @@ export class VM {
id,
vm: this,
parent: parentProcess,
target: this._target,
});
return await process.execute(args);
......
......@@ -7,12 +7,20 @@ import {VM} from "./VM";
let processMetaLibs = [];
let globalContext = {};
/**
* 设置过程库
* @param metaContexts
*/
export function setProcessMetaLibs(...metaContexts) {
for (let context of metaContexts) {
processMetaLibs.push(context);
}
}
/**
* 设置去全局上下文
* @param context
*/
export function setGlobalContext(context) {
globalContext = context;
for (let key in context) {
......@@ -20,11 +28,19 @@ export function setGlobalContext(context) {
}
}
export function executeBehavior(sequence, subEntry = 'main', args?) {
/**
* 执行行为
* @param sequence
* @param subEntry
* @param target
* @param args
*/
export function executeBehavior(sequence, subEntry = 'main', target, args?) {
const vm = new VM();
vm.setup({
processMetaLibs,
globalContext,
target,
});
vm.executeProcess(sequence, subEntry, null, args)
.then(result => {
......
/**
* Created by rockyl on 2019-11-08.
*/
import {propertyParse} from "../utils";
const cloneFields = [
/*node*/ 'x', 'y', 'width', 'height', 'rotation', 'alpha', 'scaleX', 'scaleY', 'visible',
/*label*/ 'text', 'color', 'size', 'textAlign', 'verticalAlign',
/*image*/ 'source',
/*rect*/ 'fillColor', 'strokeColor', 'strokeWidth',
/*autoadjust*/ 'left', 'top', 'right', 'bottom',
];
/**
* 构造方法后执行
* @param ctor
*/
export function afterConstructor(ctor: Function) {
ctor.prototype.afterConstructor = function () {
this.applyAutoAdjust();
this.applyScripts();
this.applyEvents();
};
ctor.prototype.clone = function () {
let target = this.constructor.apply(Object.create(this.constructor.prototype));
let originConfig = this.__originConfig;
target.name = originConfig.name;
for (let field in originConfig.properties) {
propertyParse(field, target, originConfig.properties);
}
for(let child of this.children){
let childCopy = child.clone();
target.addChild(childCopy);
}
return target;
};
}
......@@ -71,6 +71,12 @@ class AdjustProxy {
this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
}
setFrom(adjustProxy: AdjustProxy) {
for (let k in adjustProxy.data) {
this.data[k] = adjustProxy.data[k];
}
}
private onResize(e) {
this._sizeDirty = true;
}
......
......@@ -42,7 +42,7 @@ class EventsProxy extends HashObject {
if (eventConfig) {
executeBehavior({
main: eventConfig.behaviors[0],
}, 'main')
}, 'main', e.target);
}
}
}
......
/**
* Created by rockyl on 2019-11-07.
*/
import {Loader} from "../..";
import {globalLoader} from "../../2d/loader/Loader";
let assetsConfig;
......@@ -17,8 +18,6 @@ const loaderMapping = {
'.sht': 'Sheet',
};
const loader = new Loader();
/**
* 加载素材
*/
......@@ -33,7 +32,7 @@ export function loadAssets(config, onProgress?, onComplete?) {
assetsConfig.map(assetConfig => {
return new Promise((resolve) => {
const loadFunc = loaderMapping[assetConfig.ext] || 'Raw';
loader['load' + loadFunc](function (result, payload) {
globalLoader['load' + loadFunc](function (result, payload) {
if (result) {
loaded++;
onProgress && onProgress(loaded, total);
......
......@@ -4,6 +4,7 @@
import {Container} from "../../2d/display";
import {Rect, Image, Label} from "./nodes";
import {propertyParse} from "../utils";
const nodeTypeMapping = {
node: Container,
......@@ -16,20 +17,6 @@ export function instantiate(config) {
return instantiateView(config);
}
const percentKeys = ['width', 'height'];
function propertyParse(key, node, properties) {
let value = properties[key];
let targetKey = key;
if (percentKeys.indexOf(key) >= 0) {
if (typeof value === 'string') {
targetKey = 'percent' + key[0].toUpperCase() + key.substr(1);
value = parseInt(value);
}
}
node[targetKey] = value;
}
function instantiateView(config) {
const {type, scripts} = config;
......@@ -43,6 +30,7 @@ function instantiateView(config) {
const {name, uuid, properties, children, events} = config;
node.name = name;
node.uuid = uuid;
node.__originConfig = config;
injectProperties(node, properties);
if (scripts && scripts.length > 0) {
......@@ -68,7 +56,7 @@ function instantiateView(config) {
function instantiateScript(node, ScriptConfig) {
const {script: scriptName, properties, disabled} = ScriptConfig;
const script = node.scripts.add(scriptName, properties, disabled);
const script = node.scriptsProxy.add(scriptName, properties, disabled);
}
function injectProperties(target, source) {
......
......@@ -3,31 +3,51 @@
*/
import {Stage} from "../2d/display";
import { RENDERER_TYPE, StageScaleMode} from "..";
import {RENDERER_TYPE, StageScaleMode} from "..";
import {GameStage} from "./game-warpper";
import {setGlobalContext} from "./behavior-runtime";
import {globalLoader} from "../2d/loader/Loader";
export function launch(config, onAssetsProgress, onAssetsComplete) {
const {containerID, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.launchOptions;
let stage = window['stage'] = new Stage(
containerID || "game-container",
designWidth || 750,
designHeight || 1334,
frameRate || 60,
scaleMode || StageScaleMode.FIXED_WIDTH,
rendererType || RENDERER_TYPE.WEBGL
);
Stage.flushAll();
export function launch(url, onAssetsProgress, onAssetsComplete) {
return new Promise((resolve, reject) => {
globalLoader.loadJson((s, payload) => {
if(s){
resolve(payload);
}else{
reject(payload);
}
}, url);
}).then(
config=>{
return launchWithConfig(config, onAssetsProgress, onAssetsComplete);
}
)
}
export function launchWithConfig(config, onAssetsProgress, onAssetsComplete) {
return new Promise(resolve => {
const {containerID, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.launchOptions;
let stage = window['stage'] = new Stage(
containerID || "game-container",
designWidth || 750,
designHeight || 1334,
frameRate || 60,
scaleMode || StageScaleMode.FIXED_WIDTH,
rendererType || RENDERER_TYPE.WEBGL
);
Stage.flushAll();
let gameStage = new GameStage(stage);
setGlobalContext({
gameStage
});
stage.addChild(gameStage);
let gameStage = new GameStage(stage);
setGlobalContext({
gameStage
});
stage.addChild(gameStage);
setTimeout(() => {
gameStage.launch(config, onAssetsProgress, onAssetsComplete);
});
setTimeout(() => {
gameStage.launch(config, onAssetsProgress, onAssetsComplete);
});
return gameStage;
resolve(gameStage);
})
}
/**
* Created by rockyl on 2019-11-13.
*/
export function findNodeByUUID(node, uuid) {
if (node.uuid === uuid) {
return node;
}
for (let child of node.children) {
let target = findNodeByUUID(child, uuid);
if (target) {
return target;
}
}
}
......@@ -4,6 +4,7 @@
export const ESCAPE_REG_EXP = /\$\{[_a-zA-Z]\w*\}/g;
export const linkedFlag = '$_linked_$';
export const nodeScheme = 'node://';
export function arrayFind(arr, callback) {
for (let i = 0, li = arr.length; i < li; i++) {
......@@ -14,3 +15,23 @@ export function arrayFind(arr, callback) {
}
}
}
export function objClone(obj) {
return JSON.parse(JSON.stringify(obj));
}
const percentKeys = ['width', 'height'];
export function propertyParse(key, node, properties) {
let value = properties[key];
let targetKey = key;
if (percentKeys.indexOf(key) >= 0) {
if (typeof value === 'string') {
if(value[value.length-1] === '%'){
targetKey = 'percent' + key[0].toUpperCase() + key.substr(1);
}
value = parseInt(value);
}
}
node[targetKey] = value;
}
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