Commit 03035a71 authored by rockyl's avatar rockyl

提交一下

parent f70709ec
......@@ -1798,13 +1798,16 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
return arr.join('&');
}
function requireForCJS(id) {
return window[id];
}
function importCJSCode(code, node) {
if (node) {
var create = new Function('module', code);
var create = new Function('module', 'require', code);
var module = {
exports: {},
};
create(module);
create(module, requireForCJS);
return module.exports;
}
else {
......@@ -1912,7 +1915,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
function instantiateScript(node, ScriptConfig) {
var scriptName = ScriptConfig.script, props = ScriptConfig.props, disabled = ScriptConfig.disabled;
var script = node.scriptsProxy.add(scriptName, props, disabled);
var script = node.scripts.add(scriptName, props, disabled);
}
function injectProperties(target, source) {
for (var key in source) {
......@@ -2114,7 +2117,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var scriptDefs = {};
function applyScript(ctor) {
ctor.prototype.applyScripts = function () {
var scriptsProxy = this.scriptsProxy = new ScriptsProxy(this);
var scriptsProxy = this.scripts = new ScriptsProxy(this);
this.addEventListener(Event.ENTER_FRAME, scriptsProxy.onEnterFrame, scriptsProxy);
this.addEventListener(Event.ADDED_TO_STAGE, scriptsProxy.onAddedToStage, scriptsProxy);
this.addEventListener(Event.REMOVED_FROM_STAGE, scriptsProxy.onRemovedFromStage, scriptsProxy);
......@@ -2252,21 +2255,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return ScriptsProxy;
}());
function findNodeByUUID(node, uuid) {
if (node.uuid === uuid) {
return node;
}
if (node.children && node.children.length > 0) {
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
var child = _a[_i];
var target = findNodeByUUID(child, uuid);
if (target) {
return target;
}
}
}
}
var DataCenter = (function (_super) {
tslib_1.__extends(DataCenter, _super);
function DataCenter() {
......@@ -2276,7 +2264,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return _this;
}
DataCenter.prototype.registerGroup = function (name, origin) {
return this.store[name] = origin || {};
return this.store[name] = origin === undefined ? {} : origin;
};
DataCenter.prototype.unregisterGroup = function (name) {
delete this.store[name];
......@@ -2285,7 +2273,14 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return this.store[name];
};
DataCenter.prototype.getDataByPath = function (path, groupName, throwException) {
var scope = groupName === undefined ? this.store : this.getGroup(groupName) || this.store;
var scope;
if (groupName === undefined) {
scope = this.store;
}
else {
var group = this.getGroup(groupName);
scope = group === undefined ? this.store : group;
}
return getDataByPath(scope, path, throwException);
};
DataCenter.prototype.getDataByName = function (name, throwException) {
......@@ -2332,6 +2327,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
DataCenter.prototype.mutate = function (groupName, data, path, dispatch) {
if (dispatch === void 0) { dispatch = true; }
if (!groupName) {
return;
}
var group = this.getGroup(groupName);
if (!group) {
group = this.registerGroup(groupName);
......@@ -2660,7 +2658,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
else if (value && value.indexOf && value.indexOf(nodeScheme) === 0) {
var uuid = value.replace(nodeScheme, '');
if (uuid) {
props[key] = findNodeByUUID(this._vm.globalContext.gameStage, uuid);
props[key] = this._vm.globalContext.gameStage.findChildByUUID(uuid);
}
}
else if (originProps[key] !== undefined) {
......@@ -3011,6 +3009,44 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
return this.children[index];
};
Container.prototype.getChildByPath = function (path, method) {
if (!path) {
return null;
}
var p = this;
while (path.length > 0) {
var segment = path.shift();
p = p[method](segment);
if (!p) {
break;
}
}
return p;
};
Container.prototype.getChildByNamePath = function (path) {
var pathArr = path.split('/');
return this.getChildByPath(pathArr, 'getChildByName');
};
Container.prototype.getChildByIndexPath = function (path) {
var pathArr = path.split('/').map(function (seg) { return parseInt(seg); });
return this.getChildByPath(pathArr, 'getChildAt');
};
Container.prototype.findChildByUUID = function (uuid) {
if (this['uuid'] === uuid) {
return this;
}
if (this.children && this.children.length > 0) {
for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
var child = _a[_i];
if (child.findChildByUUID) {
var target = child.findChildByUUID(uuid);
if (target) {
return target;
}
}
}
}
};
Container.prototype.getChildByName = function (name, isOnlyOne, isRecursive) {
if (isOnlyOne === void 0) { isOnlyOne = true; }
if (isRecursive === void 0) { isRecursive = false; }
......@@ -4221,199 +4257,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return _dRender.htmlElement.toDataURL("image/" + typeInfo.type, typeInfo.quality);
}
var nextUid = 0;
function uid() {
return ++nextUid;
}
var backupCanvas = document.createElement("canvas");
function getGradientColor(points, colors) {
var colorObj;
var ctx = backupCanvas.getContext("2d");
if (points.length == 4) {
colorObj = ctx.createLinearGradient(points[0], points[1], points[2], points[3]);
}
else {
colorObj = ctx.createRadialGradient(points[0], points[1], 0, points[2], points[3], points[4]);
}
for (var i = 0, l = colors.length; i < l; i++) {
colorObj.addColorStop(colors[i][0], getRGBA(colors[i][1], colors[i][2]));
}
return colorObj;
}
function getCanvasBitmapStyle(image) {
var ctx = backupCanvas.getContext("2d");
return ctx.createPattern(image, "repeat");
}
function hex2rgb(hex, out) {
out = out || [];
out[0] = ((hex >> 16) & 0xFF) / 255;
out[1] = ((hex >> 8) & 0xFF) / 255;
out[2] = (hex & 0xFF) / 255;
return out;
}
function hex2string(hex) {
hex = hex.toString(16);
hex = '000000'.substr(0, 6 - hex.length) + hex;
return "#" + hex;
}
function string2hex(string) {
if (string.indexOf("#") == 0) {
string = string.replace("#", "0x");
}
return parseInt(string);
}
function getRGBA(color, alpha) {
if (color.indexOf("0x") == 0) {
color = color.replace("0x", "#");
}
if (color.length < 7) {
color = "#000000";
}
if (alpha != 1) {
var r = parseInt("0x" + color.substr(1, 2));
var g = parseInt("0x" + color.substr(3, 2));
var b = parseInt("0x" + color.substr(5, 2));
color = "rgba(" + r + "," + g + "," + b + "," + alpha + ")";
}
return color;
}
function inputFeildIosEnable() {
var u = navigator.userAgent, app = navigator.appVersion;
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if (isIOS) {
setTimeout(function () {
window["$"]("input").blur(function () {
if (isIOS) {
blurAdjust();
}
});
}, 50);
}
function blurAdjust() {
setTimeout(function () {
if (document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA') {
return;
}
var result = 'pc';
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
result = 'ios';
}
else if (/(Android)/i.test(navigator.userAgent)) {
result = 'android';
}
if (result = 'ios') {
document.activeElement["scrollIntoViewIfNeeded"](true);
}
}, 100);
}
}
function decomposeDataUri(dataUri) {
var dataUriMatch = DATA_URI.exec(dataUri);
if (dataUriMatch) {
return {
mediaType: dataUriMatch[1] ? dataUriMatch[1].toLowerCase() : undefined,
subType: dataUriMatch[2] ? dataUriMatch[2].toLowerCase() : undefined,
charset: dataUriMatch[3] ? dataUriMatch[3].toLowerCase() : undefined,
encoding: dataUriMatch[4] ? dataUriMatch[4].toLowerCase() : undefined,
data: dataUriMatch[5],
};
}
return undefined;
}
function getUrlFileExtension(url) {
var extension = URL_FILE_EXTENSION.exec(url);
if (extension) {
return extension[1].toLowerCase();
}
return undefined;
}
function sign(n) {
if (n === 0)
return 0;
return n < 0 ? -1 : 1;
}
function premultiplyTint(tint, alpha) {
if (alpha === 1.0) {
return (alpha * 255 << 24) + tint;
}
if (alpha === 0.0) {
return 0;
}
var R = ((tint >> 16) & 0xFF);
var G = ((tint >> 8) & 0xFF);
var B = (tint & 0xFF);
R = ((R * alpha) + 0.5) | 0;
G = ((G * alpha) + 0.5) | 0;
B = ((B * alpha) + 0.5) | 0;
return (alpha * 255 << 24) + (R << 16) + (G << 8) + B;
}
var TextureCache = Object.create(null);
var BaseTextureCache = Object.create(null);
var GlobalPro = {
stageRenderType: exports.RENDERER_TYPE.WEBGL,
dpi: 1,
padding: 2,
startTime: 0
};
function isWebGLSupported() {
var contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true };
try {
if (!window["WebGLRenderingContext"]) {
return false;
}
var canvas = document.createElement('canvas');
var gl = canvas.getContext('webgl', contextOptions) || canvas.getContext('experimental-webgl', contextOptions);
var success = !!(gl && gl["getContextAttributes"]().stencil);
if (gl) {
var loseContext = gl["getExtension"]('WEBGL_lose_context');
if (loseContext) {
loseContext.loseContext();
}
}
gl = null;
return success;
}
catch (e) {
return false;
}
}
function removeItems(arr, startIdx, removeCount) {
var i, length = arr.length;
if (startIdx >= length || removeCount === 0) {
return;
}
removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount);
var len = length - removeCount;
for (i = startIdx; i < len; ++i) {
arr[i] = arr[i + removeCount];
}
arr.length = len;
}
function mapWebGLBlendModesToPixi(gl, array) {
if (array === void 0) { array = []; }
array[exports.BLEND_MODES.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.ADD] = [gl.ONE, gl.DST_ALPHA];
array[exports.BLEND_MODES.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.SCREEN] = [gl.ONE, gl.ONE_MINUS_SRC_COLOR];
array[exports.BLEND_MODES.OVERLAY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.DARKEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.LIGHTEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.COLOR_DODGE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.COLOR_BURN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.HARD_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.SOFT_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.DIFFERENCE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.EXCLUSION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.HUE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.SATURATION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.COLOR] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.LUMINOSITY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.NORMAL_NPM] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.ADD_NPM] = [gl.SRC_ALPHA, gl.DST_ALPHA, gl.ONE, gl.DST_ALPHA];
array[exports.BLEND_MODES.SCREEN_NPM] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_COLOR];
return array;
}
var BaseTexture = (function (_super) {
tslib_1.__extends(BaseTexture, _super);
function BaseTexture(source, scaleMode) {
......@@ -4876,69 +4719,401 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
else if (source instanceof BaseTexture) {
return new Texture(source);
}
return source;
return source;
};
Texture.addToCache = function (texture, id) {
if (id) {
if (texture.textureCacheIds.indexOf(id) === -1) {
texture.textureCacheIds.push(id);
}
if (TextureCache[id]) {
console.warn("Texture added to the cache with an id [" + id + "] that already had an entry");
}
TextureCache[id] = texture;
}
};
Texture.removeFromCache = function (texture) {
if (typeof texture === 'string') {
var textureFromCache = TextureCache[texture];
if (textureFromCache) {
var index = textureFromCache.textureCacheIds.indexOf(texture);
if (index > -1) {
textureFromCache.textureCacheIds.splice(index, 1);
}
delete TextureCache[texture];
return textureFromCache;
}
}
else if (texture && texture.textureCacheIds) {
for (var i = 0; i < texture.textureCacheIds.length; ++i) {
if (TextureCache[texture.textureCacheIds[i]] === texture) {
delete TextureCache[texture.textureCacheIds[i]];
}
}
texture.textureCacheIds.length = 0;
return texture;
}
return null;
};
return Texture;
}(EventDispatcher));
function createWhiteTexture() {
var canvas = document.createElement('canvas');
canvas.width = 16;
canvas.height = 16;
var context = canvas.getContext('2d');
context.fillStyle = 'white';
context.fillRect(0, 0, 16, 16);
return new Texture(new BaseTexture(canvas));
}
function removeAllHandlers(tex) {
tex.destroy = function _emptyDestroy() {
};
tex.addEventListener = function _emptyOn() {
};
tex.once = function _emptyOnce() {
};
tex.dispatchEvent = function _emptyEmit() {
};
}
Texture.EMPTY = new Texture(new BaseTexture());
removeAllHandlers(Texture.EMPTY);
removeAllHandlers(Texture.EMPTY.baseTexture);
Texture.WHITE = createWhiteTexture();
removeAllHandlers(Texture.WHITE);
removeAllHandlers(Texture.WHITE.baseTexture);
var padding = 2;
function DrawAllToCanvas(images, callback) {
var textures = {};
var imagesAll = [];
var countAll = Object.getOwnPropertyNames(images).length;
preLoad(images, function (img) {
imagesAll.push(img);
if (imagesAll.length == countAll) {
imagesAll.sort(compare('width', 'height'));
while (imagesAll.length) {
putInCanvas(imagesAll, textures);
}
callback(textures);
}
});
}
function preLoad(images, callback) {
var _loop_1 = function () {
bitmap = images[key];
if (typeof (bitmap) == 'string') {
var imgTag_1 = new Image();
if (bitmap.indexOf("iVBO") === 0 || bitmap.indexOf("/9j/2w") === 0) {
imgTag_1.src = 'data:image/png;base64,' + bitmap;
}
else {
imgTag_1.src = bitmap;
}
imgTag_1["imageKey"] = key;
imgTag_1.onload = function () {
callback(imgTag_1);
};
}
else if (bitmap instanceof HTMLImageElement) {
bitmap["imageKey"] = key;
if (bitmap.complete && bitmap.width && bitmap.height) {
callback(bitmap);
}
else {
bitmap.onload = function () {
callback(bitmap);
};
}
}
else if (bitmap instanceof HTMLCanvasElement) {
callback(bitmap);
}
};
var bitmap;
for (var key in images) {
_loop_1();
}
}
function compare(name1, name2) {
return function (a, b) {
var fir1 = a[name1];
var sec1 = b[name1];
if (fir1 === sec1) {
var fir2 = a[name2];
var sec2 = b[name2];
if (fir2 === sec2) {
return 0;
}
else {
return fir2 > sec2 ? 1 : -1;
}
}
else {
return fir1 > sec1 ? 1 : -1;
}
};
}
function putInCanvas(imagesAll, textures) {
var freeRects = [];
var imageInfos = [];
var canvas = document.createElement('canvas');
canvas.width = 4096;
canvas.height = 4096;
freeRects.push(new Rectangle(0, 0, 4096, 4096));
var canvasWidth = 0, canvasHeight = 0;
var match = false;
for (var i = imagesAll.length - 1; i >= 0; i--) {
var img = imagesAll[i];
match = false;
for (var j = freeRects.length - 1; j >= 0; j--) {
var freeRect = freeRects[j];
if (freeRect.width >= img.width + padding * 2 && freeRect.height >= img.height + padding * 2) {
match = true;
var imageIn = new imageInfo(img, freeRect.x + padding, freeRect.y + padding);
imageInfos.push(imageIn);
imagesAll.splice(i, 1);
freeRects.splice(j, 1);
var restW = freeRect.width - img.width - padding;
if (restW > 0) {
var rightRect = new Rectangle(freeRect.x + img.width + padding, freeRect.y, restW, img.height + padding);
freeRect.y == 0 ? freeRects.unshift(rightRect) : freeRects.push(rightRect);
}
var restH = freeRect.height - img.height - padding;
if (restH > 0) {
var downRect = new Rectangle(freeRect.x, freeRect.y + img.height + padding, freeRect.width, restH);
freeRect.x == 0 ? freeRects.unshift(downRect) : freeRects.push(downRect);
}
if (imageIn.image.width + imageIn.x > canvasWidth) {
canvasWidth = imageIn.image.width + imageIn.x;
}
if (imageIn.image.height + imageIn.y > canvasHeight) {
canvasHeight = imageIn.image.height + imageIn.y;
}
break;
}
}
if (!match)
break;
}
canvas.width = nextPow2(canvasWidth + padding);
canvas.height = nextPow2(canvasHeight + padding);
var ctx = canvas.getContext("2d");
for (var m = 0; m < imageInfos.length; m++) {
var imageInfo_1 = imageInfos[m];
var image = imageInfo_1.image;
ctx.drawImage(imageInfo_1.image, 0, 0, image.width, image.height, imageInfo_1.x, imageInfo_1.y, image.width, image.height);
}
var baseTexture = new BaseTexture(canvas);
for (var n = 0; n < imageInfos.length; n++) {
var imageInfo_2 = imageInfos[n];
var image = imageInfo_2.image;
textures[image.imageKey] = new Texture(baseTexture, new Rectangle(imageInfo_2.x, imageInfo_2.y, image.width, image.height), new Rectangle(0, 0, image.width, image.height), null);
}
}
var imageInfo = (function () {
function imageInfo(image, x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
this.image = image;
this.x = x;
this.y = y;
}
return imageInfo;
}());
var nextUid = 0;
function uid() {
return ++nextUid;
}
var backupCanvas = document.createElement("canvas");
function getGradientColor(points, colors) {
var colorObj;
var ctx = backupCanvas.getContext("2d");
if (points.length == 4) {
colorObj = ctx.createLinearGradient(points[0], points[1], points[2], points[3]);
}
else {
colorObj = ctx.createRadialGradient(points[0], points[1], 0, points[2], points[3], points[4]);
}
for (var i = 0, l = colors.length; i < l; i++) {
colorObj.addColorStop(colors[i][0], getRGBA(colors[i][1], colors[i][2]));
}
return colorObj;
}
function getCanvasBitmapStyle(image) {
var ctx = backupCanvas.getContext("2d");
return ctx.createPattern(image, "repeat");
}
function hex2rgb(hex, out) {
out = out || [];
out[0] = ((hex >> 16) & 0xFF) / 255;
out[1] = ((hex >> 8) & 0xFF) / 255;
out[2] = (hex & 0xFF) / 255;
return out;
}
function hex2string(hex) {
hex = hex.toString(16);
hex = '000000'.substr(0, 6 - hex.length) + hex;
return "#" + hex;
}
function string2hex(string) {
if (string.indexOf("#") == 0) {
string = string.replace("#", "0x");
}
return parseInt(string);
}
function getRGBA(color, alpha) {
if (color.indexOf("0x") == 0) {
color = color.replace("0x", "#");
}
if (color.length < 7) {
color = "#000000";
}
if (alpha != 1) {
var r = parseInt("0x" + color.substr(1, 2));
var g = parseInt("0x" + color.substr(3, 2));
var b = parseInt("0x" + color.substr(5, 2));
color = "rgba(" + r + "," + g + "," + b + "," + alpha + ")";
}
return color;
}
function inputFeildIosEnable() {
var u = navigator.userAgent, app = navigator.appVersion;
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if (isIOS) {
setTimeout(function () {
window["$"]("input").blur(function () {
if (isIOS) {
blurAdjust();
}
});
}, 50);
}
function blurAdjust() {
setTimeout(function () {
if (document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA') {
return;
}
var result = 'pc';
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
result = 'ios';
}
else if (/(Android)/i.test(navigator.userAgent)) {
result = 'android';
}
if (result = 'ios') {
document.activeElement["scrollIntoViewIfNeeded"](true);
}
}, 100);
}
}
function decomposeDataUri(dataUri) {
var dataUriMatch = DATA_URI.exec(dataUri);
if (dataUriMatch) {
return {
mediaType: dataUriMatch[1] ? dataUriMatch[1].toLowerCase() : undefined,
subType: dataUriMatch[2] ? dataUriMatch[2].toLowerCase() : undefined,
charset: dataUriMatch[3] ? dataUriMatch[3].toLowerCase() : undefined,
encoding: dataUriMatch[4] ? dataUriMatch[4].toLowerCase() : undefined,
data: dataUriMatch[5],
};
}
return undefined;
}
function getUrlFileExtension(url) {
var extension = URL_FILE_EXTENSION.exec(url);
if (extension) {
return extension[1].toLowerCase();
}
return undefined;
}
function sign(n) {
if (n === 0)
return 0;
return n < 0 ? -1 : 1;
}
function premultiplyTint(tint, alpha) {
if (alpha === 1.0) {
return (alpha * 255 << 24) + tint;
}
if (alpha === 0.0) {
return 0;
}
var R = ((tint >> 16) & 0xFF);
var G = ((tint >> 8) & 0xFF);
var B = (tint & 0xFF);
R = ((R * alpha) + 0.5) | 0;
G = ((G * alpha) + 0.5) | 0;
B = ((B * alpha) + 0.5) | 0;
return (alpha * 255 << 24) + (R << 16) + (G << 8) + B;
}
var TextureCache = Object.create(null);
var BaseTextureCache = Object.create(null);
var GlobalPro = {
stageRenderType: exports.RENDERER_TYPE.WEBGL,
dpi: 1,
padding: 2,
startTime: 0
};
Texture.addToCache = function (texture, id) {
if (id) {
if (texture.textureCacheIds.indexOf(id) === -1) {
texture.textureCacheIds.push(id);
}
if (TextureCache[id]) {
console.warn("Texture added to the cache with an id [" + id + "] that already had an entry");
function isWebGLSupported() {
var contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true };
try {
if (!window["WebGLRenderingContext"]) {
return false;
}
TextureCache[id] = texture;
var canvas = document.createElement('canvas');
var gl = canvas.getContext('webgl', contextOptions) || canvas.getContext('experimental-webgl', contextOptions);
var success = !!(gl && gl["getContextAttributes"]().stencil);
if (gl) {
var loseContext = gl["getExtension"]('WEBGL_lose_context');
if (loseContext) {
loseContext.loseContext();
}
};
Texture.removeFromCache = function (texture) {
if (typeof texture === 'string') {
var textureFromCache = TextureCache[texture];
if (textureFromCache) {
var index = textureFromCache.textureCacheIds.indexOf(texture);
if (index > -1) {
textureFromCache.textureCacheIds.splice(index, 1);
}
delete TextureCache[texture];
return textureFromCache;
gl = null;
return success;
}
catch (e) {
return false;
}
else if (texture && texture.textureCacheIds) {
for (var i = 0; i < texture.textureCacheIds.length; ++i) {
if (TextureCache[texture.textureCacheIds[i]] === texture) {
delete TextureCache[texture.textureCacheIds[i]];
}
function removeItems(arr, startIdx, removeCount) {
var i, length = arr.length;
if (startIdx >= length || removeCount === 0) {
return;
}
texture.textureCacheIds.length = 0;
return texture;
removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount);
var len = length - removeCount;
for (i = startIdx; i < len; ++i) {
arr[i] = arr[i + removeCount];
}
return null;
};
return Texture;
}(EventDispatcher));
function createWhiteTexture() {
var canvas = document.createElement('canvas');
canvas.width = 16;
canvas.height = 16;
var context = canvas.getContext('2d');
context.fillStyle = 'white';
context.fillRect(0, 0, 16, 16);
return new Texture(new BaseTexture(canvas));
arr.length = len;
}
function removeAllHandlers(tex) {
tex.destroy = function _emptyDestroy() {
};
tex.addEventListener = function _emptyOn() {
};
tex.once = function _emptyOnce() {
};
tex.dispatchEvent = function _emptyEmit() {
};
function mapWebGLBlendModesToPixi(gl, array) {
if (array === void 0) { array = []; }
array[exports.BLEND_MODES.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.ADD] = [gl.ONE, gl.DST_ALPHA];
array[exports.BLEND_MODES.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.SCREEN] = [gl.ONE, gl.ONE_MINUS_SRC_COLOR];
array[exports.BLEND_MODES.OVERLAY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.DARKEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.LIGHTEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.COLOR_DODGE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.COLOR_BURN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.HARD_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.SOFT_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.DIFFERENCE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.EXCLUSION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.HUE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.SATURATION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.COLOR] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.LUMINOSITY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.NORMAL_NPM] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
array[exports.BLEND_MODES.ADD_NPM] = [gl.SRC_ALPHA, gl.DST_ALPHA, gl.ONE, gl.DST_ALPHA];
array[exports.BLEND_MODES.SCREEN_NPM] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_COLOR];
return array;
}
Texture.EMPTY = new Texture(new BaseTexture());
removeAllHandlers(Texture.EMPTY);
removeAllHandlers(Texture.EMPTY.baseTexture);
Texture.WHITE = createWhiteTexture();
removeAllHandlers(Texture.WHITE);
removeAllHandlers(Texture.WHITE.baseTexture);
var indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
var Sprite = (function (_super) {
......@@ -4950,6 +5125,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this._texture = null;
_this._width = 0;
_this._height = 0;
_this._tint = null;
_this._tintRGB = null;
_this.tint = 0xFFFFFF;
_this._cachedTint = 0xFFFFFF;
_this.uvs = null;
_this._onTextureUpdate = _this._onTextureUpdate.bind(_this);
_this.texture = texture || Texture.EMPTY;
......@@ -4967,6 +5146,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Sprite.prototype._onTextureUpdate = function () {
this._textureID = -1;
this._textureTrimmedID = -1;
this._cachedTint = 0xFFFFFF;
if (this._texture.valid)
this.uvs = this._texture._uvs.uvsFloat32;
if (this._width) {
......@@ -5159,6 +5339,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this._texture = value || Texture.EMPTY;
this._textureID = -1;
this._textureTrimmedID = -1;
this._cachedTint = 0xFFFFFF;
if (value) {
if (value.baseTexture.hasLoaded) {
this._onTextureUpdate();
......@@ -5171,6 +5352,19 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true,
configurable: true
});
Object.defineProperty(Sprite.prototype, "tint", {
get: function () {
return this._tint;
},
set: function (value) {
if (value === this._tint)
return;
this._tint = value;
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
},
enumerable: true,
configurable: true
});
Sprite.from = function (source) {
return new Sprite(Texture.from(source));
};
......@@ -10548,7 +10742,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}(EventDispatcher));
var globalLoader = new Loader();
var padding = 10;
var padding$1 = 10;
var TextField = (function (_super) {
tslib_1.__extends(TextField, _super);
function TextField() {
......@@ -10559,6 +10753,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this._lineSpacing = 14;
_this._lineType = exports.TEXT_lINETYPE.SINGLE;
_this._text = "";
_this._pureText = '';
_this._font = "Arial";
_this._size = 12;
_this._fillColor = "#000";
......@@ -10697,6 +10892,53 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this.dispatchEvent(Event.RESIZE);
}
};
Object.defineProperty(TextField.prototype, "textFlow", {
get: function () {
return this._textFlow;
},
set: function (value) {
this._textFlow = value;
this.dirty = true;
var text = '';
for (var _i = 0, _a = this._textFlow; _i < _a.length; _i++) {
var item = _a[_i];
text += item.text;
}
this._pureText = text;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextField.prototype, "isPureText", {
get: function () {
return !this._textFlow || this._textFlow.length == 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextField.prototype, "pureText", {
get: function () {
return this.isPureText ? this._text : this._pureText;
},
enumerable: true,
configurable: true
});
TextField.prototype.getStyle = function (index) {
if (!this.textFlow) {
return null;
}
var targetItem;
var count = 0;
for (var _i = 0, _a = this._textFlow; _i < _a.length; _i++) {
var item = _a[_i];
count += item.text.length;
if (index < count) {
targetItem = item;
break;
}
}
return targetItem.style;
};
Object.defineProperty(TextField.prototype, "font", {
get: function () {
return this._font;
......@@ -10841,7 +11083,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
TextField.prototype.updateText = function () {
var s = this;
if (!s._text) {
var text = s._pureText;
if (!text) {
s.canvas.width = 0;
s.canvas.height = 0;
s._localBoundsSelf.clear();
......@@ -10849,18 +11092,19 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this.updateTexture();
return;
}
var measureCache = {};
if (!s.dirty)
return;
s.dirty = false;
s._text += "";
text += "";
var can = s.canvas;
var ctx = s.context;
var hardLines = s._text.toString().split(/(?:\r\n|\r|\n)/);
var hardLines = text.toString().split(/(?:\r\n|\r|\n)/);
var realLines = [];
s.realLines = realLines;
s._prepContext(ctx);
var textWidth = s._width;
if (s._text.indexOf("\n") < 0 && s.lineType == exports.TEXT_lINETYPE.SINGLE) {
if (text.indexOf("\n") < 0 && s.lineType == exports.TEXT_lINETYPE.SINGLE) {
realLines[realLines.length] = hardLines[0];
var str = hardLines[0];
var lineW = s._getMeasuredWidth(str);
......@@ -10884,7 +11128,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
else {
var measureCache = {};
var shouldMeasureTextWidth = !textWidth;
for (var i = 0, l = hardLines.length; i < l; i++) {
var str = hardLines[i];
......@@ -10893,10 +11136,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
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);
}
var charWidth = measureChar(char);
lineWidth += charWidth;
}
if (shouldMeasureTextWidth) {
......@@ -10936,17 +11176,17 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
else if (s._textAlign == exports.TEXT_ALIGN.RIGHT) {
tx = maxW;
}
can.width = maxW + padding * 2;
can.height = maxH + padding * 2;
can.width = maxW + padding$1 * 2;
can.height = maxH + padding$1 * 2;
ctx.clearRect(0, 0, can.width, can.width);
if (s.border) {
ctx.beginPath();
ctx.strokeStyle = "#000";
ctx.lineWidth = 1;
ctx.strokeRect(padding + 0.5, padding + 0.5, maxW, maxH);
ctx.strokeRect(padding$1 + 0.5, padding$1 + 0.5, maxW, maxH);
ctx.closePath();
}
ctx.setTransform(1, 0, 0, 1, tx + padding, padding);
ctx.setTransform(1, 0, 0, 1, tx + padding$1, padding$1);
s._prepContext(ctx);
var lineH = s._lineSpacing + s.size;
var upY = 0;
......@@ -10958,20 +11198,62 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
upY = s._height - trueHeight;
}
}
var index = 0;
for (var i = 0; i < realLines.length; i++) {
var line = realLines[i];
if (s.isPureText) {
var y = upY + i * lineH;
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2;
ctx.strokeText(realLines[i], 0, upY + i * lineH, maxW);
ctx.strokeText(line, 0, y, maxW);
}
ctx.fillText(line, 0, y, maxW);
}
else {
var x = 0;
for (var j = 0, lj = line.length; j < lj; j++) {
var char = line[j];
var 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;
}
var 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);
}
s.offsetX = -padding;
s.offsetY = -padding;
this.anchorTexture = { x: (padding + 0.5) / can.width, y: padding / can.height };
}
s.offsetX = -padding$1;
s.offsetY = -padding$1;
this.anchorTexture = { x: (padding$1 + 0.5) / can.width, y: padding$1 / can.height };
s._localBoundsSelf.width = maxW;
s._localBoundsSelf.height = maxH;
s.updateTexture();
function measureChar(char) {
var w = measureCache[char];
if (w === undefined) {
w = measureCache[char] = s._getMeasuredWidth(char);
}
return w;
}
};
TextField.prototype.updateTexture = function () {
var canvas = this.canvas;
......@@ -12450,7 +12732,24 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return arrayFind(assetsConfig, function (item) { return item.uuid === uuid; });
}
function getAssetByName(name) {
return arrayFind(assetsConfig, function (item) { return item.name === name; });
var result = arrayFind(assetsConfig, function (item) { return item.name === name; });
if (result) {
return result;
}
else {
for (var _i = 0, assetsConfig_1 = assetsConfig; _i < assetsConfig_1.length; _i++) {
var assetConfig = assetsConfig_1[_i];
var res = engine.globalLoader.get(assetConfig.url);
if (res && res.frames) {
for (var key in res.frames) {
var frame = res.frames[key];
if (frame.name === name) {
return { url: key };
}
}
}
}
}
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
......@@ -14845,8 +15144,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
tslib_1.__extends(TextInput, _super);
function TextInput() {
var _this = _super.call(this) || this;
_this._placeholder = '';
_this._placeholderColor = '#666666';
_this.placeholderColor = '#666666';
_this.type = 'text';
_this.onBlur = function (e) {
_this.setBlur();
};
......@@ -14856,41 +15155,23 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this.text = '';
return _this;
}
Object.defineProperty(TextInput.prototype, "placeholder", {
get: function () {
return this._placeholder;
},
set: function (value) {
this._placeholder = value;
TextInput.prototype.onModify = function (value, key) {
switch (key) {
case 'placeholder':
if (this._placeholderLabel) {
this._placeholderLabel.text = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextInput.prototype, "placeholderColor", {
get: function () {
return this._placeholderColor;
},
set: function (value) {
this._placeholderColor = value;
}
break;
case 'placeholderColor':
if (this._placeholderLabel) {
this._placeholderLabel.fillColor = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextInput.prototype, "maxLength", {
get: function () {
return this._maxLength;
},
set: function (value) {
if (this._maxLength != value) {
this._maxLength = value;
}
break;
case 'maxLength':
this.setMaxLength();
break;
}
},
enumerable: true,
configurable: true
});
};
TextInput.prototype.setup = function () {
var fd = this._floatDisplay = new FloatDisplay();
var input = this._input = document.createElement('input');
......@@ -14905,7 +15186,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
input.type = 'text';
input.addEventListener('blur', this.onBlur);
var pl = this._placeholderLabel = new TextField();
pl.fillColor = this._placeholderColor;
pl.fillColor = this.placeholderColor;
this.verticalAlign = pl.verticalAlign = exports.VERTICAL_ALIGN.MIDDLE;
this.addChild(fd);
};
......@@ -14919,7 +15200,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
TextInput.prototype.setMaxLength = function () {
var value = this._text;
var maxLength = this._maxLength;
var maxLength = this.maxLength;
if (maxLength > 0 && value && value.length > maxLength) {
this.text = value.substr(0, maxLength);
}
......@@ -14934,7 +15215,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
else {
if (!pl.parent) {
pl.text = this._placeholder;
pl.text = this.placeholder;
pl.size = this.size;
pl.font = this.font;
this.addChildAt(pl, 0);
......@@ -14963,12 +15244,22 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
this._floatDisplay.alpha = 1;
input.style.pointerEvents = 'auto';
if (this._maxLength > 0) {
input.maxLength = this._maxLength;
var maxLength = this.maxLength;
if (maxLength > 0) {
input.maxLength = maxLength;
}
else {
input.removeAttribute('maxLength');
}
if (this.pattern) {
input.pattern = this.pattern;
}
else {
input.removeAttribute('pattern');
}
if (this.type) {
input.type = this.type;
}
input.focus();
this.dispatchEvent(Event.FOCUS);
};
......@@ -15017,6 +15308,21 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return null;
};
TextInput._bp = new Point();
tslib_1.__decorate([
dirtyFieldTrigger
], TextInput.prototype, "placeholder", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], TextInput.prototype, "placeholderColor", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], TextInput.prototype, "maxLength", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], TextInput.prototype, "type", void 0);
tslib_1.__decorate([
dirtyFieldTrigger
], TextInput.prototype, "pattern", void 0);
return TextInput;
}(Label));
......@@ -15055,6 +15361,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
textinput: TextInput,
scrollView: ScrollView,
};
function registerNodeType(name, def) {
nodeTypeMapping[name] = def;
}
function instantiate(config) {
return instantiateView(config);
}
......@@ -15092,21 +15401,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return node;
}
var template = "\n<div style=\"\nposition: absolute;\nleft: 0;\nright: 0;\ntop: 0;\nbottom: 0;\ndisplay: flex;\ndisplay: -webkit-flex;\njustify-content: center;\n-webkit-justify-content: center;\nalign-items: center;\n-webkit-align-items: center;\n\">\n<img src=\"//yun.duiba.com.cn/editor/zeroing/assets/loading.gif\"\n</div>\n";
var container$1 = document.createElement('div');
container$1.innerHTML = template;
var wrapper = container$1.removeChild(container$1.children[0]);
function showLoadingView() {
if (!wrapper.parentElement) {
document.body.appendChild(wrapper);
}
}
function hideLoadingView() {
if (wrapper.parentElement) {
document.body.removeChild(wrapper);
}
}
var Toast = (function (_super) {
tslib_1.__extends(Toast, _super);
function Toast(gameStage) {
......@@ -15279,7 +15573,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
}
showLoadingView();
return [4, loadAssets(assets, p).catch(function (e) {
console.log(e);
})];
......@@ -15302,7 +15595,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_a++;
return [3, 2];
case 5:
hideLoadingView();
this.start();
onStart && onStart();
return [2];
......@@ -15311,6 +15603,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
});
};
GameStage.prototype.start = function () {
var _this = this;
var _a = this._config, _b = _a.options, entrySceneView = _b.entrySceneView, env = _b.env, dataMapping = _a.dataMapping, processes = _a.processes, builtinProcesses = _a.builtinProcesses, scripts = _a.scripts, customs = _a.customs;
Stage.addUpdateObj(Tween);
injectEnv(env);
......@@ -15318,10 +15611,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this.dataCenter.registerDataMapping(dataMapping);
}
setProcessMetaLibs(processes, builtinProcesses);
var sceneEntry = this.instantiateView(entrySceneView);
setTimeout(function () {
var sceneEntry = _this.instantiateView(entrySceneView);
if (sceneEntry) {
this._sceneContainer.push(sceneEntry);
_this._sceneContainer.push(sceneEntry);
}
});
};
GameStage.prototype.instantiateView = function (name, cache) {
if (cache === void 0) { cache = true; }
......@@ -18549,43 +18844,87 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var url = assetConfig.url;
var opts = {
src: [url],
autoplay: true,
autoplay: false,
};
injectProperties(opts, options);
var sound = new howler_2(opts);
if (name !== undefined) {
instances[name] = sound;
var key_1 = name || uuid;
var _a = opts.keep, keep = _a === void 0 ? false : _a;
var sound = void 0;
if (keep) {
var data = instances[key_1];
if (data) {
sound = data.sound;
}
}
if (!sound) {
sound = new howler_2(opts);
}
instances[key_1] = {
sound: sound,
keep: keep,
};
if (!keep) {
sound.on('end', function () {
delete instances[name];
destroySound(key_1);
});
}
sound.play();
return sound;
}
}
function stopSound(name) {
var sound = instances[name];
var _a = instances[name], sound = _a.sound, keep = _a.keep;
if (sound) {
sound.stop();
if (!keep) {
destroySound(name);
}
}
}
function destroySound(name) {
delete instances[name];
}
var template = "\n<div style=\"\nposition: absolute;\nleft: 0;\nright: 0;\ntop: 0;\nbottom: 0;\ndisplay: flex;\ndisplay: -webkit-flex;\njustify-content: center;\n-webkit-justify-content: center;\nalign-items: center;\n-webkit-align-items: center;\n\">\n<img src=\"//yun.duiba.com.cn/editor/zeroing/assets/loading.gif\"\n</div>\n";
var container$1 = document.createElement('div');
container$1.innerHTML = template;
var wrapper = container$1.removeChild(container$1.children[0]);
var builtinLoadingView = {
onProgress: function (done, total) {
if (!wrapper.parentElement) {
document.body.appendChild(wrapper);
}
},
onComplete: function () {
if (wrapper.parentElement) {
document.body.removeChild(wrapper);
}
},
};
function launch(url, onAssetsProgress, onAssetsComplete, onStart) {
function launch(url, loadingDelegate, onStart) {
return globalLoader.loadJson(url)
.then(function (config) {
return launchWithConfig(config, onAssetsProgress, onAssetsComplete, onStart);
return launchWithConfig(config, loadingDelegate, onStart);
});
}
function launchWithLocalStorage(id, onAssetsProgress, onAssetsComplete, onStart) {
function launchWithLocalStorage(id, loadingDelegate, onStart) {
var storeKey = 'preview-project-' + id;
var storeData = localStorage.getItem(storeKey);
var _a = JSON.parse(storeData), data = _a.data, processes = _a.processes, scripts = _a.scripts, customs = _a.customs;
setProcessMetaLibs(processes);
registerScripts(scripts);
registerCustomModuleFromConfig(customs);
return launchWithConfig(data, onAssetsProgress, onAssetsComplete, onStart);
return launchWithConfig(data, loadingDelegate, onStart);
}
function launchWithWindowVariable(name, loadingDelegate, onStart) {
var _a = window[name], data = _a.data, processes = _a.processes, scripts = _a.scripts, customs = _a.customs;
setProcessMetaLibs(processes);
registerScripts(scripts);
registerCustomModuleFromConfig(customs);
return launchWithConfig(data, loadingDelegate, onStart);
}
function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onStart) {
function launchWithConfig(config, loadingDelegate, onStart) {
return new Promise(function (resolve) {
var _a = config.options, containerId = _a.containerId, designWidth = _a.designWidth, designHeight = _a.designHeight, frameRate = _a.frameRate, scaleMode = _a.scaleMode, rendererType = _a.rendererType;
var stage = window['stage'] = new Stage(containerId || "game-container", designWidth || 750, designHeight || 1334, frameRate || 60, scaleMode || StageScaleMode.FIXED_WIDTH, rendererType || exports.RENDERER_TYPE.WEBGL);
......@@ -18596,7 +18935,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
gameStage: exports.gameStage
});
stage.addChild(exports.gameStage);
exports.gameStage.launch(config, onAssetsProgress, onAssetsComplete, onStart);
var delegate = loadingDelegate || builtinLoadingView;
exports.gameStage.launch(config, function (done, total) {
delegate.onProgress && delegate.onProgress(done, total);
}, function () {
delegate.onComplete && delegate.onComplete();
}, onStart);
});
resolve(exports.gameStage);
});
......@@ -18618,6 +18962,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.DATA_URI = DATA_URI;
exports.DEG_TO_RAD = DEG_TO_RAD;
exports.DisplayObject = DisplayObject;
exports.DrawAllToCanvas = DrawAllToCanvas;
exports.ESCAPE_REG_EXP = ESCAPE_REG_EXP;
exports.Ease = Ease;
exports.EditableText = EditableText;
......@@ -18626,6 +18971,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.FloatDisplay = FloatDisplay;
exports.GDispatcher = GDispatcher;
exports.GameStage = GameStage;
exports.GlobalPro = GlobalPro;
exports.Graphics = Graphics;
exports.HashObject = HashObject;
exports.Howl = howler_2;
......@@ -18665,6 +19011,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.createTextureSheet = createTextureSheet;
exports.deepDirtyFieldDetector = deepDirtyFieldDetector;
exports.deepDirtyFieldTrigger = deepDirtyFieldTrigger;
exports.destroySound = destroySound;
exports.devicePixelRatio = devicePixelRatio;
exports.dirtyFieldDetector = dirtyFieldDetector;
exports.dirtyFieldTrigger = dirtyFieldTrigger;
......@@ -18694,6 +19041,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.launch = launch;
exports.launchWithConfig = launchWithConfig;
exports.launchWithLocalStorage = launchWithLocalStorage;
exports.launchWithWindowVariable = launchWithWindowVariable;
exports.linkedFlag = linkedFlag;
exports.loadAssets = loadAssets;
exports.md5 = md5;
......@@ -18707,6 +19055,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.registerCustomCodeModule = registerCustomCodeModule;
exports.registerCustomModule = registerCustomModule;
exports.registerCustomModuleFromConfig = registerCustomModuleFromConfig;
exports.registerNodeType = registerNodeType;
exports.registerScriptDef = registerScriptDef;
exports.registerScripts = registerScripts;
exports.setGlobalContext = setGlobalContext;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,7 +2,9 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/dist" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
......
......@@ -184,7 +184,7 @@ export default class Container extends DisplayObject {
* 是否含有child
* @param child
*/
contains(child: DisplayObject):boolean{
contains(child: DisplayObject): boolean {
return !!this.getChildIndex(child);
}
......@@ -209,6 +209,66 @@ export default class Container extends DisplayObject {
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
......
import { ObservablePoint, Point, Rectangle } from '../math';
import { sign, TextureCache } from '../utils';
import {ObservablePoint, Point, Rectangle} from '../math';
import {sign, TextureCache} from '../utils';
// import { BLEND_MODES } from '../const';
import Texture from '../texture/Texture';
import { Event } from '../events/Event';
import {Event} from '../events/Event';
import Container from './Container';
import { DisplayObject } from "./DisplayObject";
import {DisplayObject} from "./DisplayObject";
import CanvasRenderer from '../renderers/CanvasRenderer';
import { SCALE_MODES } from '../const';
import { WebglRenderer } from '../renderers/WebglRenderer';
import {SCALE_MODES} from '../const';
import {WebglRenderer} from '../renderers/WebglRenderer';
const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
/**
......@@ -456,6 +456,7 @@ export default class Sprite extends Container {
get tint() {
return this._tint;
}
set tint(value) {
if (value === this._tint) return;
this._tint = value;
......
......@@ -18,7 +18,6 @@ const padding = 10;
* @public
*/
export class TextField extends Sprite {
canvas: HTMLCanvasElement;
context: CanvasRenderingContext2D;
/**
......@@ -231,6 +230,8 @@ export class TextField extends Sprite {
private _lineType: TEXT_lINETYPE = TEXT_lINETYPE.SINGLE;
protected _text: string = "";
/**
* 文本内容
* @property text
......@@ -244,7 +245,7 @@ export class TextField extends Sprite {
}
public get text(): string {
return this._text;
return this.pureText;
}
protected _setText(value) {
......@@ -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字体样式
......@@ -292,7 +335,6 @@ export class TextField extends Sprite {
this._size = value;
this.dirty = true;
}
;
}
public get size(): number {
......@@ -314,7 +356,6 @@ export class TextField extends Sprite {
this._fillColor = value;
this.dirty = true;
}
;
}
public get fillColor(): any {
......@@ -336,7 +377,6 @@ export class TextField extends Sprite {
this._strokeColor = value;
this.dirty = true;
}
;
}
public get strokeColor(): string {
......@@ -358,7 +398,6 @@ export class TextField extends Sprite {
this._stroke = value;
this.dirty = true;
}
;
}
public get stroke(): number {
......@@ -380,7 +419,6 @@ export class TextField extends Sprite {
this._italic = value;
this.dirty = true;
}
;
}
public get italic(): boolean {
......@@ -402,7 +440,6 @@ export class TextField extends Sprite {
this._bold = value;
this.dirty = true;
}
;
}
public get bold(): boolean {
......@@ -423,7 +460,6 @@ export class TextField extends Sprite {
this._border = value;
this.dirty = true;
}
;
}
public get border(): boolean {
......@@ -512,8 +548,9 @@ export class TextField extends Sprite {
*/
public updateText(): void {
let s: TextField = this;
let text = s._pureText;
//如果没有文本
if (!s._text) {
if (!text) {
s.canvas.width = 0;
s.canvas.height = 0;
s._localBoundsSelf.clear();
......@@ -521,12 +558,13 @@ export class TextField extends Sprite {
this.updateTexture();
return
}
let measureCache = {};
if (!s.dirty) return;
s.dirty = false;
s._text += "";
text += "";
let can = s.canvas;
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 = [];
s.realLines = realLines;
s._prepContext(ctx);
......@@ -534,7 +572,7 @@ export class TextField extends Sprite {
let textWidth = s._width;
// 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];
let str = hardLines[0];
let lineW = s._getMeasuredWidth(str);
......@@ -559,17 +597,13 @@ export class TextField extends Sprite {
}
} else {
//textWidth取每行最大值,如果没设置过textWidth
let measureCache = {};
const shouldMeasureTextWidth = !textWidth;
for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i];
if (!str) continue;
let lineWidth = 0;
for (let char of str) {
let charWidth = measureCache[char];
if (charWidth === undefined) {
charWidth = measureCache[char] = s._getMeasuredWidth(char);
}
let charWidth = measureChar(char);
lineWidth += charWidth;
}
if (shouldMeasureTextWidth) {
......@@ -630,13 +664,46 @@ export class TextField extends Sprite {
upY = s._height - trueHeight;
}
}
let index = 0;
for (let i = 0; i < realLines.length; i++) {
let line = realLines[i];
if (s.isPureText) {
let y = upY + i * lineH;
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2;
ctx.strokeText(realLines[i], 0, upY + i * lineH, maxW);
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代替
s.offsetX = -padding;
......@@ -651,7 +718,15 @@ export class TextField extends Sprite {
s._localBoundsSelf.width = maxW;
s._localBoundsSelf.height = maxH;
//修改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
export * from './twiddle';
export { default as toDisplayDataURL } from "./toDisplayDataURL";
export { default as determineCrossOrigin } from './determineCrossOrigin';
export * from './DrawAllToCanvas'
let nextUid = 0;
......
......@@ -24,6 +24,8 @@ export * from "./2d/ui";
export * from './2d/tween'
export * from './2d/net'
export {GlobalPro, DrawAllToCanvas} from './2d/utils'
export { default as toDisplayDataURL } from "./2d/utils/toDisplayDataURL";
export { inputFeildIosEnable } from "./2d/utils/index"
......
......@@ -5,7 +5,6 @@
*/
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";
import {getLogSwitch, Logs} from "../log-switch";
......@@ -231,7 +230,7 @@ export class Process {
} else if (value && value.indexOf && value.indexOf(nodeScheme) === 0) {
let uuid = value.replace(nodeScheme, '');
if (uuid) {
props[key] = findNodeByUUID(this._vm.globalContext.gameStage, uuid);
props[key] = this._vm.globalContext.gameStage.findChildByUUID(uuid);
}
} else if (originProps[key] !== undefined) {
props[key] = originProps[key];
......
......@@ -15,7 +15,7 @@ const scriptDefs = {};
*/
export function applyScript(ctor: 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.ADDED_TO_STAGE, scriptsProxy.onAddedToStage, scriptsProxy);
......
......@@ -8,14 +8,13 @@ import {loadAssets} from "./assets-manager";
import {instantiate} from "./view-interpreter";
import {dataCenter, DataCenter} from "./data-center";
import {setProcessMetaLibs} from "../behavior-runtime";
import {registerScripts} from "..";
import {Tween} from "../../2d/tween";
import {Rect} from "./nodes";
import {injectEnv} from "./enviroment";
import {registerCustomModuleFromConfig} from "./custom-module";
import {hideLoadingView, showLoadingView} from "./loading-view";
import {Toast} from "./Toast";
import {arrayFind} from "../utils";
import {registerScripts} from "..";
import {registerCustomModuleFromConfig} from "./custom-module";
/**
* 游戏舞台
......@@ -111,7 +110,6 @@ export class GameStage extends Container {
}
}
showLoadingView();
await loadAssets(assets, p).catch(e => {
console.log(e);
});
......@@ -124,7 +122,6 @@ export class GameStage extends Container {
}
}
}
hideLoadingView();
this.start();
......@@ -157,10 +154,12 @@ export class GameStage extends Container {
}
setProcessMetaLibs(processes, builtinProcesses);
setTimeout(()=>{
let sceneEntry = this.instantiateView(entrySceneView);
if (sceneEntry) {
this._sceneContainer.push(sceneEntry);
}
})
}
/**
......
......@@ -2,16 +2,6 @@
* 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 = `
<div style="
position: absolute;
......@@ -34,18 +24,15 @@ let container = document.createElement('div');
container.innerHTML = template;
let wrapper = container.removeChild(container.children[0]);
export function showLoadingView() {
export default {
onProgress(done, total) {
if (!wrapper.parentElement) {
document.body.appendChild(wrapper);
}
}
export function hideLoadingView() {
},
onComplete() {
if (wrapper.parentElement) {
document.body.removeChild(wrapper);
}
}
export function setLoadingViewProgress(current, total) {
},
}
......@@ -32,18 +32,18 @@ export function loadAssets(config, onProgress?, onComplete?) {
config.map(assetConfig => {
assetsConfig.push(assetConfig);
const loadFunc = loaderMapping[assetConfig.ext];
if(loadFunc){
if (loadFunc) {
let method = globalLoader['load' + loadFunc];
return method.call(globalLoader, assetConfig.url, assetConfig.uuid).then(
(data)=>{
(data) => {
loaded++;
onProgress && onProgress(loaded, total);
},
(error)=>{
(error) => {
failedList.push(assetConfig.url);
}
);
}else{
} else {
loaded++;
onProgress && onProgress(loaded, total);
return Promise.resolve();
......@@ -64,14 +64,29 @@ export function loadAssets(config, onProgress?, onComplete?) {
* 根据uuid获取素材配置
* @param uuid
*/
export function getAssetByUUID(uuid) {
return arrayFind(assetsConfig,item => item.uuid === uuid);
export function getAssetByUUID(uuid): any {
return arrayFind(assetsConfig, item => item.uuid === uuid);
}
/**
* 根据name获取素材配置
* @param name
*/
export function getAssetByName(name) {
return arrayFind(assetsConfig,item => item.name === name);
export function getAssetByName(name): any {
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 {
* @param 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 {
* @param 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);
}
......@@ -101,7 +107,7 @@ export class DataCenter extends EventDispatcher {
* @param dispatch
*/
increase(groupName, step?, path?, dispatch = true) {
if(step < 0 || step > 0){
if (step < 0 || step > 0) {
let data: any = this.getDataByPath(path, groupName);
if (data === undefined) {
data = 0;
......@@ -122,6 +128,9 @@ export class DataCenter extends EventDispatcher {
* @param dispatch
*/
mutate(groupName, data?, path?, dispatch = true) {
if (!groupName) {
return;
}
let group = this.getGroup(groupName);
if (!group) {
......
......@@ -7,15 +7,23 @@ import {Event} from "../../../2d/events/Event";
import {FloatDisplay} from "../../../2d/display/FloatDisplay";
import {TextField} from "../../../2d/text";
import {Point} from "../../../2d/math";
import {dirtyFieldTrigger} from "../../decorators";
import {VERTICAL_ALIGN} from "../../..";
export class TextInput extends Label {
private _floatDisplay: FloatDisplay;
private _placeholderLabel: TextField;
private _input: any;
private _placeholder: string = '';
private _placeholderColor: any = '#666666';
private _maxLength: number;
@dirtyFieldTrigger
placeholder: string;
@dirtyFieldTrigger
placeholderColor: any = '#666666';
@dirtyFieldTrigger
maxLength: number;
@dirtyFieldTrigger
type: string = 'text';
@dirtyFieldTrigger
pattern: string;
private _oldFillColor;
private _oldStrokeColor;
......@@ -30,32 +38,21 @@ export class TextInput extends Label {
this.text = '';
}
get placeholder(): string {
return this._placeholder;
}
set placeholder(value: string) {
this._placeholder = value;
onModify(value, key) {
switch (key) {
case 'placeholder':
if (this._placeholderLabel) {
this._placeholderLabel.text = value;
}
get placeholderColor(): any {
return this._placeholderColor;
}
set placeholderColor(value: any) {
this._placeholderColor = value;
break;
case 'placeholderColor':
if (this._placeholderLabel) {
this._placeholderLabel.fillColor = value;
}
get maxLength(): number {
return this._maxLength;
}
set maxLength(value: number) {
if(this._maxLength != value){
this._maxLength = value;
break;
case 'maxLength':
this.setMaxLength();
break;
}
}
......@@ -76,7 +73,7 @@ export class TextInput extends Label {
input.addEventListener('blur', this.onBlur);
let pl = this._placeholderLabel = new TextField();
pl.fillColor = this._placeholderColor;
pl.fillColor = this.placeholderColor;
this.verticalAlign = pl.verticalAlign = VERTICAL_ALIGN.MIDDLE;
......@@ -95,7 +92,7 @@ export class TextInput extends Label {
private setMaxLength() {
let value = this._text;
let maxLength = this._maxLength;
let maxLength = this.maxLength;
if (maxLength > 0 && value && value.length > maxLength) {
this.text = value.substr(0, maxLength);
}
......@@ -103,14 +100,14 @@ export class TextInput extends Label {
private showPlaceholderLabel(value) {
let pl = this._placeholderLabel;
if(value){
if (value) {
let pl = this._placeholderLabel;
if (pl.parent) {
pl.parent.removeChild(pl);
}
}else{
} else {
if (!pl.parent) {
pl.text = this._placeholder;
pl.text = this.placeholder;
pl.size = this.size;
pl.font = this.font;
this.addChildAt(pl, 0);
......@@ -147,12 +144,23 @@ export class TextInput extends Label {
this._floatDisplay.alpha = 1;
input.style.pointerEvents = 'auto';
if(this._maxLength > 0){
input.maxLength = this._maxLength;
}else{
const maxLength = this.maxLength;
if (maxLength > 0) {
input.maxLength = maxLength;
} else {
input.removeAttribute('maxLength')
}
if (this.pattern) {
input.pattern = this.pattern;
} else {
input.removeAttribute('pattern')
}
if (this.type) {
input.type = this.type;
}
input.focus();
this.dispatchEvent(Event.FOCUS);
......@@ -178,8 +186,8 @@ export class TextInput extends Label {
this.setBlur();
};
private onClickStage(e){
if(e.currentTarget !== this){
private onClickStage(e) {
if (e.currentTarget !== this) {
this.setBlur();
}
}
......
......@@ -7,35 +7,59 @@ import {injectProperties} from "../utils";
const instances = {};
export function playSound(uuid, options = {}, name?) {
export function playSound(uuid, options: any = {}, name?) {
let assetConfig = getAssetByUUID(uuid);
if (assetConfig) {
let url = assetConfig.url;
let opts: any = {
src: [url],
autoplay: true,
autoplay: false,
};
injectProperties(opts, options);
let sound = new Howl(opts);
const key = name || uuid;
if (name !== undefined) {
instances[name] = sound;
const {keep = false} = opts;
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 () {
delete instances[name];
destroySound(key);
});
}
sound.play();
return sound;
}
}
export function stopSound(name){
let sound = instances[name];
if(sound){
export function stopSound(name) {
let {sound, keep} = instances[name];
if (sound) {
sound.stop();
delete instances[name];
if (!keep) {
destroySound(name);
}
}
}
export function destroySound(name) {
delete instances[name];
}
......@@ -11,10 +11,11 @@ export * from './game-warpper'
export * from './behavior-runtime'
export * from './web'
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 {
instantiate
instantiate,
registerNodeType,
}
......@@ -8,17 +8,18 @@ import {GameStage} from "./game-warpper";
import {setGlobalContext} from "./behavior-runtime";
import {globalLoader} from "../2d/loader/Loader";
import {Event} from "../2d/events/Event";
import builtinLoadingView from "./game-warpper/LoadingView";
export let gameStage: GameStage;
export function launch(url, onAssetsProgress, onAssetsComplete, onStart) {
export function launch(url, loadingDelegate?, onStart?) {
return globalLoader.loadJson(url)
.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;
let storeData = localStorage.getItem(storeKey);
let {data, processes, scripts, customs,} = JSON.parse(storeData);
......@@ -27,10 +28,20 @@ export function launchWithLocalStorage(id, onAssetsProgress, onAssetsComplete, o
registerScripts(scripts);
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 => {
const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.options;
let stage = window['stage'] = new Stage(
......@@ -39,7 +50,7 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onS
designHeight || 1334,
frameRate || 60,
scaleMode || StageScaleMode.FIXED_WIDTH,
rendererType || RENDERER_TYPE.WEBGL
rendererType || RENDERER_TYPE.WEBGL,
);
Stage.flushAll();
......@@ -50,7 +61,13 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onS
});
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);
......
/**
* 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 {
return arr.join('&');
}
function requireForCJS(id){
return window[id];
}
/**
* 导入cjs包装的代码
* @param code
......@@ -141,11 +145,11 @@ export function obj2query(obj: any): string {
*/
export function importCJSCode(code, node?) {
if (node) {
let create = new Function('module', code);
let create = new Function('module', 'require', code);
let module = {
exports: {},
};
create(module);
create(module, requireForCJS);
return module.exports;
} else {
let create = new Function('exports', code);
......@@ -253,7 +257,7 @@ export function strShort(str, limit, replace = '…'){
export function instantiateScript(node, 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) {
......
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