Commit 962fd5d9 authored by rockyl's avatar rockyl

提交一波

parent 12377187
{"id":"engine","url":"engine.53262d62b13fbd758c11074e8875d82b17828de5.js"}
\ No newline at end of file
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
"typescript": "^2.7.2" "typescript": "^2.7.2"
}, },
"scripts": { "scripts": {
"declare": "node scripts/declare.js", "declare": "node scripts/declare.js src/index.ts",
"rollup": "rollup -c -o dist/engine.js", "rollup": "rollup -c -o dist/engine.js",
"rollup:debug": "rollup -c -m ", "rollup:debug": "rollup -c -m ",
"rollup:prod": "rollup -c -o dist/engine.js --environment BUILD:production", "rollup:prod": "rollup -c -o dist/engine.js --environment BUILD:production",
"rename": "node scripts/rename-hash.js dist/engine.js", "preprocess": "node scripts/pre-process.js engine dist/engine.js",
"build": "rm -rf dist&&yarn rollup:prod && yarn rename && ali-oss-publish -c oss.config.js -e dist", "build": "rm -rf dist&&yarn rollup:prod && yarn preprocess && ali-oss-publish -c oss.config.js -e dist",
"build:debug": "rm -rf dist&&yarn rollup && yarn rename && ali-oss-publish -c oss.config.js -e dist", "build:debug": "rm -rf dist&&yarn rollup && yarn preprocess && ali-oss-publish -c oss.config.js -e dist",
"ts": "dts-bundle --name engine --main types/src/index.d.ts --out ../../dist/index.d.ts", "ts": "dts-bundle --name engine --main types/src/index.d.ts --out ../../dist/index.d.ts",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"mergeDts": "node scripts/mergeDts.js" "mergeDts": "node scripts/mergeDts.js"
......
...@@ -4,20 +4,32 @@ ...@@ -4,20 +4,32 @@
const crypto = require('crypto'); const crypto = require('crypto');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const fileName = process.argv[2]; const [_, __, id, fileName] = process.argv;
const stream = fs.createReadStream(fileName); const stream = fs.createReadStream(fileName);
const fsHash = crypto.createHash('sha1'); const fsHash = crypto.createHash('sha1');
stream.on('data', function(d) { stream.on('data', function (d) {
fsHash.update(d); fsHash.update(d);
}); });
stream.on('end', function() { stream.on('end', function () {
const md5 = fsHash.digest('hex'); const md5 = fsHash.digest('hex');
loadComplete(md5);
});
function loadComplete(md5) {
const extIndex = fileName.lastIndexOf('.'); const extIndex = fileName.lastIndexOf('.');
const newFileName = fileName.substr(0, extIndex + 1) + md5 + fileName.substr(extIndex); const newFileName = fileName.substr(0, extIndex + 1) + md5 + fileName.substr(extIndex);
fs.renameSync(fileName, newFileName) fs.renameSync(fileName, newFileName);
});
\ No newline at end of file let manifest = {
id,
url: path.basename(newFileName),
};
fs.writeFileSync('manifest.json', JSON.stringify(manifest));
}
...@@ -446,6 +446,14 @@ export default class Container extends DisplayObject { ...@@ -446,6 +446,14 @@ export default class Container extends DisplayObject {
} }
} }
let widthSetted = !!this._width && this._width !== 0;
let heightSetted = !!this._height && this._height !== 0;
if(widthSetted){
this._bounds.width = this._width;
}
if(heightSetted){
this._bounds.height = this._height;
}
} }
/** /**
...@@ -463,9 +471,9 @@ export default class Container extends DisplayObject { ...@@ -463,9 +471,9 @@ export default class Container extends DisplayObject {
//如果不可见 //如果不可见
if (!this.visible) return null if (!this.visible) return null
//如果禁止子级的鼠标事件 //如果禁止子级的鼠标事件
if (isMouseEvent && !this.mouseChildren) return null; if (isMouseEvent && !this.mouseChildren) return this.hitTestSelf(globalPoint);
var children = this.children; var children = this.children;
var length = children.length var length = children.length;
let child, hitDisplayObject; let child, hitDisplayObject;
//后序遍历,后添加的在上层 //后序遍历,后添加的在上层
for (var i = length - 1; i >= 0; i--) { for (var i = length - 1; i >= 0; i--) {
...@@ -479,9 +487,29 @@ export default class Container extends DisplayObject { ...@@ -479,9 +487,29 @@ export default class Container extends DisplayObject {
//存在直接返回 //存在直接返回
if (hitDisplayObject) return hitDisplayObject; if (hitDisplayObject) return hitDisplayObject;
} }
return this.hitTestSelf(globalPoint);
}
hitTestSelf(globalPoint) {
if (this.mouseEnabled) {
return this.hitTestSelfBounds(globalPoint);
}
return null; return null;
} }
hitTestSelfBounds(globalPoint) {
if (this.width && this.height) {
let lp = this.globalToLocal(globalPoint, DisplayObject._bp);
if (lp.x > 0 &&
lp.x < this.width &&
lp.y > 0 &&
lp.y < this.height
) return this;
}
return null
}
/** /**
* webgl渲染 * webgl渲染
* @param {WebglRenderer} renderer - The renderer * @param {WebglRenderer} renderer - The renderer
......
...@@ -642,8 +642,8 @@ export class Stage extends Container { ...@@ -642,8 +642,8 @@ export class Stage extends Container {
} else { } else {
cp = new Point(); cp = new Point();
} }
cp.x = (points[o].clientX - points[o].target.offsetLeft) * devicePixelRatio; cp.x = (points[o].clientX - points[o].target.offsetLeft + window.pageXOffset) * devicePixelRatio;
cp.y = (points[o].clientY - points[o].target.offsetTop) * devicePixelRatio; cp.y = (points[o].clientY - points[o].target.offsetTop + window.pageYOffset) * devicePixelRatio;
//计算舞台中的点 //计算舞台中的点
sp = s.globalToLocal(cp, DisplayObject._bp); sp = s.globalToLocal(cp, DisplayObject._bp);
//检查是否有鼠标事件 //检查是否有鼠标事件
......
...@@ -3,6 +3,7 @@ import {TextureCache} from "../utils"; ...@@ -3,6 +3,7 @@ import {TextureCache} from "../utils";
import {Texture} from "../texture"; import {Texture} from "../texture";
import {httpRequest} from "../net"; import {httpRequest} from "../net";
import {createTextureSheet} from "../../zeroing/game-warpper/texture-sheet"; import {createTextureSheet} from "../../zeroing/game-warpper/texture-sheet";
import {preloadSound} from "../../zeroing/game-warpper/sound";
export class Loader extends EventDispatcher { export class Loader extends EventDispatcher {
...@@ -60,6 +61,12 @@ export class Loader extends EventDispatcher { ...@@ -60,6 +61,12 @@ export class Loader extends EventDispatcher {
return this.loadRaw(url, uuid, 'text'); return this.loadRaw(url, uuid, 'text');
} }
loadSound(url: string, uuid?: string) {
preloadSound(url, uuid);
return Promise.resolve();
}
loadImage(url: string, uuid?: string) { loadImage(url: string, uuid?: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let img = this.caches[uuid || url]; let img = this.caches[uuid || url];
......
...@@ -46,9 +46,18 @@ export function httpRequest(url: string, method: string = 'get', params?: any, t ...@@ -46,9 +46,18 @@ export function httpRequest(url: string, method: string = 'get', params?: any, t
function doProxyRequest(payload, resolve, reject) { function doProxyRequest(payload, resolve, reject) {
let proxyWindow = window['proxy_window']; let proxyWindow = window['proxy_window'];
window.addEventListener('message', function (event) { window.addEventListener('message', onMessage, false);
proxyWindow.postMessage(JSON.stringify({
action: 'http-request-proxy',
payload: payload,
}), '*');
function onMessage(event) {
window.removeEventListener('message', onMessage);
try { try {
let data = JSON.parse(event.data); let data = JSON.parse(event.data);
console.log('onMessage', event.data);
switch (data.action) { switch (data.action) {
case 'http-request-proxy-resolve': case 'http-request-proxy-resolve':
...@@ -61,12 +70,7 @@ function doProxyRequest(payload, resolve, reject) { ...@@ -61,12 +70,7 @@ function doProxyRequest(payload, resolve, reject) {
} catch (e) { } catch (e) {
} }
}, false); }
proxyWindow.postMessage(JSON.stringify({
action: 'http-request-proxy',
payload: payload,
}), '*')
} }
function doXhrRequest({url, method, params, type, headers}, resolve, reject) { function doXhrRequest({url, method, params, type, headers}, resolve, reject) {
...@@ -82,17 +86,15 @@ function doXhrRequest({url, method, params, type, headers}, resolve, reject) { ...@@ -82,17 +86,15 @@ function doXhrRequest({url, method, params, type, headers}, resolve, reject) {
const isGet = method.toUpperCase() === 'GET'; const isGet = method.toUpperCase() === 'GET';
const queryStr = obj2query(params); const queryStr = obj2query(params);
let openUrl = url; let openUrl = url;
/*if(openUrl.indexOf('projectx') >= 0){ if (openUrl.indexOf('projectx') == 0) {
openUrl = openUrl.replace(/projectx\/\w+\//, ''); openUrl = '/' + openUrl;
}*/ }
if (isGet) { if (isGet) {
openUrl = urlJoin(openUrl, queryStr); openUrl = urlJoin(openUrl, queryStr);
} }
xhr.open(method, openUrl, true); xhr.open(method, openUrl, true);
if (!isGet) { for (let key in headers) {
for (let key in headers) { xhr.setRequestHeader(key, headers[key]);
xhr.setRequestHeader(key, headers[key]);
}
} }
xhr.responseType = type; xhr.responseType = type;
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
...@@ -118,7 +120,9 @@ function doXhrRequest({url, method, params, type, headers}, resolve, reject) { ...@@ -118,7 +120,9 @@ function doXhrRequest({url, method, params, type, headers}, resolve, reject) {
function doRequest(payload, resolve, reject) { function doRequest(payload, resolve, reject) {
if (window['proxy_window'] && payload.url.indexOf('blob') !== 0) { if (window['proxy_window'] && payload.url.indexOf('blob') !== 0) {
doProxyRequest(payload, resolve, reject); doProxyRequest(payload, function (p) {
resolve(p);
}, reject);
} else { } else {
doXhrRequest(payload, resolve, reject); doXhrRequest(payload, resolve, reject);
} }
......
...@@ -429,10 +429,10 @@ export default class Texture extends EventDispatcher { ...@@ -429,10 +429,10 @@ export default class Texture extends EventDispatcher {
if (texture.textureCacheIds.indexOf(id) === -1) { if (texture.textureCacheIds.indexOf(id) === -1) {
texture.textureCacheIds.push(id); texture.textureCacheIds.push(id);
} }
if (TextureCache[id]) { /*if (TextureCache[id]) {
//覆盖 //覆盖
console.warn(`Texture added to the cache with an id [${id}] that already had an entry`); console.warn(`Texture added to the cache with an id [${id}] that already had an entry`);
} }*/
TextureCache[id] = texture; TextureCache[id] = texture;
} }
} }
......
...@@ -138,7 +138,7 @@ export class ScrollListBase extends ScrollViewBase { ...@@ -138,7 +138,7 @@ export class ScrollListBase extends ScrollViewBase {
if (s._isInit > 0) { if (s._isInit > 0) {
if (s._updateId != s.viewPort.transform._localID) { if (s._updateId != s.viewPort.transform._localID) {
const items = s._items; const items = s._items;
let id: number = (Math.abs(Math.floor(Math.ceil(s.viewPort[s.paramXY]) / s._itemRow)) - 1) * s._cols; let id: number = s.viewPort[s.paramXY] > 0 ? 0 : (Math.abs(Math.floor(s.viewPort[s.paramXY] / s._itemRow)) - 1) * s._cols;
id = id < 0 ? 0 : id; id = id < 0 ? 0 : id;
if (id != s._lastFirstId) { if (id != s._lastFirstId) {
s._lastFirstId = id; s._lastFirstId = id;
......
...@@ -203,7 +203,7 @@ export class ScrollViewBase extends Container { ...@@ -203,7 +203,7 @@ export class ScrollViewBase extends Container {
s.addSpeed = 0; s.addSpeed = 0;
s.speed = 0; s.speed = 0;
s.isStop = true; s.isStop = true;
view[s.paramXY] = s.distance - s.maxDistance; view[s.paramXY] = Math.min(0, s.distance - s.maxDistance);
return; return;
} }
} }
......
...@@ -102,12 +102,13 @@ function putInCanvas(imagesAll, textures) { ...@@ -102,12 +102,13 @@ function putInCanvas(imagesAll, textures) {
var freeRects = []; var freeRects = [];
//图片信息数组 //图片信息数组
var imageInfos: imageInfo[] = []; var imageInfos: imageInfo[] = [];
//先初始化4096*4096 var size = 2048;
//先初始化size*size
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.width = 4096; canvas.width = size;
canvas.height = 4096; canvas.height = size;
//添加第一个可用矩形 //添加第一个可用矩形
freeRects.push(new Rectangle(0, 0, 4096, 4096)) freeRects.push(new Rectangle(0, 0, size, size))
//可变 //可变
var canvasWidth = 0, canvasHeight = 0 var canvasWidth = 0, canvasHeight = 0
//先排满在canvas //先排满在canvas
...@@ -117,10 +118,10 @@ function putInCanvas(imagesAll, textures) { ...@@ -117,10 +118,10 @@ function putInCanvas(imagesAll, textures) {
match = false match = false
for (var j = freeRects.length - 1; j >= 0; j--) { for (var j = freeRects.length - 1; j >= 0; j--) {
let freeRect = freeRects[j]; let freeRect = freeRects[j];
if (freeRect.width >= img.width + padding * 2 && freeRect.height >= img.height + padding * 2) { if (freeRect.width >= img.width + padding && freeRect.height >= img.height + padding) {
match = true match = true
//有满足的,记录 //有满足的,记录
var imageIn = new imageInfo(img, freeRect.x + padding, freeRect.y + padding) var imageIn = new imageInfo(img, freeRect.x, freeRect.y)
imageInfos.push(imageIn) imageInfos.push(imageIn)
//imagesAll里移除 //imagesAll里移除
imagesAll.splice(i, 1); imagesAll.splice(i, 1);
......
...@@ -24,7 +24,7 @@ export * from "./2d/ui"; ...@@ -24,7 +24,7 @@ export * from "./2d/ui";
export * from './2d/tween' export * from './2d/tween'
export * from './2d/net' export * from './2d/net'
export {GlobalPro, DrawAllToCanvas} from './2d/utils' export * from './2d/utils'
export { default as toDisplayDataURL } from "./2d/utils/toDisplayDataURL"; export { default as toDisplayDataURL } from "./2d/utils/toDisplayDataURL";
......
...@@ -17,7 +17,7 @@ function logProcess(meta, vm, process, ...params) { ...@@ -17,7 +17,7 @@ function logProcess(meta, vm, process, ...params) {
let showLog = false; let showLog = false;
if (typeof logConfig === 'boolean') { if (typeof logConfig === 'boolean') {
showLog = true; showLog = logConfig;
} else if (logConfig.indexOf(meta.id) >= 0 || logConfig.indexOf(meta.name) >= 0) { } else if (logConfig.indexOf(meta.id) >= 0 || logConfig.indexOf(meta.name) >= 0) {
showLog = true; showLog = true;
} }
......
...@@ -126,7 +126,7 @@ class ScriptsProxy { ...@@ -126,7 +126,7 @@ class ScriptsProxy {
* @param options * @param options
* @param disabled * @param disabled
*/ */
add(name, options, disabled): ScriptBase { add(name, options, disabled = false): ScriptBase {
let def = scriptDefs[name]; let def = scriptDefs[name];
if (!def) { if (!def) {
console.warn(`script[${name}] def not exists`); console.warn(`script[${name}] def not exists`);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-05. * Created by rockyl on 2019-11-05.
*/ */
import {Container, Stage} from "../../2d/display"; import {Container, Stage} from "../../2d/display/index";
import {StackContainer} from "./StackContainer"; import {StackContainer} from "./StackContainer";
import {loadAssets} from "./assets-manager"; import {loadAssets} from "./assets-manager";
import {instantiate} from "./view-interpreter"; import {instantiate} from "./view-interpreter";
......
/**
* Created by rockyl on 2019-11-22.
*/
const template = `
<div style="
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
align-items: center;
-webkit-align-items: center;
">
<img src="//yun.duiba.com.cn/editor/zeroing/assets/loading.gif">
</div>
`;
let container = document.createElement('div');
container.innerHTML = template;
let wrapper = container.removeChild(container.children[0]);
export default {
onProgress(done, total) {
if (!wrapper.parentElement) {
document.body.appendChild(wrapper);
}
},
onComplete() {
if (wrapper.parentElement) {
document.body.removeChild(wrapper);
}
},
}
...@@ -3,35 +3,88 @@ ...@@ -3,35 +3,88 @@
*/ */
const template = ` const template = `
<div style=" <div class="zeroing-loading-wrapper">
position: absolute; <div class="zeroing-loading-content">
left: 0; </div>
right: 0;
top: 0;
bottom: 0;
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
align-items: center;
-webkit-align-items: center;
">
<img src="//yun.duiba.com.cn/editor/zeroing/assets/loading.gif"
</div> </div>
`; `;
let container = document.createElement('div'); const style = `
container.innerHTML = template; .zeroing-loading-wrapper{
let wrapper = container.removeChild(container.children[0]); position: absolute;
top:0;
left: 0;
right: 0;
bottom: 0;
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
align-items: center;
-webkit-align-items: center;
}
@keyframes part-body
{
0%,40% {transform: scale(1);}
20% {transform: scale(1.5);}
}
.zeroing-loading-part {
transform-origin: 2px 12px;
position: absolute;
}
.zeroing-loading-part-body{
background-color: dimgray;
width: 4px;
height: 6px;
border-radius: 2px;
transform-origin: 2px 6px;
animation: part-body 1500ms linear infinite;
}
`;
let inited = false;
let wrapper;
function init() {
if (inited) {
return;
}
inited = true;
let container = document.createElement('div');
container.innerHTML = template;
wrapper = container.removeChild(container.children[0]);
let styleEl = document.createElement('style');
styleEl.innerText = style;
document.body.appendChild(styleEl);
let content = wrapper.children[0];
let count = 8;
let perDelay = 1500 / count;
let perDeg = 360 / count;
for (let i = 0; i < count; i++) {
let part = document.createElement('div');
part.innerHTML = `<div class="zeroing-loading-part" style="
transform: rotate(${i * perDeg}deg); ">
<div class="zeroing-loading-part-body" style="
animation-delay:${-(count - i) * perDelay}ms;
"></div>
</div>`;
content.appendChild(part.children[0]);
}
}
export default { export default {
onProgress(done, total) { onProgress(done, total) {
init();
if (!wrapper.parentElement) { if (!wrapper.parentElement) {
document.body.appendChild(wrapper); document.body.appendChild(wrapper);
} }
}, },
onComplete() { onComplete() {
if (wrapper.parentElement) { if (wrapper && wrapper.parentElement) {
document.body.removeChild(wrapper); document.body.removeChild(wrapper);
} }
}, },
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-05. * Created by rockyl on 2019-11-05.
*/ */
import {Container, DisplayObject} from "../../2d/display"; import {Container, DisplayObject} from "../../2d/display/index";
/** /**
* 栈式视图容器 * 栈式视图容器
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-25. * Created by rockyl on 2019-11-25.
*/ */
import {Container} from "../../2d/display"; import {Container} from "../../2d/display/index";
import {GameStage} from "./GameStage"; import {GameStage} from "./GameStage";
import {Label, Rect} from "./nodes"; import {Label, Rect} from "./nodes";
import {Tween} from "../../2d/tween"; import {Tween} from "../../2d/tween";
...@@ -16,6 +16,7 @@ export class Toast extends Container { ...@@ -16,6 +16,7 @@ export class Toast extends Container {
constructor(gameStage: GameStage) { constructor(gameStage: GameStage) {
super(); super();
this._gameStage = gameStage; this._gameStage = gameStage;
this.mouseEnabled = this.mouseChildren = false;
this.horizonCenter = 0; this.horizonCenter = 0;
this.verticalCenter = 0; this.verticalCenter = 0;
......
...@@ -18,6 +18,7 @@ const loaderMapping = { ...@@ -18,6 +18,7 @@ const loaderMapping = {
'.json': 'Json', '.json': 'Json',
'.svga': 'Svga', '.svga': 'Svga',
'.sht': 'Sheet', '.sht': 'Sheet',
'.mp3': 'Sound',
'': 'Raw', '': 'Raw',
}; };
...@@ -74,7 +75,21 @@ export function loadAssets(config, onProgress?, onComplete?) { ...@@ -74,7 +75,21 @@ export function loadAssets(config, onProgress?, onComplete?) {
* @param uuid * @param uuid
*/ */
export function getAssetByUUID(uuid): any { export function getAssetByUUID(uuid): any {
return arrayFind(assetsConfig, item => item.uuid === uuid); let result = arrayFind(assetsConfig, item => item.uuid === uuid);
if (result) {
return result;
} else {
for (let assetConfig of assetsConfig) {
let res = globalLoader.get(assetConfig.url);
if (res && res.frames) {
for (let key in res.frames) {
if (key === uuid) {
return {uuid: key};
}
}
}
}
}
} }
/** /**
...@@ -92,7 +107,7 @@ export function getAssetByName(name): any { ...@@ -92,7 +107,7 @@ export function getAssetByName(name): any {
for (let key in res.frames) { for (let key in res.frames) {
const frame = res.frames[key]; const frame = res.frames[key];
if (frame.name === name) { if (frame.name === name) {
return {url: key}; return {uuid: key};
} }
} }
} }
......
...@@ -12,9 +12,16 @@ const customMap = {}; ...@@ -12,9 +12,16 @@ const customMap = {};
* @param customs * @param customs
*/ */
export function registerCustomModules(customs) { export function registerCustomModules(customs) {
if(!customs){
return;
}
for (let custom of customs) { for (let custom of customs) {
customMap[custom.id].assets = custom.assets; if(custom.assets){
customMap[custom.id].props = custom.props; customMap[custom.id].assets = custom.assets;
}
if(custom.props){
customMap[custom.id].props = custom.props;
}
} }
} }
......
...@@ -7,7 +7,7 @@ import Sprite from "../../../2d/display/Sprite"; ...@@ -7,7 +7,7 @@ import Sprite from "../../../2d/display/Sprite";
import Texture from "../../../2d/texture/Texture"; import Texture from "../../../2d/texture/Texture";
import {getFont} from "../bmp-text-manager"; import {getFont} from "../bmp-text-manager";
import {dirtyFieldTrigger} from "../../decorators"; import {dirtyFieldTrigger} from "../../decorators";
import {VERTICAL_ALIGN} from "../../.."; import {VERTICAL_ALIGN} from "../../../2d/const";
export class BitmapText extends Container { export class BitmapText extends Container {
private _charCache = []; private _charCache = [];
...@@ -52,6 +52,12 @@ export class BitmapText extends Container { ...@@ -52,6 +52,12 @@ export class BitmapText extends Container {
maxHeight = sp.height; maxHeight = sp.height;
} }
} }
for (let j = li, lj = this.children.length; j < lj; j++) {
this._charCache.push(this.removeChildAt(j));
j--;
lj--;
}
if (this._height) { if (this._height) {
maxHeight = this._height; maxHeight = this._height;
} }
...@@ -69,9 +75,6 @@ export class BitmapText extends Container { ...@@ -69,9 +75,6 @@ export class BitmapText extends Container {
break; break;
} }
} }
for (let i = li; i < this.children.length; i++) {
this._charCache.push(this.removeChildAt(li));
}
} }
private addChar(char, index) { private addChar(char, index) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2020-01-07. * Created by rockyl on 2020-01-07.
*/ */
import {FloatDisplay} from "../../../2d/display"; import {FloatDisplay} from "../../../2d/display/index";
import {afterConstructor} from "../../decorators/after-constructor"; import {afterConstructor} from "../../decorators/after-constructor";
import {applyAutoAdjust} from "../../decorators/auto-adjust"; import {applyAutoAdjust} from "../../decorators/auto-adjust";
import {applyScript} from "../../decorators/scripts"; import {applyScript} from "../../decorators/scripts";
......
...@@ -42,7 +42,7 @@ export class Image extends Sprite { ...@@ -42,7 +42,7 @@ export class Image extends Sprite {
} else { //否则就使用素材名 } else { //否则就使用素材名
const assetConfig = getAssetByName(url); const assetConfig = getAssetByName(url);
if (assetConfig) { if (assetConfig) {
url = assetConfig.url; url = assetConfig.uuid;
} }
} }
this.texture = Texture.fromImage(url); this.texture = Texture.fromImage(url);
......
/** /**
* Created by rockyl on 2019-11-08. * Created by rockyl on 2019-11-08.
*/ */
import {TextField} from "../../../2d/text"; import {TextField} from "../../../2d/text/index";
import {dataCenter} from "../data-center"; import {dataCenter} from "../data-center";
import {ESCAPE_REG_EXP, htmlToPureText} from "../../utils"; import {ESCAPE_REG_EXP, htmlToPureText} from "../../utils";
import {Event} from "../../../2d/events";
/** /**
* 文本 * 文本
......
...@@ -5,10 +5,26 @@ import {Label} from "./Label"; ...@@ -5,10 +5,26 @@ import {Label} from "./Label";
import {MouseEvent} from "../../../2d/events/MouseEvent"; import {MouseEvent} from "../../../2d/events/MouseEvent";
import {Event} from "../../../2d/events/Event"; import {Event} from "../../../2d/events/Event";
import {FloatDisplay} from "../../../2d/display/FloatDisplay"; import {FloatDisplay} from "../../../2d/display/FloatDisplay";
import {TextField} from "../../../2d/text"; import {TextField} from "../../../2d/text/index";
import {Point} from "../../../2d/math"; import {Point} from "../../../2d/math/index";
import {dirtyFieldTrigger} from "../../decorators"; import {dirtyFieldTrigger} from "../../decorators";
import {VERTICAL_ALIGN} from "../../.."; import {VERTICAL_ALIGN} from "../../../2d/const";
let timer;
function delayScrollTop() {
cancelDelayScrollTop();
timer = setTimeout(function () {
window.scrollTo(0, 0);
}, 100);
}
function cancelDelayScrollTop() {
if (timer) {
clearTimeout(timer);
timer = null;
}
}
export class TextInput extends Label { export class TextInput extends Label {
private _floatDisplay: FloatDisplay; private _floatDisplay: FloatDisplay;
...@@ -23,10 +39,11 @@ export class TextInput extends Label { ...@@ -23,10 +39,11 @@ export class TextInput extends Label {
@dirtyFieldTrigger @dirtyFieldTrigger
type: string = 'text'; type: string = 'text';
@dirtyFieldTrigger @dirtyFieldTrigger
pattern: string; charRegStr: string;
private _oldFillColor; private _oldFillColor;
private _oldStrokeColor; private _oldStrokeColor;
private _charReg: RegExp;
constructor() { constructor() {
super(); super();
...@@ -51,7 +68,10 @@ export class TextInput extends Label { ...@@ -51,7 +68,10 @@ export class TextInput extends Label {
} }
break; break;
case 'maxLength': case 'maxLength':
this.setMaxLength(); this._text = this.updateMaxLength(this._text);
break;
case 'charRegStr':
this.setCharReg();
break; break;
} }
} }
...@@ -70,12 +90,12 @@ export class TextInput extends Label { ...@@ -70,12 +90,12 @@ export class TextInput extends Label {
style.backgroundColor = 'transparent'; style.backgroundColor = 'transparent';
input.type = 'text'; input.type = 'text';
input.addEventListener('focus', this.onFocus);
input.addEventListener('blur', this.onBlur); input.addEventListener('blur', this.onBlur);
input.addEventListener('input', this.onInput); input.addEventListener('input', this.onInput);
let pl = this._placeholderLabel = new TextField(); let pl = this._placeholderLabel = new TextField();
pl.fillColor = this.placeholderColor; pl.fillColor = this.placeholderColor;
this.verticalAlign = pl.verticalAlign = VERTICAL_ALIGN.MIDDLE; this.verticalAlign = pl.verticalAlign = VERTICAL_ALIGN.MIDDLE;
this.addChild(fd); this.addChild(fd);
...@@ -84,18 +104,42 @@ export class TextInput extends Label { ...@@ -84,18 +104,42 @@ export class TextInput extends Label {
protected _setText(value) { protected _setText(value) {
super._setText(value); super._setText(value);
this.setMaxLength(); this._text = this.updateMaxLength(this._text);
this._text = this.updateWithCharReg(this._text);
setTimeout(() => { setTimeout(() => {
this.showPlaceholderLabel(value) this.showPlaceholderLabel(value)
}, 1); }, 1);
} }
private setMaxLength() { private updateMaxLength(text) {
let value = this._text; let value = text;
let maxLength = this.maxLength; let maxLength = this.maxLength;
if (maxLength > 0 && value && value.length > maxLength) { if (maxLength > 0 && value && value.length > maxLength) {
this.text = value.substr(0, maxLength); value = value.substr(0, maxLength);
}
return value;
}
private updateWithCharReg(text) {
let value = text;
if (this._charReg) {
value = '';
for (let char of text) {
if (char.match(this._charReg)) {
value += char;
}
}
}
return value;
}
private setCharReg() {
if (this.charRegStr) {
this._charReg = new RegExp(this.charRegStr);
this._text = this.updateWithCharReg(this._text);
} else {
this._charReg = null;
} }
} }
...@@ -113,6 +157,7 @@ export class TextInput extends Label { ...@@ -113,6 +157,7 @@ export class TextInput extends Label {
pl.font = this.font; pl.font = this.font;
this.addChildAt(pl, 0); this.addChildAt(pl, 0);
} }
pl.textAlign = this.textAlign;
} }
} }
...@@ -131,6 +176,8 @@ export class TextInput extends Label { ...@@ -131,6 +176,8 @@ export class TextInput extends Label {
style.width = this.width + 'px'; style.width = this.width + 'px';
style.height = this.height + 'px'; style.height = this.height + 'px';
style.fontFamily = this.font; style.fontFamily = this.font;
style.pointerEvents = 'auto';
style.textAlign = this.textAlign;
this._oldFillColor = this.fillColor; this._oldFillColor = this.fillColor;
this._oldStrokeColor = this.strokeColor; this._oldStrokeColor = this.strokeColor;
...@@ -140,10 +187,10 @@ export class TextInput extends Label { ...@@ -140,10 +187,10 @@ export class TextInput extends Label {
if (pl.parent) { if (pl.parent) {
pl.parent.removeChild(pl); pl.parent.removeChild(pl);
} }
//this.addChild(this._floatDisplay); //this.addChild(this._floatDisplay);
this._floatDisplay.alpha = 1; this._floatDisplay.alpha = 1;
input.style.pointerEvents = 'auto';
const maxLength = this.maxLength; const maxLength = this.maxLength;
if (maxLength > 0) { if (maxLength > 0) {
...@@ -152,12 +199,6 @@ export class TextInput extends Label { ...@@ -152,12 +199,6 @@ export class TextInput extends Label {
input.removeAttribute('maxLength') input.removeAttribute('maxLength')
} }
if (this.pattern) {
input.pattern = this.pattern;
} else {
input.removeAttribute('pattern')
}
if (this.type) { if (this.type) {
input.type = this.type; input.type = this.type;
} }
...@@ -183,18 +224,32 @@ export class TextInput extends Label { ...@@ -183,18 +224,32 @@ export class TextInput extends Label {
this.dispatchEvent(Event.BLUR); this.dispatchEvent(Event.BLUR);
} }
private onFocus = (e) => {
cancelDelayScrollTop();
};
private onBlur = (e) => { private onBlur = (e) => {
this.setBlur(); this.setBlur();
delayScrollTop();
}; };
private onInput = (e) => { private onInput = (e) => {
if (this._charReg) {
//console.log('before:', this._input.value);
let text = this.updateWithCharReg(this._input.value);
//console.log('after:', text);
this._input.value = text;
}
this.dispatchEvent(Event.CHANGING, this._input.value); this.dispatchEvent(Event.CHANGING, this._input.value);
}; };
private onClickStage(e) { private onClickStage(e) {
if (e.currentTarget !== this) { //e.stopPropagation();
this.setBlur(); //if (e.currentTarget !== this) {
} this.setBlur();
//}
} }
private onClickStatic() { private onClickStatic() {
......
...@@ -61,3 +61,19 @@ export function stopSound(name) { ...@@ -61,3 +61,19 @@ export function stopSound(name) {
export function destroySound(name) { export function destroySound(name) {
delete instances[name]; delete instances[name];
} }
export function mute(muted = true) {
Howler.mute(muted)
}
export function preloadSound(url, uuid) {
let sound = new Howl({
src: url,
preload: true,
});
instances[uuid] = {
sound,
keep: true,
};
}
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* Created by rockyl on 2019-11-08. * Created by rockyl on 2019-11-08.
*/ */
import {Container} from "../../2d/display"; import {Container} from "../../2d/display/index";
import {Rect, Image, Label, Circle, ScrollView, TextInput, ScrollList, BitmapText, HtmlView} from "./nodes"; import {Rect, Image, Label, Circle, ScrollView, TextInput, ScrollList, BitmapText, HtmlView} from "./nodes";
import {injectProperties, instantiateScript,} from "../utils"; import {injectProperties, instantiateScript,} from "../utils/index";
const nodeTypeMapping = { const nodeTypeMapping = {
node: Container, node: Container,
......
...@@ -15,6 +15,7 @@ import {instantiate, registerNodeType} from './game-warpper/view-interpreter' ...@@ -15,6 +15,7 @@ import {instantiate, registerNodeType} from './game-warpper/view-interpreter'
export {Howl, Howler} from 'howler'; export {Howl, Howler} from 'howler';
import emojiRegex from 'emoji-regex'; import emojiRegex from 'emoji-regex';
export {compute as computeProps} from 'props-compute';
const emojiRegexp = emojiRegex(); const emojiRegexp = emojiRegex();
......
...@@ -14,7 +14,7 @@ import {queryParams} from "./web"; ...@@ -14,7 +14,7 @@ import {queryParams} from "./web";
export let gameStage: GameStage; export let gameStage: GameStage;
export function launch(url, loadingDelegate?, onStart?) { export function launch(url, loadingDelegate?, onStart?) {
if(queryParams.__proxy_mode__){ if (queryParams.__proxy_mode__) {
return Promise.resolve('cancel launch'); return Promise.resolve('cancel launch');
} }
return globalLoader.loadJson(url) return globalLoader.loadJson(url)
...@@ -45,8 +45,11 @@ export function launchWithWindowVariable(name, loadingDelegate?, onStart?) { ...@@ -45,8 +45,11 @@ export function launchWithWindowVariable(name, loadingDelegate?, onStart?) {
return launchWithConfig(data, loadingDelegate, onStart); return launchWithConfig(data, loadingDelegate, onStart);
} }
export function launchWithConfig(config, loadingDelegate?, onStart?) { export async function launchWithConfig(config, loadingDelegate?, onStart?) {
return new Promise(resolve => { await new Promise(resolve => {
setTimeout(resolve, 300);
});
return await new Promise(resolve => {
const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.options; const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType,} = config.options;
let stage = window['stage'] = new Stage( let stage = window['stage'] = new Stage(
containerId || "game-container", containerId || "game-container",
...@@ -67,9 +70,9 @@ export function launchWithConfig(config, loadingDelegate?, onStart?) { ...@@ -67,9 +70,9 @@ export function launchWithConfig(config, loadingDelegate?, onStart?) {
let delegate = loadingDelegate || builtinLoadingView; let delegate = loadingDelegate || builtinLoadingView;
gameStage.launch(config, function(done, total){ gameStage.launch(config, function (done, total) {
delegate.onProgress && delegate.onProgress(done, total) delegate.onProgress && delegate.onProgress(done, total)
}, function(){ }, function () {
delegate.onComplete && delegate.onComplete(); delegate.onComplete && delegate.onComplete();
}, onStart); }, onStart);
}); });
......
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
*/ */
export * from './utils' export * from './utils'
export * from './math'
export * from './md5' export * from './md5'
export * from './ObjectPool' export * from './ObjectPool'
/**
* Created by rockyl on 2020-01-21.
*/
export function transPoint(str, sep = ',') {
if (str) {
let arr = str.split(sep);
return {
x: parseFloat(arr[0]),
y: parseFloat(arr[1] === undefined ? '0' : arr[1]),
}
}
}
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