Commit 03035a71 authored by rockyl's avatar rockyl

提交一下

parent f70709ec
This diff is collapsed.
This diff is collapsed.
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/dist" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
......
...@@ -184,7 +184,7 @@ export default class Container extends DisplayObject { ...@@ -184,7 +184,7 @@ export default class Container extends DisplayObject {
* 是否含有child * 是否含有child
* @param child * @param child
*/ */
contains(child: DisplayObject):boolean{ contains(child: DisplayObject): boolean {
return !!this.getChildIndex(child); return !!this.getChildIndex(child);
} }
...@@ -209,6 +209,66 @@ export default class Container extends DisplayObject { ...@@ -209,6 +209,66 @@ export default class Container extends DisplayObject {
return this.children[index]; return this.children[index];
} }
/**
* 根据路径获取子节点
* @param path
* @param method
*/
getChildByPath(path: any, method: string): DisplayObject {
if (!path) {
return null;
}
let p = this;
while (path.length > 0) {
let segment = path.shift();
p = p[method](segment);
if (!p) {
break;
}
}
return p;
}
/**
* 根据名称路径获取子节点
* @param path
*/
getChildByNamePath(path: string): DisplayObject {
const pathArr = path.split('/');
return this.getChildByPath(pathArr, 'getChildByName');
}
/**
* 根据索引路径获取子节点
* @param path
*/
getChildByIndexPath(path: string): DisplayObject {
const pathArr = path.split('/').map(seg => parseInt(seg));
return this.getChildByPath(pathArr, 'getChildAt');
}
/**
* 根据uuid搜索子节点
* @param uuid
*/
findChildByUUID(uuid: string) {
if (this['uuid'] === uuid) {
return this;
}
if (this.children && this.children.length > 0) {
for (let child of this.children) {
if(child.findChildByUUID){
let target = child.findChildByUUID(uuid);
if (target) {
return target;
}
}
}
}
}
/** /**
* 通过名字获取子级 * 通过名字获取子级
* @param name * @param name
......
import { ObservablePoint, Point, Rectangle } from '../math'; import {ObservablePoint, Point, Rectangle} from '../math';
import { sign, TextureCache } from '../utils'; import {sign, TextureCache} from '../utils';
// import { BLEND_MODES } from '../const'; // import { BLEND_MODES } from '../const';
import Texture from '../texture/Texture'; import Texture from '../texture/Texture';
import { Event } from '../events/Event'; import {Event} from '../events/Event';
import Container from './Container'; import Container from './Container';
import { DisplayObject } from "./DisplayObject"; import {DisplayObject} from "./DisplayObject";
import CanvasRenderer from '../renderers/CanvasRenderer'; import CanvasRenderer from '../renderers/CanvasRenderer';
import { SCALE_MODES } from '../const'; import {SCALE_MODES} from '../const';
import { WebglRenderer } from '../renderers/WebglRenderer'; import {WebglRenderer} from '../renderers/WebglRenderer';
const indices = new Uint16Array([0, 1, 2, 0, 2, 3]); const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
/** /**
...@@ -22,17 +22,17 @@ export default class Sprite extends Container { ...@@ -22,17 +22,17 @@ export default class Sprite extends Container {
* *
*/ */
private _anchorTexture: ObservablePoint; private _anchorTexture: ObservablePoint;
/** /**
* 色值调色 * 色值调色
*/ */
private _tint: number; private _tint: number;
/** /**
* RGB形式色值,webgl用 * RGB形式色值,webgl用
*/ */
_tintRGB: number; _tintRGB: number;
/** /**
* 和_tint比较用,用于canvas调色缓存 * 和_tint比较用,用于canvas调色缓存
*/ */
_cachedTint: number; _cachedTint: number;
/** /**
* 使用的贴图 * 使用的贴图
...@@ -99,9 +99,9 @@ export default class Sprite extends Container { ...@@ -99,9 +99,9 @@ export default class Sprite extends Container {
this._height = 0; this._height = 0;
this._tint = null; this._tint = null;
this._tintRGB = null; this._tintRGB = null;
this.tint = 0xFFFFFF; this.tint = 0xFFFFFF;
this._cachedTint = 0xFFFFFF; this._cachedTint = 0xFFFFFF;
this.uvs = null; this.uvs = null;
...@@ -454,13 +454,14 @@ export default class Sprite extends Container { ...@@ -454,13 +454,14 @@ export default class Sprite extends Container {
} }
get tint() { get tint() {
return this._tint; return this._tint;
} }
set tint(value) {
if (value === this._tint) return; set tint(value) {
this._tint = value; if (value === this._tint) return;
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); this._tint = value;
} this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
}
//一些静态类方法 //一些静态类方法
/** /**
......
...@@ -18,7 +18,6 @@ const padding = 10; ...@@ -18,7 +18,6 @@ const padding = 10;
* @public * @public
*/ */
export class TextField extends Sprite { export class TextField extends Sprite {
canvas: HTMLCanvasElement; canvas: HTMLCanvasElement;
context: CanvasRenderingContext2D; context: CanvasRenderingContext2D;
/** /**
...@@ -231,6 +230,8 @@ export class TextField extends Sprite { ...@@ -231,6 +230,8 @@ export class TextField extends Sprite {
private _lineType: TEXT_lINETYPE = TEXT_lINETYPE.SINGLE; private _lineType: TEXT_lINETYPE = TEXT_lINETYPE.SINGLE;
protected _text: string = "";
/** /**
* 文本内容 * 文本内容
* @property text * @property text
...@@ -244,7 +245,7 @@ export class TextField extends Sprite { ...@@ -244,7 +245,7 @@ export class TextField extends Sprite {
} }
public get text(): string { public get text(): string {
return this._text; return this.pureText;
} }
protected _setText(value) { protected _setText(value) {
...@@ -256,7 +257,49 @@ export class TextField extends Sprite { ...@@ -256,7 +257,49 @@ export class TextField extends Sprite {
} }
} }
protected _text: string = ""; protected _textFlow: any;
protected _pureText = '';
get textFlow(): any {
return this._textFlow;
}
set textFlow(value: any) {
this._textFlow = value;
this.dirty = true;
let text = '';
for (let item of this._textFlow) {
text += item.text;
}
this._pureText = text;
}
get isPureText() {
return !this._textFlow || this._textFlow.length == 0;
}
get pureText() {
return this.isPureText ? this._text : this._pureText;
}
protected getStyle(index) {
if (!this.textFlow) {
return null;
}
let targetItem;
let count = 0;
for (let item of this._textFlow) {
count += item.text.length;
if (index < count) {
targetItem = item;
break;
}
}
return targetItem.style;
}
/** /**
* 文本的css字体样式 * 文本的css字体样式
...@@ -292,7 +335,6 @@ export class TextField extends Sprite { ...@@ -292,7 +335,6 @@ export class TextField extends Sprite {
this._size = value; this._size = value;
this.dirty = true; this.dirty = true;
} }
;
} }
public get size(): number { public get size(): number {
...@@ -314,7 +356,6 @@ export class TextField extends Sprite { ...@@ -314,7 +356,6 @@ export class TextField extends Sprite {
this._fillColor = value; this._fillColor = value;
this.dirty = true; this.dirty = true;
} }
;
} }
public get fillColor(): any { public get fillColor(): any {
...@@ -336,7 +377,6 @@ export class TextField extends Sprite { ...@@ -336,7 +377,6 @@ export class TextField extends Sprite {
this._strokeColor = value; this._strokeColor = value;
this.dirty = true; this.dirty = true;
} }
;
} }
public get strokeColor(): string { public get strokeColor(): string {
...@@ -358,7 +398,6 @@ export class TextField extends Sprite { ...@@ -358,7 +398,6 @@ export class TextField extends Sprite {
this._stroke = value; this._stroke = value;
this.dirty = true; this.dirty = true;
} }
;
} }
public get stroke(): number { public get stroke(): number {
...@@ -380,7 +419,6 @@ export class TextField extends Sprite { ...@@ -380,7 +419,6 @@ export class TextField extends Sprite {
this._italic = value; this._italic = value;
this.dirty = true; this.dirty = true;
} }
;
} }
public get italic(): boolean { public get italic(): boolean {
...@@ -402,7 +440,6 @@ export class TextField extends Sprite { ...@@ -402,7 +440,6 @@ export class TextField extends Sprite {
this._bold = value; this._bold = value;
this.dirty = true; this.dirty = true;
} }
;
} }
public get bold(): boolean { public get bold(): boolean {
...@@ -423,7 +460,6 @@ export class TextField extends Sprite { ...@@ -423,7 +460,6 @@ export class TextField extends Sprite {
this._border = value; this._border = value;
this.dirty = true; this.dirty = true;
} }
;
} }
public get border(): boolean { public get border(): boolean {
...@@ -512,8 +548,9 @@ export class TextField extends Sprite { ...@@ -512,8 +548,9 @@ export class TextField extends Sprite {
*/ */
public updateText(): void { public updateText(): void {
let s: TextField = this; let s: TextField = this;
let text = s._pureText;
//如果没有文本 //如果没有文本
if (!s._text) { if (!text) {
s.canvas.width = 0; s.canvas.width = 0;
s.canvas.height = 0; s.canvas.height = 0;
s._localBoundsSelf.clear(); s._localBoundsSelf.clear();
...@@ -521,12 +558,13 @@ export class TextField extends Sprite { ...@@ -521,12 +558,13 @@ export class TextField extends Sprite {
this.updateTexture(); this.updateTexture();
return return
} }
let measureCache = {};
if (!s.dirty) return; if (!s.dirty) return;
s.dirty = false; s.dirty = false;
s._text += ""; text += "";
let can = s.canvas; let can = s.canvas;
let ctx = s.context; let ctx = s.context;
let hardLines: any = s._text.toString().split(/(?:\r\n|\r|\n)/); let hardLines: any = text.toString().split(/(?:\r\n|\r|\n)/);
let realLines: any = []; let realLines: any = [];
s.realLines = realLines; s.realLines = realLines;
s._prepContext(ctx); s._prepContext(ctx);
...@@ -534,7 +572,7 @@ export class TextField extends Sprite { ...@@ -534,7 +572,7 @@ export class TextField extends Sprite {
let textWidth = s._width; let textWidth = s._width;
// let lineH = s._lineSpacing + s.size; // let lineH = s._lineSpacing + s.size;
//单行文本时 //单行文本时
if (s._text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) { if (text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
realLines[realLines.length] = hardLines[0]; realLines[realLines.length] = hardLines[0];
let str = hardLines[0]; let str = hardLines[0];
let lineW = s._getMeasuredWidth(str); let lineW = s._getMeasuredWidth(str);
...@@ -559,17 +597,13 @@ export class TextField extends Sprite { ...@@ -559,17 +597,13 @@ export class TextField extends Sprite {
} }
} else { } else {
//textWidth取每行最大值,如果没设置过textWidth //textWidth取每行最大值,如果没设置过textWidth
let measureCache = {};
const shouldMeasureTextWidth = !textWidth; const shouldMeasureTextWidth = !textWidth;
for (let i = 0, l = hardLines.length; i < l; i++) { for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i]; let str = hardLines[i];
if (!str) continue; if (!str) continue;
let lineWidth = 0; let lineWidth = 0;
for (let char of str) { for (let char of str) {
let charWidth = measureCache[char]; let charWidth = measureChar(char);
if (charWidth === undefined) {
charWidth = measureCache[char] = s._getMeasuredWidth(char);
}
lineWidth += charWidth; lineWidth += charWidth;
} }
if (shouldMeasureTextWidth) { if (shouldMeasureTextWidth) {
...@@ -630,13 +664,46 @@ export class TextField extends Sprite { ...@@ -630,13 +664,46 @@ export class TextField extends Sprite {
upY = s._height - trueHeight; upY = s._height - trueHeight;
} }
} }
let index = 0;
for (let i = 0; i < realLines.length; i++) { for (let i = 0; i < realLines.length; i++) {
if (s.stroke) { let line = realLines[i];
ctx.strokeStyle = s.strokeColor; if (s.isPureText) {
ctx.lineWidth = s.stroke * 2; let y = upY + i * lineH;
ctx.strokeText(realLines[i], 0, upY + i * lineH, maxW); if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2;
ctx.strokeText(line, 0, y, maxW);
}
ctx.fillText(line, 0, y, maxW);
} else {
let x = 0;
for (let j = 0, lj = line.length; j < lj; j++) {
const char = line[j];
let style = s.getStyle(index);
if (style) {
if (style.hasOwnProperty('color')) {
ctx.fillStyle = style.color;
}
if (style.hasOwnProperty('stroke')) {
ctx.lineWidth = style.stroke * 2;
}
if (style.hasOwnProperty('strokeColor')) {
ctx.strokeStyle = style.strokeColor;
}
} else {
ctx.fillStyle = s.fillColor;
ctx.lineWidth = s.stroke;
ctx.strokeStyle = s.strokeColor;
}
let y = upY + i * lineH;
if (ctx.lineWidth > 0) {
ctx.strokeText(char, x, y);
}
ctx.fillText(char, x, y);
x += measureChar(char);
index++;
}
} }
ctx.fillText(realLines[i], 0, upY + i * lineH, maxW);
} }
//offset用_anchorTexture代替 //offset用_anchorTexture代替
s.offsetX = -padding; s.offsetX = -padding;
...@@ -651,7 +718,15 @@ export class TextField extends Sprite { ...@@ -651,7 +718,15 @@ export class TextField extends Sprite {
s._localBoundsSelf.width = maxW; s._localBoundsSelf.width = maxW;
s._localBoundsSelf.height = maxH; s._localBoundsSelf.height = maxH;
//修改texture及baseTexture属性 //修改texture及baseTexture属性
s.updateTexture() s.updateTexture();
function measureChar(char) {
let w = measureCache[char];
if (w === undefined) {
w = measureCache[char] = s._getMeasuredWidth(char);
}
return w;
}
} }
/** /**
......
...@@ -8,7 +8,7 @@ import { BLEND_MODES, DATA_URI, RENDERER_TYPE, URL_FILE_EXTENSION } from "../con ...@@ -8,7 +8,7 @@ import { BLEND_MODES, DATA_URI, RENDERER_TYPE, URL_FILE_EXTENSION } from "../con
export * from './twiddle'; export * from './twiddle';
export { default as toDisplayDataURL } from "./toDisplayDataURL"; export { default as toDisplayDataURL } from "./toDisplayDataURL";
export { default as determineCrossOrigin } from './determineCrossOrigin'; export { default as determineCrossOrigin } from './determineCrossOrigin';
export * from './DrawAllToCanvas'
let nextUid = 0; let nextUid = 0;
......
...@@ -24,6 +24,8 @@ export * from "./2d/ui"; ...@@ -24,6 +24,8 @@ export * from "./2d/ui";
export * from './2d/tween' export * from './2d/tween'
export * from './2d/net' export * from './2d/net'
export {GlobalPro, DrawAllToCanvas} from './2d/utils'
export { default as toDisplayDataURL } from "./2d/utils/toDisplayDataURL"; export { default as toDisplayDataURL } from "./2d/utils/toDisplayDataURL";
export { inputFeildIosEnable } from "./2d/utils/index" export { inputFeildIosEnable } from "./2d/utils/index"
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
*/ */
import {VM} from "./VM"; import {VM} from "./VM";
import {getDataByPath, linkedFlag, nodeScheme, objClone} from "../utils"; import {getDataByPath, linkedFlag, nodeScheme, objClone} from "../utils";
import {findNodeByUUID} from "../node-utils";
import {dataCenter} from "../game-warpper/data-center"; import {dataCenter} from "../game-warpper/data-center";
import {env} from "../game-warpper/enviroment"; import {env} from "../game-warpper/enviroment";
import {getLogSwitch, Logs} from "../log-switch"; import {getLogSwitch, Logs} from "../log-switch";
...@@ -231,7 +230,7 @@ export class Process { ...@@ -231,7 +230,7 @@ export class Process {
} 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, '');
if (uuid) { if (uuid) {
props[key] = findNodeByUUID(this._vm.globalContext.gameStage, uuid); props[key] = this._vm.globalContext.gameStage.findChildByUUID(uuid);
} }
} else if (originProps[key] !== undefined) { } else if (originProps[key] !== undefined) {
props[key] = originProps[key]; props[key] = originProps[key];
......
...@@ -15,7 +15,7 @@ const scriptDefs = {}; ...@@ -15,7 +15,7 @@ const scriptDefs = {};
*/ */
export function applyScript(ctor: Function) { export function applyScript(ctor: Function) {
ctor.prototype.applyScripts = function () { ctor.prototype.applyScripts = function () {
let scriptsProxy = this.scriptsProxy = new ScriptsProxy(this); let scriptsProxy = this.scripts = new ScriptsProxy(this);
this.addEventListener(Event.ENTER_FRAME, scriptsProxy.onEnterFrame, scriptsProxy); this.addEventListener(Event.ENTER_FRAME, scriptsProxy.onEnterFrame, scriptsProxy);
this.addEventListener(Event.ADDED_TO_STAGE, scriptsProxy.onAddedToStage, scriptsProxy); this.addEventListener(Event.ADDED_TO_STAGE, scriptsProxy.onAddedToStage, scriptsProxy);
......
...@@ -8,14 +8,13 @@ import {loadAssets} from "./assets-manager"; ...@@ -8,14 +8,13 @@ import {loadAssets} from "./assets-manager";
import {instantiate} from "./view-interpreter"; import {instantiate} from "./view-interpreter";
import {dataCenter, DataCenter} from "./data-center"; import {dataCenter, DataCenter} from "./data-center";
import {setProcessMetaLibs} from "../behavior-runtime"; import {setProcessMetaLibs} from "../behavior-runtime";
import {registerScripts} from "..";
import {Tween} from "../../2d/tween"; import {Tween} from "../../2d/tween";
import {Rect} from "./nodes"; import {Rect} from "./nodes";
import {injectEnv} from "./enviroment"; import {injectEnv} from "./enviroment";
import {registerCustomModuleFromConfig} from "./custom-module";
import {hideLoadingView, showLoadingView} from "./loading-view";
import {Toast} from "./Toast"; import {Toast} from "./Toast";
import {arrayFind} from "../utils"; import {arrayFind} from "../utils";
import {registerScripts} from "..";
import {registerCustomModuleFromConfig} from "./custom-module";
/** /**
* 游戏舞台 * 游戏舞台
...@@ -111,7 +110,6 @@ export class GameStage extends Container { ...@@ -111,7 +110,6 @@ export class GameStage extends Container {
} }
} }
showLoadingView();
await loadAssets(assets, p).catch(e => { await loadAssets(assets, p).catch(e => {
console.log(e); console.log(e);
}); });
...@@ -124,7 +122,6 @@ export class GameStage extends Container { ...@@ -124,7 +122,6 @@ export class GameStage extends Container {
} }
} }
} }
hideLoadingView();
this.start(); this.start();
...@@ -157,10 +154,12 @@ export class GameStage extends Container { ...@@ -157,10 +154,12 @@ export class GameStage extends Container {
} }
setProcessMetaLibs(processes, builtinProcesses); setProcessMetaLibs(processes, builtinProcesses);
let sceneEntry = this.instantiateView(entrySceneView); setTimeout(()=>{
if (sceneEntry) { let sceneEntry = this.instantiateView(entrySceneView);
this._sceneContainer.push(sceneEntry); if (sceneEntry) {
} this._sceneContainer.push(sceneEntry);
}
})
} }
/** /**
......
...@@ -2,16 +2,6 @@ ...@@ -2,16 +2,6 @@
* Created by rockyl on 2019-11-22. * Created by rockyl on 2019-11-22.
*/ */
/*const template = `
<div id="loadingWrapper" style="position: absolute; left: 0;top: 0;right: 0;bottom: 0;">
<div id="loadingTrack" style="width: 100px;height: 20px;border: 1px solid deepskyblue;">
<div id="loadingThumb">
</div>
</div>
</div>
`;*/
const template = ` const template = `
<div style=" <div style="
position: absolute; position: absolute;
...@@ -34,18 +24,15 @@ let container = document.createElement('div'); ...@@ -34,18 +24,15 @@ let container = document.createElement('div');
container.innerHTML = template; container.innerHTML = template;
let wrapper = container.removeChild(container.children[0]); let wrapper = container.removeChild(container.children[0]);
export function showLoadingView() { export default {
if (!wrapper.parentElement) { onProgress(done, total) {
document.body.appendChild(wrapper); if (!wrapper.parentElement) {
} document.body.appendChild(wrapper);
} }
},
export function hideLoadingView() { onComplete() {
if (wrapper.parentElement) { if (wrapper.parentElement) {
document.body.removeChild(wrapper); document.body.removeChild(wrapper);
} }
} },
export function setLoadingViewProgress(current, total) {
} }
...@@ -32,18 +32,18 @@ export function loadAssets(config, onProgress?, onComplete?) { ...@@ -32,18 +32,18 @@ export function loadAssets(config, onProgress?, onComplete?) {
config.map(assetConfig => { config.map(assetConfig => {
assetsConfig.push(assetConfig); assetsConfig.push(assetConfig);
const loadFunc = loaderMapping[assetConfig.ext]; const loadFunc = loaderMapping[assetConfig.ext];
if(loadFunc){ if (loadFunc) {
let method = globalLoader['load' + loadFunc]; let method = globalLoader['load' + loadFunc];
return method.call(globalLoader, assetConfig.url, assetConfig.uuid).then( return method.call(globalLoader, assetConfig.url, assetConfig.uuid).then(
(data)=>{ (data) => {
loaded++; loaded++;
onProgress && onProgress(loaded, total); onProgress && onProgress(loaded, total);
}, },
(error)=>{ (error) => {
failedList.push(assetConfig.url); failedList.push(assetConfig.url);
} }
); );
}else{ } else {
loaded++; loaded++;
onProgress && onProgress(loaded, total); onProgress && onProgress(loaded, total);
return Promise.resolve(); return Promise.resolve();
...@@ -64,14 +64,29 @@ export function loadAssets(config, onProgress?, onComplete?) { ...@@ -64,14 +64,29 @@ export function loadAssets(config, onProgress?, onComplete?) {
* 根据uuid获取素材配置 * 根据uuid获取素材配置
* @param uuid * @param uuid
*/ */
export function getAssetByUUID(uuid) { export function getAssetByUUID(uuid): any {
return arrayFind(assetsConfig,item => item.uuid === uuid); return arrayFind(assetsConfig, item => item.uuid === uuid);
} }
/** /**
* 根据name获取素材配置 * 根据name获取素材配置
* @param name * @param name
*/ */
export function getAssetByName(name) { export function getAssetByName(name): any {
return arrayFind(assetsConfig,item => item.name === name); let result = arrayFind(assetsConfig, item => item.name === name);
if (result) {
return result;
} else {
for (let assetConfig of assetsConfig) {
let res = engine.globalLoader.get(assetConfig.url);
if (res && res.frames) {
for (let key in res.frames) {
const frame = res.frames[key];
if (frame.name === name) {
return {url: key};
}
}
}
}
}
} }
...@@ -24,7 +24,7 @@ export class DataCenter extends EventDispatcher { ...@@ -24,7 +24,7 @@ export class DataCenter extends EventDispatcher {
* @param origin * @param origin
*/ */
registerGroup(name, origin?) { registerGroup(name, origin?) {
return this.store[name] = origin || {}; return this.store[name] = origin === undefined ? {} : origin;
} }
/** /**
...@@ -50,7 +50,13 @@ export class DataCenter extends EventDispatcher { ...@@ -50,7 +50,13 @@ export class DataCenter extends EventDispatcher {
* @param throwException * @param throwException
*/ */
getDataByPath(path, groupName?, throwException?) { getDataByPath(path, groupName?, throwException?) {
let scope = groupName === undefined ? this.store : this.getGroup(groupName) || this.store; let scope;
if (groupName === undefined) {
scope = this.store;
} else {
let group = this.getGroup(groupName);
scope = group === undefined ? this.store : group;
}
return getDataByPath(scope, path, throwException); return getDataByPath(scope, path, throwException);
} }
...@@ -101,7 +107,7 @@ export class DataCenter extends EventDispatcher { ...@@ -101,7 +107,7 @@ export class DataCenter extends EventDispatcher {
* @param dispatch * @param dispatch
*/ */
increase(groupName, step?, path?, dispatch = true) { increase(groupName, step?, path?, dispatch = true) {
if(step < 0 || step > 0){ if (step < 0 || step > 0) {
let data: any = this.getDataByPath(path, groupName); let data: any = this.getDataByPath(path, groupName);
if (data === undefined) { if (data === undefined) {
data = 0; data = 0;
...@@ -122,6 +128,9 @@ export class DataCenter extends EventDispatcher { ...@@ -122,6 +128,9 @@ export class DataCenter extends EventDispatcher {
* @param dispatch * @param dispatch
*/ */
mutate(groupName, data?, path?, dispatch = true) { mutate(groupName, data?, path?, dispatch = true) {
if (!groupName) {
return;
}
let group = this.getGroup(groupName); let group = this.getGroup(groupName);
if (!group) { if (!group) {
......
...@@ -7,15 +7,23 @@ import {Event} from "../../../2d/events/Event"; ...@@ -7,15 +7,23 @@ import {Event} from "../../../2d/events/Event";
import {FloatDisplay} from "../../../2d/display/FloatDisplay"; import {FloatDisplay} from "../../../2d/display/FloatDisplay";
import {TextField} from "../../../2d/text"; import {TextField} from "../../../2d/text";
import {Point} from "../../../2d/math"; import {Point} from "../../../2d/math";
import {dirtyFieldTrigger} from "../../decorators";
import {VERTICAL_ALIGN} from "../../.."; import {VERTICAL_ALIGN} from "../../..";
export class TextInput extends Label { export class TextInput extends Label {
private _floatDisplay: FloatDisplay; private _floatDisplay: FloatDisplay;
private _placeholderLabel: TextField; private _placeholderLabel: TextField;
private _input: any; private _input: any;
private _placeholder: string = ''; @dirtyFieldTrigger
private _placeholderColor: any = '#666666'; placeholder: string;
private _maxLength: number; @dirtyFieldTrigger
placeholderColor: any = '#666666';
@dirtyFieldTrigger
maxLength: number;
@dirtyFieldTrigger
type: string = 'text';
@dirtyFieldTrigger
pattern: string;
private _oldFillColor; private _oldFillColor;
private _oldStrokeColor; private _oldStrokeColor;
...@@ -30,32 +38,21 @@ export class TextInput extends Label { ...@@ -30,32 +38,21 @@ export class TextInput extends Label {
this.text = ''; this.text = '';
} }
get placeholder(): string { onModify(value, key) {
return this._placeholder; switch (key) {
} case 'placeholder':
if (this._placeholderLabel) {
set placeholder(value: string) { this._placeholderLabel.text = value;
this._placeholder = value; }
this._placeholderLabel.text = value; break;
} case 'placeholderColor':
if (this._placeholderLabel) {
get placeholderColor(): any { this._placeholderLabel.fillColor = value;
return this._placeholderColor; }
} break;
case 'maxLength':
set placeholderColor(value: any) { this.setMaxLength();
this._placeholderColor = value; break;
this._placeholderLabel.fillColor = value;
}
get maxLength(): number {
return this._maxLength;
}
set maxLength(value: number) {
if(this._maxLength != value){
this._maxLength = value;
this.setMaxLength();
} }
} }
...@@ -76,7 +73,7 @@ export class TextInput extends Label { ...@@ -76,7 +73,7 @@ export class TextInput extends Label {
input.addEventListener('blur', this.onBlur); input.addEventListener('blur', this.onBlur);
let pl = this._placeholderLabel = new TextField(); let pl = this._placeholderLabel = new TextField();
pl.fillColor = this._placeholderColor; pl.fillColor = this.placeholderColor;
this.verticalAlign = pl.verticalAlign = VERTICAL_ALIGN.MIDDLE; this.verticalAlign = pl.verticalAlign = VERTICAL_ALIGN.MIDDLE;
...@@ -95,7 +92,7 @@ export class TextInput extends Label { ...@@ -95,7 +92,7 @@ export class TextInput extends Label {
private setMaxLength() { private setMaxLength() {
let value = this._text; let value = this._text;
let maxLength = this._maxLength; let maxLength = this.maxLength;
if (maxLength > 0 && value && value.length > maxLength) { if (maxLength > 0 && value && value.length > maxLength) {
this.text = value.substr(0, maxLength); this.text = value.substr(0, maxLength);
} }
...@@ -103,14 +100,14 @@ export class TextInput extends Label { ...@@ -103,14 +100,14 @@ export class TextInput extends Label {
private showPlaceholderLabel(value) { private showPlaceholderLabel(value) {
let pl = this._placeholderLabel; let pl = this._placeholderLabel;
if(value){ if (value) {
let pl = this._placeholderLabel; let pl = this._placeholderLabel;
if (pl.parent) { if (pl.parent) {
pl.parent.removeChild(pl); pl.parent.removeChild(pl);
} }
}else{ } else {
if (!pl.parent) { if (!pl.parent) {
pl.text = this._placeholder; pl.text = this.placeholder;
pl.size = this.size; pl.size = this.size;
pl.font = this.font; pl.font = this.font;
this.addChildAt(pl, 0); this.addChildAt(pl, 0);
...@@ -147,12 +144,23 @@ export class TextInput extends Label { ...@@ -147,12 +144,23 @@ export class TextInput extends Label {
this._floatDisplay.alpha = 1; this._floatDisplay.alpha = 1;
input.style.pointerEvents = 'auto'; input.style.pointerEvents = 'auto';
if(this._maxLength > 0){ const maxLength = this.maxLength;
input.maxLength = this._maxLength; if (maxLength > 0) {
}else{ input.maxLength = maxLength;
} else {
input.removeAttribute('maxLength') input.removeAttribute('maxLength')
} }
if (this.pattern) {
input.pattern = this.pattern;
} else {
input.removeAttribute('pattern')
}
if (this.type) {
input.type = this.type;
}
input.focus(); input.focus();
this.dispatchEvent(Event.FOCUS); this.dispatchEvent(Event.FOCUS);
...@@ -178,8 +186,8 @@ export class TextInput extends Label { ...@@ -178,8 +186,8 @@ export class TextInput extends Label {
this.setBlur(); this.setBlur();
}; };
private onClickStage(e){ private onClickStage(e) {
if(e.currentTarget !== this){ if (e.currentTarget !== this) {
this.setBlur(); this.setBlur();
} }
} }
......
...@@ -7,35 +7,59 @@ import {injectProperties} from "../utils"; ...@@ -7,35 +7,59 @@ import {injectProperties} from "../utils";
const instances = {}; const instances = {};
export function playSound(uuid, options = {}, name?) { export function playSound(uuid, options: any = {}, name?) {
let assetConfig = getAssetByUUID(uuid); let assetConfig = getAssetByUUID(uuid);
if (assetConfig) { if (assetConfig) {
let url = assetConfig.url; let url = assetConfig.url;
let opts: any = { let opts: any = {
src: [url], src: [url],
autoplay: true, autoplay: false,
}; };
injectProperties(opts, options); injectProperties(opts, options);
let sound = new Howl(opts); const key = name || uuid;
if (name !== undefined) { const {keep = false} = opts;
instances[name] = sound;
let sound;
if (keep) {
const data = instances[key];
if (data) {
sound = data.sound;
}
}
if (!sound) {
sound = new Howl(opts);
}
instances[key] = {
sound,
keep,
};
if (!keep) {
sound.on('end', function () { sound.on('end', function () {
delete instances[name]; destroySound(key);
}); });
} }
sound.play();
return sound; return sound;
} }
} }
export function stopSound(name){ export function stopSound(name) {
let sound = instances[name]; let {sound, keep} = instances[name];
if(sound){ if (sound) {
sound.stop(); sound.stop();
delete instances[name]; if (!keep) {
destroySound(name);
}
} }
} }
export function destroySound(name) {
delete instances[name];
}
...@@ -11,10 +11,11 @@ export * from './game-warpper' ...@@ -11,10 +11,11 @@ export * from './game-warpper'
export * from './behavior-runtime' export * from './behavior-runtime'
export * from './web' export * from './web'
export * from './log-switch' export * from './log-switch'
import {instantiate} from './game-warpper/view-interpreter' import {instantiate, registerNodeType} from './game-warpper/view-interpreter'
export {Howl, Howler} from 'howler'; export {Howl, Howler} from 'howler';
export { export {
instantiate instantiate,
registerNodeType,
} }
...@@ -8,17 +8,18 @@ import {GameStage} from "./game-warpper"; ...@@ -8,17 +8,18 @@ import {GameStage} from "./game-warpper";
import {setGlobalContext} from "./behavior-runtime"; import {setGlobalContext} from "./behavior-runtime";
import {globalLoader} from "../2d/loader/Loader"; import {globalLoader} from "../2d/loader/Loader";
import {Event} from "../2d/events/Event"; import {Event} from "../2d/events/Event";
import builtinLoadingView from "./game-warpper/LoadingView";
export let gameStage: GameStage; export let gameStage: GameStage;
export function launch(url, onAssetsProgress, onAssetsComplete, onStart) { export function launch(url, loadingDelegate?, onStart?) {
return globalLoader.loadJson(url) return globalLoader.loadJson(url)
.then(config => { .then(config => {
return launchWithConfig(config, onAssetsProgress, onAssetsComplete, onStart); return launchWithConfig(config, loadingDelegate, onStart);
}); });
} }
export function launchWithLocalStorage(id, onAssetsProgress, onAssetsComplete, onStart) { export function launchWithLocalStorage(id, loadingDelegate?, onStart?) {
const storeKey = 'preview-project-' + id; const storeKey = 'preview-project-' + id;
let storeData = localStorage.getItem(storeKey); let storeData = localStorage.getItem(storeKey);
let {data, processes, scripts, customs,} = JSON.parse(storeData); let {data, processes, scripts, customs,} = JSON.parse(storeData);
...@@ -27,10 +28,20 @@ export function launchWithLocalStorage(id, onAssetsProgress, onAssetsComplete, o ...@@ -27,10 +28,20 @@ export function launchWithLocalStorage(id, onAssetsProgress, onAssetsComplete, o
registerScripts(scripts); registerScripts(scripts);
registerCustomModuleFromConfig(customs); registerCustomModuleFromConfig(customs);
return launchWithConfig(data, onAssetsProgress, onAssetsComplete, onStart); return launchWithConfig(data, loadingDelegate, onStart);
} }
export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onStart) { export function launchWithWindowVariable(name, loadingDelegate?, onStart?) {
let {data, processes, scripts, customs,} = window[name];
setProcessMetaLibs(processes);
registerScripts(scripts);
registerCustomModuleFromConfig(customs);
return launchWithConfig(data, loadingDelegate, onStart);
}
export function launchWithConfig(config, loadingDelegate?, onStart?) {
return new Promise(resolve => { return new Promise(resolve => {
const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.options; const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.options;
let stage = window['stage'] = new Stage( let stage = window['stage'] = new Stage(
...@@ -39,7 +50,7 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onS ...@@ -39,7 +50,7 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onS
designHeight || 1334, designHeight || 1334,
frameRate || 60, frameRate || 60,
scaleMode || StageScaleMode.FIXED_WIDTH, scaleMode || StageScaleMode.FIXED_WIDTH,
rendererType || RENDERER_TYPE.WEBGL rendererType || RENDERER_TYPE.WEBGL,
); );
Stage.flushAll(); Stage.flushAll();
...@@ -50,7 +61,13 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onS ...@@ -50,7 +61,13 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onS
}); });
stage.addChild(gameStage); stage.addChild(gameStage);
gameStage.launch(config, onAssetsProgress, onAssetsComplete, onStart); let delegate = loadingDelegate || builtinLoadingView;
gameStage.launch(config, function(done, total){
delegate.onProgress && delegate.onProgress(done, total)
}, function(){
delegate.onComplete && delegate.onComplete();
}, onStart);
}); });
resolve(gameStage); resolve(gameStage);
......
/**
* Created by rockyl on 2019-11-13.
*/
export function findNodeByUUID(node, uuid) {
if (node.uuid === uuid) {
return node;
}
if(node.children && node.children.length > 0){
for (let child of node.children) {
let target = findNodeByUUID(child, uuid);
if (target) {
return target;
}
}
}
}
...@@ -134,6 +134,10 @@ export function obj2query(obj: any): string { ...@@ -134,6 +134,10 @@ export function obj2query(obj: any): string {
return arr.join('&'); return arr.join('&');
} }
function requireForCJS(id){
return window[id];
}
/** /**
* 导入cjs包装的代码 * 导入cjs包装的代码
* @param code * @param code
...@@ -141,11 +145,11 @@ export function obj2query(obj: any): string { ...@@ -141,11 +145,11 @@ export function obj2query(obj: any): string {
*/ */
export function importCJSCode(code, node?) { export function importCJSCode(code, node?) {
if (node) { if (node) {
let create = new Function('module', code); let create = new Function('module', 'require', code);
let module = { let module = {
exports: {}, exports: {},
}; };
create(module); create(module, requireForCJS);
return module.exports; return module.exports;
} else { } else {
let create = new Function('exports', code); let create = new Function('exports', code);
...@@ -253,7 +257,7 @@ export function strShort(str, limit, replace = '…'){ ...@@ -253,7 +257,7 @@ export function strShort(str, limit, replace = '…'){
export function instantiateScript(node, ScriptConfig) { export function instantiateScript(node, ScriptConfig) {
const {script: scriptName, props, disabled} = ScriptConfig; const {script: scriptName, props, disabled} = ScriptConfig;
const script = node.scriptsProxy.add(scriptName, props, disabled); const script = node.scripts.add(scriptName, props, disabled);
} }
export function injectProperties(target, source) { export function injectProperties(target, source) {
......
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