Commit af6a8e74 authored by rockyl's avatar rockyl

提交

parent 8f20e2d8
This diff is collapsed.
This diff is collapsed.
...@@ -3,6 +3,7 @@ import {DisplayObject} from "./DisplayObject"; ...@@ -3,6 +3,7 @@ import {DisplayObject} from "./DisplayObject";
import {devicePixelRatio} from "../const"; import {devicePixelRatio} from "../const";
let container; let container;
let el;
/** /**
* 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/> * 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/>
...@@ -87,6 +88,8 @@ export class FloatDisplay extends DisplayObject { ...@@ -87,6 +88,8 @@ export class FloatDisplay extends DisplayObject {
container.style.position = "absolute"; container.style.position = "absolute";
container.style.left = "0"; container.style.left = "0";
container.style.top = "0"; container.style.top = "0";
container.style.fontSize = '30px';
container.style.lineHeight = 'normal';
s.stage.rootDiv.appendChild(container);//, s.stage.rootDiv.childNodes[0] s.stage.rootDiv.appendChild(container);//, s.stage.rootDiv.childNodes[0]
} }
if (s._htmlElement) { if (s._htmlElement) {
...@@ -126,7 +129,11 @@ export class FloatDisplay extends DisplayObject { ...@@ -126,7 +129,11 @@ export class FloatDisplay extends DisplayObject {
let s = this; let s = this;
let she: any; let she: any;
if (typeof (htmlElement) == "string") { if (typeof (htmlElement) == "string") {
she = document.getElementById(htmlElement); if (!el) {
el = document.createElement('div');
}
el.innerHTML = htmlElement;
she = el.children[0];
} else if (htmlElement._instanceType == "Video") { } else if (htmlElement._instanceType == "Video") {
she = htmlElement.media; she = htmlElement.media;
} else { } else {
......
...@@ -676,7 +676,12 @@ export class TextField extends Sprite { ...@@ -676,7 +676,12 @@ export class TextField extends Sprite {
} }
ctx.fillText(line, 0, y, maxW); ctx.fillText(line, 0, y, maxW);
} else { } else {
let x = 0; let lineWidth = 0;
for (let char of line) {
let charWidth = measureChar(char);
lineWidth += charWidth;
}
let x = -lineWidth / 2;
for (let j = 0, lj = line.length; j < lj; j++) { for (let j = 0, lj = line.length; j < lj; j++) {
const char = line[j]; const char = line[j];
let style = s.getStyle(index); let style = s.getStyle(index);
......
...@@ -20,9 +20,11 @@ export class Process { ...@@ -20,9 +20,11 @@ export class Process {
private _meta; private _meta;
private _target; private _target;
private _originProps; private _originProps;
private _scope: any;
constructor(id) { constructor(id) {
this.id = id; this.id = id;
this._scope = {};
} }
get processConfig() { get processConfig() {
...@@ -37,6 +39,10 @@ export class Process { ...@@ -37,6 +39,10 @@ export class Process {
return this._sequence; return this._sequence;
} }
get scope() {
return this._scope;
}
init(context) { init(context) {
const {vm, parent, sequence, id, target} = context; const {vm, parent, sequence, id, target} = context;
this._vm = vm; this._vm = vm;
...@@ -104,19 +110,19 @@ export class Process { ...@@ -104,19 +110,19 @@ export class Process {
if (metaConfig.script.indexOf(linkScheme) === 0) { if (metaConfig.script.indexOf(linkScheme) === 0) {
func = this._vm.getScript(metaConfig.script.replace(linkScheme, '')); func = this._vm.getScript(metaConfig.script.replace(linkScheme, ''));
} else { } else {
func = new Function('args', 'props', 'target', 'global', 'vm', warpAsyncScript(metaConfig.script)); func = new Function('args', 'props', 'target', 'global', 'vm', 'scope', warpAsyncScript(metaConfig.script));
} }
if (func) { if (func) {
let globalContext = this._vm.globalContext; let globalContext = this._vm.globalContext;
globalContext.gameStage = engine.gameStage; globalContext.gameStage = engine.gameStage;
globalContext.dataCenter = engine.gameStage.dataCenter; globalContext.dataCenter = engine.gameStage.dataCenter;
globalContext.env = engine.env; globalContext.env = engine.env;
result = await func(payload, this._config.props, this._target, globalContext, this._vm); result = await func(payload, this._config.props, this._target, globalContext, this._vm, this._parent.scope);
if (log){ if (log) {
console.log(`[${this._vm.id}:${this.id}] output: <${result.type}>`, result.payload); console.log(`[${this._vm.id}:${this.id}] output: <${result.type}>`, result.payload);
} }
} else { } else {
if (log){ if (log) {
console.log('script lose'); console.log('script lose');
} }
} }
...@@ -214,6 +220,9 @@ export class Process { ...@@ -214,6 +220,9 @@ export class Process {
case 'static': case 'static':
props[key] = name; props[key] = name;
break; break;
case 'scope':
props[key] = getDataByPath(this._parent.scope, name);
break;
case 'arguments': case 'arguments':
props[key] = args ? getDataByPath(args, name) : undefined; props[key] = args ? getDataByPath(args, name) : undefined;
break; break;
......
...@@ -13,8 +13,7 @@ import {Rect} from "./nodes"; ...@@ -13,8 +13,7 @@ import {Rect} from "./nodes";
import {injectEnv} from "./enviroment"; import {injectEnv} from "./enviroment";
import {Toast} from "./Toast"; import {Toast} from "./Toast";
import {arrayFind} from "../utils"; import {arrayFind} from "../utils";
import {registerCustomModuleAssets, registerScripts} from ".."; import {registerCustomModules, registerScripts} from "..";
import {registerCustomModuleFromConfig} from "./custom-module";
/** /**
* 游戏舞台 * 游戏舞台
...@@ -150,7 +149,7 @@ export class GameStage extends Container { ...@@ -150,7 +149,7 @@ export class GameStage extends Container {
//registerScripts(scripts); //registerScripts(scripts);
//registerCustomModuleFromConfig(customs); //registerCustomModuleFromConfig(customs);
registerCustomModuleAssets(customs); registerCustomModules(customs);
if(dataMapping){ if(dataMapping){
this.dataCenter.registerDataMapping(dataMapping); this.dataCenter.registerDataMapping(dataMapping);
......
...@@ -11,9 +11,10 @@ const customMap = {}; ...@@ -11,9 +11,10 @@ const customMap = {};
* 注册自定义模块素材映射 * 注册自定义模块素材映射
* @param customs * @param customs
*/ */
export function registerCustomModuleAssets(customs) { export function registerCustomModules(customs) {
for (let custom of customs) { for (let custom of customs) {
customMap[custom.id].assets = custom.assets; customMap[custom.id].assets = custom.assets;
customMap[custom.id].props = custom.props;
} }
} }
...@@ -87,3 +88,11 @@ export function resolveCustomAsset(id, uuid) { ...@@ -87,3 +88,11 @@ export function resolveCustomAsset(id, uuid) {
return config; return config;
} }
} }
/**
* 获取配置参数
* @param id
*/
export function getProps(id) {
return customMap[id].props;
}
/**
* Created by rockyl on 2020-01-07.
*/
import {FloatDisplay} from "../../../2d/display";
export class HtmlView extends FloatDisplay{
}
...@@ -61,12 +61,14 @@ export class Label extends TextField { ...@@ -61,12 +61,14 @@ export class Label extends TextField {
if (this._htmlText != value) { if (this._htmlText != value) {
this._htmlText = value; this._htmlText = value;
let matchResult = value.match(ESCAPE_REG_EXP); if(this._htmlText){
let matchResult = value.match(ESCAPE_REG_EXP);
if (matchResult) { if (matchResult) {
this.dealEscape(value, matchResult, this.onHtmlMutated); this.dealEscape(value, matchResult, this.onHtmlMutated);
} else { } else {
this.text = htmlToPureText(value); this.text = htmlToPureText(value);
}
} }
} }
} }
......
...@@ -9,3 +9,4 @@ export * from './TextInput' ...@@ -9,3 +9,4 @@ export * from './TextInput'
export * from './ScrollView' export * from './ScrollView'
export * from './ScrollList' export * from './ScrollList'
export * from './BitmapText' export * from './BitmapText'
export * from './HtmlView'
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
import {Container} from "../../2d/display"; import {Container} from "../../2d/display";
import {Rect, Image, Label, Circle, ScrollView, TextInput, ScrollList, BitmapText} from "./nodes"; import {Rect, Image, Label, Circle, ScrollView, TextInput, ScrollList, BitmapText, HtmlView} from "./nodes";
import {injectProperties, instantiateScript,} from "../utils"; import {injectProperties, instantiateScript,} from "../utils";
const nodeTypeMapping = { const nodeTypeMapping = {
...@@ -16,6 +16,7 @@ const nodeTypeMapping = { ...@@ -16,6 +16,7 @@ const nodeTypeMapping = {
scrollView: ScrollView, scrollView: ScrollView,
scrollList: ScrollList, scrollList: ScrollList,
bitmapText: BitmapText, bitmapText: BitmapText,
htmlView: HtmlView,
}; };
export function registerNodeType(name, def) { export function registerNodeType(name, def) {
...@@ -42,15 +43,6 @@ function instantiateView(config) { ...@@ -42,15 +43,6 @@ function instantiateView(config) {
node.__originConfig = config; node.__originConfig = config;
injectProperties(node, properties); injectProperties(node, properties);
if (scripts && scripts.length > 0) {
for (let scriptConfig of scripts) {
instantiateScript(node, scriptConfig);
}
}
if (events) {
node.eventsProxy.start(events);
}
if (children && children.length > 0) { if (children && children.length > 0) {
for (let childConfig of children) { for (let childConfig of children) {
const childNode = instantiateView(childConfig); const childNode = instantiateView(childConfig);
...@@ -60,5 +52,14 @@ function instantiateView(config) { ...@@ -60,5 +52,14 @@ function instantiateView(config) {
} }
} }
if (scripts && scripts.length > 0) {
for (let scriptConfig of scripts) {
instantiateScript(node, scriptConfig);
}
}
if (events && node.eventsProxy) {
node.eventsProxy.start(events);
}
return node; return node;
} }
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