Commit ee17ddaa authored by rockyl's avatar rockyl

data类型修改为dynamic

增加map类型
parent b68b29df
......@@ -2,9 +2,33 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Examples</title>
<title>GameStage</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<!-- <meta name="viewport" content="width=device-width,minimum-scale=1.0,user-scalable=no"> -->
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: white;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script type="text/javascript" src="../dist/engine.js"></script>
<script src="index.js"></script>
</body>
</html>
\ No newline at end of file
/**
* Created by rockyl on 2019-11-24.
*/
let stage = window['stage'] = new engine.Stage(
"game-container",
750,
1334,
60,
engine.StageScaleMode.FIXED_WIDTH,
engine.RENDERER_TYPE.WEBGL
);
engine.Stage.flushAll();
const scrollView = new engine.Container();
stage.addChild(scrollView);
/*let scrollView = new engine.ScrollView();
scrollView.x = 100;
scrollView.y = 100;
scrollView.width = 100;
scrollView.height = 100;
stage.addChild(scrollView);*/
let rect = new engine.Rect();
rect.fillColor = 'orange';
rect.strokeWidth = 1;
rect.width = 200;
rect.height = 200;
scrollView.addChild(rect);
setTimeout(()=>{
console.log(rect.width, rect.height, rect.getBounds().width);
console.log(scrollView.width);
}, 200);
......@@ -26,9 +26,10 @@
},
"scripts": {
"build-webpack": "webpack",
"rollup": "rollup -c",
"rollup": "rollup -c -o dist/engine.js",
"rollup:debug": "rollup -c -m ",
"rename": "node scripts/rename-hash.js dist/engine.js",
"build": "yarn rollup && yarn rename",
"build": "rm -rf dist&&yarn rollup && yarn rename",
"ts": "dts-bundle --name engine --main types/src/index.d.ts --out ../../dist/index.d.ts",
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack -w",
......
......@@ -12,10 +12,9 @@ export default {
input: 'src/index.ts',
output: [
{
file: `dist/engine.js`,
file: `debug/engine.js`,
format: 'umd',
name: 'engine',
sourcemap: true,
}
],
plugins: [
......
......@@ -7,6 +7,7 @@ import {VM} from "./VM";
import {getDataByPath, linkedFlag, nodeScheme, objClone} from "../utils";
import {findNodeByUUID} from "../node-utils";
import {dataCenter} from "../game-warpper/data-center";
import {env} from "../game-warpper/enviroment";
const log = true;
......@@ -91,7 +92,7 @@ export class Process {
if (this._meta) {
let metaConfig = this._meta;
if (metaConfig) {
this.updateProps(payload);
this.updateProps(this._config.props = {}, payload, this._originProps, this._meta.props);
if (metaConfig.script) {
let func = new Function('args', 'props', 'target', 'global', 'vm', warpAsyncScript(metaConfig.script));
let globalContext = this._vm.globalContext;
......@@ -162,7 +163,7 @@ export class Process {
* 获取props
*/
getProps(key?) {
if (key) {
if (key && this._config.props) {
return this._config.props[key];
}
return this._config.props;
......@@ -171,30 +172,37 @@ export class Process {
/**
* 更新props
*/
updateProps(args) {
if (this._originProps) {
let props = this._config.props;
let propsConfig = this._meta.props;
updateProps(props, args, originProps, propsConfig) {
if (originProps) {
for (let key in propsConfig) {
let value = this._originProps[key];
let value = originProps[key];
const valueType = typeof value;
if (valueType == 'object') {
let name = value.value;
switch (value.type) {
case 'link':
let linkedValue = this.resolveLinkedProp(value, key);
if (linkedValue !== undefined) {
props[key] = undefined;
}else{
props[key] = linkedValue;
}
break;
case 'static':
props[key] = value.value;
props[key] = name;
break;
case 'arguments':
props[key] = args ? getDataByPath(args, value.value) : undefined;
props[key] = args ? getDataByPath(args, name) : undefined;
break;
case 'data-center':
let nameValue = dataCenter.getDataByName(value.value);
props[key] = nameValue !== undefined ? nameValue : dataCenter.getDataByPath(value.value);
let nameValue = dataCenter.getDataByName(name);
props[key] = nameValue !== undefined ? nameValue : dataCenter.getDataByPath(name);
break;
case 'env':
props[key] = env[name];
break;
case 'map':
this.updateProps(props[key] = {}, args, name, name);
break;
}
} else if (value && value.indexOf && value.indexOf(nodeScheme) === 0) {
......
......@@ -14,6 +14,7 @@ import {Rect} from "./nodes";
import {injectEnv} from "./enviroment";
import {registerCustomModuleFromConfig} from "./custom-module";
import {hideLoadingView, showLoadingView} from "./loading-view";
import {Toast} from "./Toast";
/**
* 游戏舞台
......@@ -21,6 +22,7 @@ import {hideLoadingView, showLoadingView} from "./loading-view";
export class GameStage extends Container {
private _sceneContainer: StackContainer; //场景容器
private _popupContainer: StackContainer; //弹层容器
private _toast: Toast;
private _blackLayer: Rect;
private _stage;
private _dataCenter: DataCenter;
......@@ -189,7 +191,7 @@ export class GameStage extends Container {
case 'push':
case 'replace':
case 'popAll':
if (options.center) {
if (options && options.center) {
view.horizonCenter = 0;
view.verticalCenter = 0;
}
......
/**
* Created by rockyl on 2019-11-25.
*/
import {Container} from "../../2d/display";
import {GameStage} from "./GameStage";
import {Label, Rect} from "./nodes";
export class Toast extends Container {
private _contentSample: Container;
private _content: Container;
private _gameStage: GameStage;
constructor(gameStage: GameStage) {
super();
this._gameStage = gameStage;
}
show(props) {
if (!props.text) {
return;
}
const {text, duration, viewName} = props;
let contentView = this.getContent(viewName);
let lab = contentView.getChildByName('lab');
if (!lab) {
console.warn('[lab] child no exists on toast view');
return;
}
lab.text = text;
contentView.width = lab.width;
contentView.height = lab.height;
this.addChild(contentView);
}
hide() {
}
private getContent(viewName) {
let view;
if (viewName) {
view = this._gameStage.instantiateView(viewName);
}
if (!view) {
if (!this._content) {
this._content = new Container();
let bg = new Rect();
bg.percentWidth = 100;
bg.percentHeight = 100;
bg.alpha = 0.7;
view.addChild(bg);
let lab = new Label();
lab.name = 'lab';
view.addChild(bg);
}
view = this._content;
}
return view;
}
}
......@@ -3,14 +3,16 @@
*/
import {Container} from "../../2d/display";
import {Rect, Image, Label} from "./nodes";
import {Rect, Image, Label, Circle, ScrollView} from "./nodes";
import {propertyParse} from "../utils";
const nodeTypeMapping = {
node: Container,
rect: Rect,
circle: Circle,
label: Label,
image: Image,
scrollView: ScrollView,
};
export function instantiate(config) {
......
......@@ -162,3 +162,42 @@ export function importUMDCode(code) {
create.call(exports);
return exports;
}
export function trimChar(str: string, char: string) {
while (true) {
let len = str.length, from = 0, end = len;
if (str[0] === char) {
from = 1;
}
if (str[len - 1] === char) {
end = len - 1;
}
str = str.substring(from, end);
if (str.length == len) {
break;
}
}
return str;
}
export function joinPath(...segments: string[]) {
let result = [];
for (let segment of segments) {
result.push(trimChar(segment, '/'));
}
return result.join('/');
}
export function findVariable(name: string, ...contexts) {
let result;
for (let context of contexts) {
if (context) {
result = context[name];
if(result !== undefined){
break;
}
}
}
return result;
}
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