Commit eb2f29c0 authored by rockyl's avatar rockyl

过程、脚本、自定义模块代码抽离功能

parent e9c9c132
...@@ -128,7 +128,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -128,7 +128,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
for (var i = 0, len = eventTypes[type].length; i < len; i++) { for (var i = 0, len = eventTypes[type].length; i < len; i++) {
var ee = eventTypes[type][i]; var ee = eventTypes[type][i];
if (ee.fn === listener && ee.context === context) { if (ee.fn === listener && ee.context === context) {
console.log("已添加过该事件");
return; return;
} }
} }
...@@ -1615,7 +1614,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -1615,7 +1614,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this._host.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, this); this._host.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, this);
}; };
AdjustProxy.prototype.onRemovedFromStage = function (e) { AdjustProxy.prototype.onRemovedFromStage = function (e) {
this._host.parent.removeEventListener(Event.RESIZE, this.onResize);
this._host.removeEventListener(Event.RESIZE, this.onResize, this); this._host.removeEventListener(Event.RESIZE, this.onResize, this);
this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame); this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
}; };
...@@ -1723,7 +1721,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -1723,7 +1721,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
node[targetKey] = value; node[targetKey] = value;
} }
function getDataByPath(scope, path, throwException) { function getDataByPath(scope, path, throwException) {
var func = new Function('scope', "return scope." + path); var func = new Function('scope', "return scope" + (path === undefined ? '' : ('.' + path)));
try { try {
return func(scope); return func(scope);
} }
...@@ -2070,38 +2068,38 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2070,38 +2068,38 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
ScriptBase.prototype.mounted = function () { Object.defineProperty(ScriptBase.prototype, "disabled", {
};
ScriptBase.prototype.destroy = function () {
};
ScriptBase.prototype.update = function (t) {
};
ScriptBase.prototype.awake = function () {
};
ScriptBase.prototype.sleep = function () {
};
return ScriptBase;
}());
function registerScriptDef(id, def) {
scriptDefs[id] = def;
Object.defineProperty(def, 'disabled', {
get: function () { get: function () {
return !!this._disabled; return this._disabled;
}, },
set: function (v) { set: function (v) {
if (this._disabled !== v) { if (this._disabled !== v) {
this._disabled = v; this._disabled = v;
if (this._disabled) { if (this._disabled) {
this.awake(); this.sleep();
} }
else { else {
this.sleep(); this.awake();
} }
} }
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
ScriptBase.prototype.mounted = function () {
};
ScriptBase.prototype.destroy = function () {
};
ScriptBase.prototype.update = function (t) {
};
ScriptBase.prototype.awake = function () {
};
ScriptBase.prototype.sleep = function () {
};
return ScriptBase;
}());
function registerScriptDef(id, def) {
scriptDefs[id] = def;
} }
function registerScripts(scripts) { function registerScripts(scripts) {
for (var id in scripts) { for (var id in scripts) {
...@@ -2158,8 +2156,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2158,8 +2156,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
ScriptsProxy.prototype.get = function (name) { ScriptsProxy.prototype.get = function (id) {
return this._scripts.filter(function (script) { return script.constructor['name'] === name; }); return this._scripts.filter(function (script) {
return script.constructor['id'] === id;
});
}; };
ScriptsProxy.prototype.onAddedToStage = function () { ScriptsProxy.prototype.onAddedToStage = function () {
for (var _i = 0, _a = this._scripts; _i < _a.length; _i++) { for (var _i = 0, _a = this._scripts; _i < _a.length; _i++) {
...@@ -2219,8 +2219,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2219,8 +2219,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
DataCenter.prototype.getGroup = function (name) { DataCenter.prototype.getGroup = function (name) {
return this.store[name]; return this.store[name];
}; };
DataCenter.prototype.getDataByPath = function (path, throwException) { DataCenter.prototype.getDataByPath = function (path, groupName, throwException) {
return getDataByPath(this.store, path, throwException); var scope = groupName === undefined ? this.store : this.getGroup(groupName) || this.store;
return getDataByPath(scope, path, throwException);
}; };
DataCenter.prototype.getDataByName = function (name, throwException) { DataCenter.prototype.getDataByName = function (name, throwException) {
var watcher = this.getWatcher(name); var watcher = this.getWatcher(name);
...@@ -2236,10 +2237,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2236,10 +2237,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var name = args[0]; var name = args[0];
var watcher = this.getWatcher(name); var watcher = this.getWatcher(name);
try { try {
var data = this.getDataByPath(watcher.path, true); var data = this.getDataByPath(watcher.path, undefined, true);
if (args[1] !== undefined) { if (args[1] !== undefined) {
data = data[args[1]]; data = data[args[1]];
} }
if (data === undefined) {
data = '';
}
result = result.replace(new RegExp('\\$\\{' + escape.replace(/\|/g, '\\|') + '\\}', 'g'), data); result = result.replace(new RegExp('\\$\\{' + escape.replace(/\|/g, '\\|') + '\\}', 'g'), data);
} }
catch (e) { catch (e) {
...@@ -2247,13 +2251,27 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2247,13 +2251,27 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
return result; return result;
}; };
DataCenter.prototype.mutate = function (name, data, path, dispatch) { DataCenter.prototype.increase = function (groupName, step, path, dispatch) {
if (dispatch === void 0) { dispatch = true; }
if (step < 0 || step > 0) {
var data = this.getDataByPath(path, groupName);
if (data === undefined) {
data = 0;
}
else {
data = parseInt(data);
}
data += step;
this.mutate(groupName, data, path, dispatch);
}
};
DataCenter.prototype.mutate = function (groupName, data, path, dispatch) {
if (dispatch === void 0) { dispatch = true; } if (dispatch === void 0) { dispatch = true; }
var group = this.getGroup(name); var group = this.getGroup(groupName);
if (!group) { if (!group) {
this.registerGroup(name); this.registerGroup(groupName);
} }
if (data) { if (data !== undefined) {
if (path) { if (path) {
var func = new Function('scope', 'data', "scope." + path + "=data"); var func = new Function('scope', 'data', "scope." + path + "=data");
try { try {
...@@ -2264,13 +2282,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2264,13 +2282,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
} }
else { else {
this.registerGroup(name, data); this.registerGroup(groupName, data);
} }
} }
if (dispatch) { if (dispatch) {
for (var _i = 0, _a = this.watchers; _i < _a.length; _i++) { for (var _i = 0, _a = this.watchers; _i < _a.length; _i++) {
var watcher = _a[_i]; var watcher = _a[_i];
if (watcher.path.indexOf(name) === 0) { if (watcher.path.indexOf(groupName) === 0) {
this.dispatchEvent(watcher.name, { this.dispatchEvent(watcher.name, {
name: watcher.name, name: watcher.name,
path: watcher.path, path: watcher.path,
...@@ -2280,7 +2298,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2280,7 +2298,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
} }
globalEvent.dispatchEvent(DATA_CENTER_EVENT, { globalEvent.dispatchEvent(DATA_CENTER_EVENT, {
name: name, name: groupName,
path: path, path: path,
data: data, data: data,
}); });
...@@ -2427,6 +2445,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2427,6 +2445,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
console.log(); console.log();
} }
globalContext = this._vm.globalContext; globalContext = this._vm.globalContext;
globalContext.dataCenter = globalContext.gameStage.dataCenter;
return [4, func(payload, this._config.props, this._target, globalContext, this._vm)]; return [4, func(payload, this._config.props, this._target, globalContext, this._vm)];
case 1: case 1:
result = _a.sent(); result = _a.sent();
...@@ -10143,6 +10162,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -10143,6 +10162,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
url = urlJoin(url, queryStr); url = urlJoin(url, queryStr);
} }
_req_1.open(method, url, true); _req_1.open(method, url, true);
if (!isGet) {
_req_1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
_req_1.responseType = type; _req_1.responseType = type;
if (isGet) { if (isGet) {
_req_1.send(); _req_1.send();
...@@ -10280,7 +10302,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -10280,7 +10302,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this._textAlign = exports.TEXT_ALIGN.LEFT; _this._textAlign = exports.TEXT_ALIGN.LEFT;
_this._verticalAlign = exports.VERTICAL_ALIGN.UP; _this._verticalAlign = exports.VERTICAL_ALIGN.UP;
_this._lineSpacing = 14; _this._lineSpacing = 14;
_this._lineType = exports.TEXT_lINETYPE.SINGLE; _this._lineType = exports.TEXT_lINETYPE.MULTI;
_this._text = ""; _this._text = "";
_this._font = "Arial"; _this._font = "Arial";
_this._size = 12; _this._size = 12;
...@@ -10418,6 +10440,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -10418,6 +10440,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
TextField.prototype._setText = function (value) { TextField.prototype._setText = function (value) {
this._text = value; this._text = value;
this.dirty = true; this.dirty = true;
this.dispatchEvent(Event.RESIZE);
}; };
Object.defineProperty(TextField.prototype, "font", { Object.defineProperty(TextField.prototype, "font", {
get: function () { get: function () {
...@@ -10606,24 +10629,34 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -10606,24 +10629,34 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
} }
else { else {
var measureCache = {};
if (!textWidth) { if (!textWidth) {
for (var i = 0, l = hardLines.length; i < l; i++) { for (var i = 0, l = hardLines.length; i < l; i++) {
var str = hardLines[i]; var str = hardLines[i];
if (!str) if (!str)
continue; continue;
textWidth = Math.max(s._getMeasuredWidth(str), textWidth); var lineWidth = 0;
for (var _i = 0, str_1 = str; _i < str_1.length; _i++) {
var char = str_1[_i];
var charWidth = measureCache[char];
if (charWidth === undefined) {
charWidth = measureCache[char] = s._getMeasuredWidth(char);
}
lineWidth += charWidth;
}
textWidth = Math.max(lineWidth, textWidth);
} }
} }
for (var i = 0, l = hardLines.length; i < l; i++) { for (var i = 0, l = hardLines.length; i < l; i++) {
var str = hardLines[i]; var str = hardLines[i];
if (!str) if (!str)
continue; continue;
var w = s._getMeasuredWidth(str[0]); var w = measureCache[str[0]];
var lineStr = str[0]; var lineStr = str[0];
var wordW = 0; var wordW = 0;
var strLen = str.length; var strLen = str.length;
for (var j = 1; j < strLen; j++) { for (var j = 1; j < strLen; j++) {
wordW = ctx.measureText(str[j]).width; wordW = measureCache[str[j]];
w += wordW; w += wordW;
if (w > textWidth) { if (w > textWidth) {
realLines[realLines.length] = lineStr; realLines[realLines.length] = lineStr;
...@@ -12285,7 +12318,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -12285,7 +12318,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (url.indexOf(assetScheme) === 0) { if (url.indexOf(assetScheme) === 0) {
var uuid = url.replace(assetScheme, ''); var uuid = url.replace(assetScheme, '');
var assetConfig = getAssetByUUID(uuid); var assetConfig = getAssetByUUID(uuid);
url = assetConfig.url; if (assetConfig) {
url = assetConfig.url;
this.texture = Texture.fromImage(url);
}
} }
} }
else { else {
...@@ -12293,12 +12329,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -12293,12 +12329,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (assetConfig) { if (assetConfig) {
url = assetConfig.url; url = assetConfig.url;
} }
this.texture = Texture.fromImage(url);
} }
this.texture = Texture.fromImage(url);
}; };
Image.prototype._setSourceDirect = function (value) { Image.prototype._setSourceDirect = function (value) {
this._source = value; this._source = value;
this.updateSource(); this.updateSource();
this.dispatchEvent(Event.RESIZE);
}; };
Image.prototype._setSource = function (value) { Image.prototype._setSource = function (value) {
if (value !== this._source) { if (value !== this._source) {
...@@ -12321,7 +12358,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -12321,7 +12358,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
else { else {
this._setSourceDirect(value); this._setSourceDirect(value);
} }
this.dispatchEvent(Event.RESIZE);
} }
}; };
Image.prototype.unregisterEvents = function () { Image.prototype.unregisterEvents = function () {
...@@ -12366,9 +12402,29 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -12366,9 +12402,29 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
else { else {
_super.prototype._setText.call(this, value); _super.prototype._setText.call(this, value);
} }
this.dispatchEvent(Event.RESIZE);
} }
}; };
Object.defineProperty(Label.prototype, "htmlText", {
get: function () {
return this._htmlText;
},
set: function (v) {
if (this._htmlText != v) {
this._htmlText = v;
var el = this._el;
if (!el) {
el = this._el = document.createElement('div');
}
el.innerHTML = v;
document.body.append(el);
var pureText = el.innerText;
document.body.removeChild(el);
this.text = pureText;
}
},
enumerable: true,
configurable: true
});
Label.prototype.unregisterEvents = function () { Label.prototype.unregisterEvents = function () {
for (var _i = 0, _a = this._registeredEvents; _i < _a.length; _i++) { for (var _i = 0, _a = this._registeredEvents; _i < _a.length; _i++) {
var item = _a[_i]; var item = _a[_i];
...@@ -12478,6 +12534,97 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -12478,6 +12534,97 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
} }
var Toast = (function (_super) {
tslib_1.__extends(Toast, _super);
function Toast(gameStage) {
var _this = _super.call(this) || this;
_this._gameStage = gameStage;
_this.horizonCenter = 0;
_this.verticalCenter = 0;
return _this;
}
Toast.prototype.show = function (props) {
if (props === void 0) { props = {}; }
if (!props.text) {
return;
}
var contentView = this.getContent(props.viewName);
var lab = contentView.getChildByName('lab');
if (!lab) {
console.warn('[lab] child no exists on toast view');
return;
}
var text = props.text, _a = props.padding, padding = _a === void 0 ? 10 : _a, _b = props.duration, duration = _b === void 0 ? 1000 : _b, _c = props.showDuration, showDuration = _c === void 0 ? 300 : _c, _d = props.hideDuration, hideDuration = _d === void 0 ? 200 : _d;
lab.text = text;
lab.x = lab.y = padding;
this.width = contentView.width = lab.width + padding * 2;
this.height = contentView.height = lab.height + padding * 2;
if (!contentView.visible) {
contentView.visible = true;
contentView.alpha = 0;
}
Tween.get(contentView, null, null, true)
.to({ alpha: 1 }, showDuration)
.wait(duration)
.to({ alpha: 0 }, hideDuration)
.call(this.removeContentView, this);
};
Toast.prototype.hide = function (animation, hideDuration) {
if (animation === void 0) { animation = true; }
if (hideDuration === void 0) { hideDuration = 200; }
if (this._content) {
var contentView = this._content;
if (animation) {
Tween.get(contentView, null, null, true)
.to({ alpha: 0 }, hideDuration)
.call(this.removeContentView, this);
}
else {
Tween.removeTweens(contentView);
this.removeContentView();
}
}
};
Toast.prototype.removeContentView = function () {
this._content.visible = false;
this.removeChild(this._content);
this._content = null;
};
Toast.prototype.getContent = function (viewName) {
var view;
if (this.children.length == 0) {
if (viewName) {
view = this._gameStage.instantiateView(viewName);
}
if (!view) {
if (!this._contentSample) {
this._contentSample = new Container();
var bg = new Rect();
bg.borderRadius = 10;
bg.percentWidth = 100;
bg.percentHeight = 100;
bg.fillColor = 'black';
bg.alpha = 0.7;
this._contentSample.addChild(bg);
var lab = new Label();
lab.name = 'lab';
lab.fillColor = 'white';
lab.size = 30;
this._contentSample.addChild(lab);
}
view = this._contentSample;
}
this._content = view;
this.addChild(view);
}
else {
view = this.getChildAt(0);
}
return view;
};
return Toast;
}(Container));
var GameStage = (function (_super) { var GameStage = (function (_super) {
tslib_1.__extends(GameStage, _super); tslib_1.__extends(GameStage, _super);
function GameStage(stage) { function GameStage(stage) {
...@@ -12493,6 +12640,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -12493,6 +12640,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this.addChild(_this._sceneContainer = new StackContainer()); _this.addChild(_this._sceneContainer = new StackContainer());
_this.addChild(blackLayer); _this.addChild(blackLayer);
_this.addChild(_this._popupContainer = new StackContainer(false)); _this.addChild(_this._popupContainer = new StackContainer(false));
_this.addChild(_this._toast = new Toast(_this));
blackLayer['percentWidth'] = 100; blackLayer['percentWidth'] = 100;
blackLayer['percentHeight'] = 100; blackLayer['percentHeight'] = 100;
blackLayer.visible = false; blackLayer.visible = false;
...@@ -12517,6 +12665,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -12517,6 +12665,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(GameStage.prototype, "toast", {
get: function () {
return this._toast;
},
enumerable: true,
configurable: true
});
Object.defineProperty(GameStage.prototype, "dataCenter", { Object.defineProperty(GameStage.prototype, "dataCenter", {
get: function () { get: function () {
return this._dataCenter; return this._dataCenter;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
}, },
"scripts": { "scripts": {
"build-webpack": "webpack", "build-webpack": "webpack",
"rollup": "rollup -c -o dist/engine.js --environment BUILD:production", "rollup": "rollup -c -o dist/engine.js --environment BUILD:production1",
"rollup:debug": "rollup -c -m ", "rollup:debug": "rollup -c -m ",
"rename": "node scripts/rename-hash.js dist/engine.js", "rename": "node scripts/rename-hash.js dist/engine.js",
"build": "rm -rf dist&&yarn rollup && yarn rename", "build": "rm -rf dist&&yarn rollup && yarn rename",
......
...@@ -98,7 +98,7 @@ export class EventDispatcher extends HashObject { ...@@ -98,7 +98,7 @@ export class EventDispatcher extends HashObject {
for (var i = 0, len = eventTypes[type].length; i < len; i++) { for (var i = 0, len = eventTypes[type].length; i < len; i++) {
let ee: EE = eventTypes[type][i] let ee: EE = eventTypes[type][i]
if (ee.fn === listener && ee.context === context) { if (ee.fn === listener && ee.context === context) {
console.log("已添加过该事件") //console.log("已添加过该事件")
return return
} }
} }
......
...@@ -31,6 +31,9 @@ export function httpRequest(callback: Function, url: string, method: string = 'g ...@@ -31,6 +31,9 @@ export function httpRequest(callback: Function, url: string, method: string = 'g
url = urlJoin(url, queryStr); url = urlJoin(url, queryStr);
} }
_req.open(method, url, true); _req.open(method, url, true);
if(!isGet){
_req.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
}
_req.responseType = type; _req.responseType = type;
if (isGet) { if (isGet) {
_req.send(); _req.send();
......
...@@ -229,7 +229,7 @@ export class TextField extends Sprite { ...@@ -229,7 +229,7 @@ export class TextField extends Sprite {
return this._lineType; return this._lineType;
} }
private _lineType: TEXT_lINETYPE = TEXT_lINETYPE.SINGLE; private _lineType: TEXT_lINETYPE = TEXT_lINETYPE.MULTI;
/** /**
* 文本内容 * 文本内容
...@@ -252,6 +252,8 @@ export class TextField extends Sprite { ...@@ -252,6 +252,8 @@ export class TextField extends Sprite {
protected _setText(value) { protected _setText(value) {
this._text = value; this._text = value;
this.dirty = true; this.dirty = true;
this.dispatchEvent(Event.RESIZE);
} }
protected _text: string = ""; protected _text: string = "";
...@@ -558,22 +560,31 @@ export class TextField extends Sprite { ...@@ -558,22 +560,31 @@ export class TextField extends Sprite {
} }
} else { } else {
//textWidth取每行最大值,如果没设置过textWidth //textWidth取每行最大值,如果没设置过textWidth
let measureCache = {};
if (!textWidth) { if (!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;
textWidth = Math.max(s._getMeasuredWidth(str), textWidth); let lineWidth = 0;
for (let char of str) {
let charWidth = measureCache[char];
if (charWidth === undefined) {
charWidth = measureCache[char] = s._getMeasuredWidth(char);
}
lineWidth += charWidth;
}
textWidth = Math.max(lineWidth, 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 w = s._getMeasuredWidth(str[0]); let w = measureCache[str[0]];
let lineStr = str[0]; let lineStr = str[0];
let wordW = 0; let wordW = 0;
let strLen = str.length; let strLen = str.length;
for (let j = 1; j < strLen; j++) { for (let j = 1; j < strLen; j++) {
wordW = ctx.measureText(str[j]).width; wordW = measureCache[str[j]];
w += wordW; w += wordW;
if (w > textWidth) { if (w > textWidth) {
realLines[realLines.length] = lineStr; realLines[realLines.length] = lineStr;
...@@ -633,7 +644,7 @@ export class TextField extends Sprite { ...@@ -633,7 +644,7 @@ export class TextField extends Sprite {
this.anchorTexture = {x: (padding + 0.5) / can.width, y: padding / can.height} this.anchorTexture = {x: (padding + 0.5) / can.width, y: padding / can.height}
// document.body.appendChild(can) //document.body.appendChild(can)
// s._bounds.height = maxH; // s._bounds.height = maxH;
// s._bounds.width = maxW; // s._bounds.width = maxW;
//x,y都是0 //x,y都是0
......
...@@ -96,15 +96,16 @@ export class Process { ...@@ -96,15 +96,16 @@ export class Process {
this.updateProps(this._config.props = {}, payload, this._originProps, this._meta.props); this.updateProps(this._config.props = {}, payload, this._originProps, this._meta.props);
if (metaConfig.script) { if (metaConfig.script) {
let func; let func;
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', warpAsyncScript(metaConfig.script));
} }
if(!func){ if (!func) {
console.log(); console.log();
} }
let globalContext = this._vm.globalContext; let globalContext = this._vm.globalContext;
globalContext.dataCenter = globalContext.gameStage.dataCenter;
result = await func(payload, this._config.props, this._target, globalContext, this._vm); result = await func(payload, this._config.props, this._target, globalContext, this._vm);
} }
} else { } else {
...@@ -193,7 +194,7 @@ export class Process { ...@@ -193,7 +194,7 @@ export class Process {
let linkedValue = this.resolveLinkedProp(value, key); let linkedValue = this.resolveLinkedProp(value, key);
if (linkedValue !== undefined) { if (linkedValue !== undefined) {
props[key] = linkedValue; props[key] = linkedValue;
}else{ } else {
props[key] = undefined; props[key] = undefined;
} }
break; break;
...@@ -219,7 +220,7 @@ export class Process { ...@@ -219,7 +220,7 @@ export class Process {
if (uuid) { if (uuid) {
props[key] = findNodeByUUID(this._vm.globalContext.gameStage, uuid); props[key] = findNodeByUUID(this._vm.globalContext.gameStage, uuid);
} }
}else if(originProps[key] !== undefined){ } else if (originProps[key] !== undefined) {
props[key] = originProps[key]; props[key] = originProps[key];
} }
......
...@@ -68,7 +68,7 @@ class AdjustProxy { ...@@ -68,7 +68,7 @@ class AdjustProxy {
} }
onRemovedFromStage(e) { onRemovedFromStage(e) {
this._host.parent.removeEventListener(Event.RESIZE, this.onResize); //this._host.parent.removeEventListener(Event.RESIZE, this.onResize);
this._host.removeEventListener(Event.RESIZE, this.onResize, this); this._host.removeEventListener(Event.RESIZE, this.onResize, this);
this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame); this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
} }
......
...@@ -28,12 +28,27 @@ export function applyScript(ctor: Function) { ...@@ -28,12 +28,27 @@ export function applyScript(ctor: Function) {
*/ */
export class ScriptBase { export class ScriptBase {
private _host: Container; private _host: Container;
disabled: boolean; private _disabled: boolean;
get host() { get host() {
return this._host return this._host
} }
get disabled(){
return this._disabled;
}
set disabled(v){
if (this._disabled !== v) {
this._disabled = v;
if (this._disabled) {
this.sleep();
} else {
this.awake();
}
}
}
mounted() { mounted() {
} }
...@@ -63,7 +78,7 @@ export class ScriptBase { ...@@ -63,7 +78,7 @@ export class ScriptBase {
export function registerScriptDef(id, def) { export function registerScriptDef(id, def) {
scriptDefs[id] = def; scriptDefs[id] = def;
Object.defineProperty(def, 'disabled', { /*Object.defineProperty(def, 'disabled', {
get: function () { get: function () {
return !!this._disabled; return !!this._disabled;
}, },
...@@ -79,8 +94,7 @@ export function registerScriptDef(id, def) { ...@@ -79,8 +94,7 @@ export function registerScriptDef(id, def) {
} }
}, },
enumerable: true, enumerable: true,
configurable: true });*/
});
} }
export function registerScripts(scripts) { export function registerScripts(scripts) {
...@@ -158,10 +172,12 @@ class ScriptsProxy { ...@@ -158,10 +172,12 @@ class ScriptsProxy {
/** /**
* 根据名字获取脚本 * 根据名字获取脚本
* @param name * @param id
*/ */
get(name): ScriptBase[] { get(id): ScriptBase[] {
return this._scripts.filter(script => script.constructor['name'] === name); return this._scripts.filter(script => {
return script.constructor['id'] === id;
});
} }
/** /**
......
...@@ -47,6 +47,7 @@ export class GameStage extends Container { ...@@ -47,6 +47,7 @@ export class GameStage extends Container {
this.addChild(this._sceneContainer = new StackContainer()); this.addChild(this._sceneContainer = new StackContainer());
this.addChild(blackLayer); this.addChild(blackLayer);
this.addChild(this._popupContainer = new StackContainer(false)); this.addChild(this._popupContainer = new StackContainer(false));
this.addChild(this._toast = new Toast(this));
blackLayer['percentWidth'] = 100; blackLayer['percentWidth'] = 100;
blackLayer['percentHeight'] = 100; blackLayer['percentHeight'] = 100;
...@@ -74,6 +75,13 @@ export class GameStage extends Container { ...@@ -74,6 +75,13 @@ export class GameStage extends Container {
return this._popupContainer; return this._popupContainer;
} }
/**
* Toast提示
*/
get toast(): Toast {
return this._toast;
}
/** /**
* 数据中心 * 数据中心
*/ */
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import {Container} from "../../2d/display"; import {Container} from "../../2d/display";
import {GameStage} from "./GameStage"; import {GameStage} from "./GameStage";
import {Label, Rect} from "./nodes"; import {Label, Rect} from "./nodes";
import {Tween} from "../../2d/tween";
export class Toast extends Container { export class Toast extends Container {
private _contentSample: Container; private _contentSample: Container;
...@@ -15,50 +16,91 @@ export class Toast extends Container { ...@@ -15,50 +16,91 @@ export class Toast extends Container {
constructor(gameStage: GameStage) { constructor(gameStage: GameStage) {
super(); super();
this._gameStage = gameStage; this._gameStage = gameStage;
this.horizonCenter = 0;
this.verticalCenter = 0;
} }
show(props) { show(props: any = {}) {
if (!props.text) { if (!props.text) {
return; return;
} }
const {text, duration, viewName} = props;
let contentView = this.getContent(viewName); let contentView = this.getContent(props.viewName);
let lab = contentView.getChildByName('lab'); let lab = contentView.getChildByName('lab');
if (!lab) { if (!lab) {
console.warn('[lab] child no exists on toast view'); console.warn('[lab] child no exists on toast view');
return; return;
} }
const {text, padding = 10, duration = 1000, showDuration = 300, hideDuration = 200} = props;
lab.text = text; lab.text = text;
contentView.width = lab.width; lab.x = lab.y = padding;
contentView.height = lab.height; this.width = contentView.width = lab.width + padding * 2;
this.height = contentView.height = lab.height + padding * 2;
this.addChild(contentView); if (!contentView.visible) {
contentView.visible = true;
contentView.alpha = 0;
}
Tween.get(contentView, null, null, true)
.to({alpha: 1}, showDuration)
.wait(duration)
.to({alpha: 0}, hideDuration)
.call(this.removeContentView, this)
} }
hide() { hide(animation = true, hideDuration = 200) {
if (this._content) {
const contentView = this._content;
if(animation){
Tween.get(contentView, null, null, true)
.to({alpha: 0}, hideDuration)
.call(this.removeContentView, this)
}else{
Tween.removeTweens(contentView);
this.removeContentView();
}
}
}
private removeContentView() {
this._content.visible = false;
this.removeChild(this._content);
this._content = null;
} }
private getContent(viewName) { private getContent(viewName) {
let view; let view;
if (viewName) {
view = this._gameStage.instantiateView(viewName); if (this.children.length == 0) {
} if (viewName) {
if (!view) { view = this._gameStage.instantiateView(viewName);
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; if (!view) {
if (!this._contentSample) {
this._contentSample = new Container();
let bg = new Rect();
bg.borderRadius = 10;
bg.percentWidth = 100;
bg.percentHeight = 100;
bg.fillColor = 'black';
bg.alpha = 0.7;
this._contentSample.addChild(bg);
let lab = new Label();
lab.name = 'lab';
lab.fillColor = 'white';
lab.size = 30;
this._contentSample.addChild(lab);
}
view = this._contentSample;
}
this._content = view;
this.addChild(view);
} else {
view = this.getChildAt(0);
} }
return view; return view;
} }
} }
...@@ -46,10 +46,12 @@ export class DataCenter extends EventDispatcher { ...@@ -46,10 +46,12 @@ export class DataCenter extends EventDispatcher {
/** /**
* 根据路径获取数据 * 根据路径获取数据
* @param path * @param path
* @param groupName
* @param throwException * @param throwException
*/ */
getDataByPath(path, throwException?) { getDataByPath(path, groupName?, throwException?) {
return getDataByPath(this.store, path, throwException); let scope = groupName === undefined ? this.store : this.getGroup(groupName) || this.store;
return getDataByPath(scope, path, throwException);
} }
/** /**
...@@ -59,7 +61,7 @@ export class DataCenter extends EventDispatcher { ...@@ -59,7 +61,7 @@ export class DataCenter extends EventDispatcher {
*/ */
getDataByName(name, throwException?) { getDataByName(name, throwException?) {
let watcher = this.getWatcher(name); let watcher = this.getWatcher(name);
if(watcher){ if (watcher) {
return getDataByPath(this.store, watcher.path, throwException); return getDataByPath(this.store, watcher.path, throwException);
} }
} }
...@@ -76,10 +78,13 @@ export class DataCenter extends EventDispatcher { ...@@ -76,10 +78,13 @@ export class DataCenter extends EventDispatcher {
let name = args[0]; let name = args[0];
let watcher = this.getWatcher(name); let watcher = this.getWatcher(name);
try { try {
let data = this.getDataByPath(watcher.path, true); let data: any = this.getDataByPath(watcher.path, undefined, true);
if(args[1] !== undefined){ if (args[1] !== undefined) {
data = data[args[1]]; data = data[args[1]];
} }
if (data === undefined) {
data = '';
}
result = result.replace(new RegExp('\\$\\{' + escape.replace(/\|/g, '\\|') + '\\}', 'g'), data); result = result.replace(new RegExp('\\$\\{' + escape.replace(/\|/g, '\\|') + '\\}', 'g'), data);
} catch (e) { } catch (e) {
...@@ -88,20 +93,41 @@ export class DataCenter extends EventDispatcher { ...@@ -88,20 +93,41 @@ export class DataCenter extends EventDispatcher {
return result; return result;
} }
/**
* 数值递增
* @param groupName
* @param step
* @param path
* @param dispatch
*/
increase(groupName, step?, path?, dispatch = true) {
if(step < 0 || step > 0){
let data: any = this.getDataByPath(path, groupName);
if (data === undefined) {
data = 0;
} else {
data = parseInt(data);
}
data += step;
this.mutate(groupName, data, path, dispatch);
}
}
/** /**
* 修改数据 * 修改数据
* @param name * @param groupName
* @param data * @param data
* @param path * @param path
* @param dispatch * @param dispatch
*/ */
mutate(name, data?, path?, dispatch = true) { mutate(groupName, data?, path?, dispatch = true) {
let group = this.getGroup(name); let group = this.getGroup(groupName);
if (!group) { if (!group) {
this.registerGroup(name); this.registerGroup(groupName);
} }
if (data) { if (data !== undefined) {
if (path) { if (path) {
let func = new Function('scope', 'data', `scope.${path}=data`); let func = new Function('scope', 'data', `scope.${path}=data`);
try { try {
...@@ -110,13 +136,13 @@ export class DataCenter extends EventDispatcher { ...@@ -110,13 +136,13 @@ export class DataCenter extends EventDispatcher {
console.warn(e); console.warn(e);
} }
} else { } else {
this.registerGroup(name, data); this.registerGroup(groupName, data);
} }
} }
if (dispatch) { if (dispatch) {
for (let watcher of this.watchers) { for (let watcher of this.watchers) {
if (watcher.path.indexOf(name) === 0) { if (watcher.path.indexOf(groupName) === 0) {
this.dispatchEvent(watcher.name, { this.dispatchEvent(watcher.name, {
name: watcher.name, name: watcher.name,
path: watcher.path, path: watcher.path,
...@@ -127,7 +153,7 @@ export class DataCenter extends EventDispatcher { ...@@ -127,7 +153,7 @@ export class DataCenter extends EventDispatcher {
} }
globalEvent.dispatchEvent(DATA_CENTER_EVENT, { globalEvent.dispatchEvent(DATA_CENTER_EVENT, {
name, name: groupName,
path, path,
data, data,
}) })
......
...@@ -33,15 +33,18 @@ export class Image extends Sprite { ...@@ -33,15 +33,18 @@ export class Image extends Sprite {
if (url.indexOf(assetScheme) === 0) { if (url.indexOf(assetScheme) === 0) {
let uuid = url.replace(assetScheme, ''); let uuid = url.replace(assetScheme, '');
const assetConfig = getAssetByUUID(uuid); const assetConfig = getAssetByUUID(uuid);
url = assetConfig.url; if(assetConfig){
url = assetConfig.url;
this.texture = Texture.fromImage(url);
}
} }
} else{ //否则就使用素材名 } else{ //否则就使用素材名
const assetConfig = getAssetByName(url); const assetConfig = getAssetByName(url);
if(assetConfig){ if(assetConfig){
url = assetConfig.url; url = assetConfig.url;
} }
this.texture = Texture.fromImage(url);
} }
this.texture = Texture.fromImage(url);
} }
private _setSourceDirect(value){ private _setSourceDirect(value){
......
...@@ -13,6 +13,8 @@ export class Label extends TextField { ...@@ -13,6 +13,8 @@ export class Label extends TextField {
private _originText; private _originText;
private _escapes = []; private _escapes = [];
private _registeredEvents = []; private _registeredEvents = [];
private _htmlText;
private _el;
/** /**
* 重载文本设置 * 重载文本设置
...@@ -20,7 +22,7 @@ export class Label extends TextField { ...@@ -20,7 +22,7 @@ export class Label extends TextField {
* @private * @private
*/ */
protected _setText(value) { protected _setText(value) {
if(value !== this._text){ if (value !== this._text) {
let matchResult = value.match(ESCAPE_REG_EXP); let matchResult = value.match(ESCAPE_REG_EXP);
if (matchResult) { if (matchResult) {
...@@ -42,6 +44,29 @@ export class Label extends TextField { ...@@ -42,6 +44,29 @@ export class Label extends TextField {
} }
} }
get htmlText() {
return this._htmlText;
}
/**
* 设置html文本
*/
set htmlText(v) {
if (this._htmlText != v) {
this._htmlText = v;
let el = this._el;
if(!el){
el = this._el = document.createElement('div');
}
el.innerHTML = v;
document.body.append(el);
let pureText = el.innerText;
document.body.removeChild(el);
this.text = pureText;
}
}
/** /**
* 把之前侦听的全部移除 * 把之前侦听的全部移除
*/ */
......
...@@ -45,7 +45,7 @@ export function propertyParse(key, node, properties) { ...@@ -45,7 +45,7 @@ export function propertyParse(key, node, properties) {
* @param throwException * @param throwException
*/ */
export function getDataByPath(scope, path, throwException?) { export function getDataByPath(scope, path, throwException?) {
let func = new Function('scope', `return scope.${path}`); let func = new Function('scope', `return scope` + (path === undefined ? '' : ('.' + path)));
try { try {
return func(scope); return func(scope);
} catch (e) { } catch (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