Commit 217c86c6 authored by rockyl's avatar rockyl

增加HtmlRenderer组件

parent b4a6f7cf
...@@ -66,10 +66,11 @@ export default class AssetsManager{ ...@@ -66,10 +66,11 @@ export default class AssetsManager{
/** /**
* 加载一批资源 * 加载一批资源
* @param items 资源数组: ['aaa.png', {uuid: 'bbb', url: 'alias.png'}] * @param items 资源数组: ['aaa.png', {uuid: 'bbb', url: 'alias.png'}]
* @param replaceConfig 替换项配置
* @param progress 进度回调,参数为加载百分比 * @param progress 进度回调,参数为加载百分比
* @return Promise<Array<any>> 资源组 * @return Promise<Array<any>> 资源组
*/ */
loadResItems(items: Array<any | string>, progress?: (percentage: number) => void): Promise<Array<any>> { loadResItems(items: Array<any | string>, replaceConfig?, progress?: (percentage: number) => void): Promise<Array<any>> {
let total = items.length; let total = items.length;
let count = 0; let count = 0;
...@@ -81,6 +82,9 @@ export default class AssetsManager{ ...@@ -81,6 +82,9 @@ export default class AssetsManager{
} else { } else {
url = item.url; url = item.url;
} }
if(replaceConfig){
url = replaceConfig[url] || url;
}
if (!url) { if (!url) {
return Promise.resolve(); return Promise.resolve();
} }
...@@ -392,7 +396,7 @@ export default class AssetsManager{ ...@@ -392,7 +396,7 @@ export default class AssetsManager{
loadAnim(url: string, uuid?: string, cache: boolean = true, config?: any): Promise<FrameAnimation[]> { loadAnim(url: string, uuid?: string, cache: boolean = true, config?: any): Promise<FrameAnimation[]> {
let pngFile = url.substring(0, url.lastIndexOf('.')) + '.png'; let pngFile = url.substring(0, url.lastIndexOf('.')) + '.png';
return Promise.all(<Promise<any>[]>[ return <Promise<FrameAnimation[]>>Promise.all([
this.loadJson(url, null, false), this.loadJson(url, null, false),
this.loadImage(pngFile, null, false), this.loadImage(pngFile, null, false),
]).then( ]).then(
......
...@@ -52,8 +52,12 @@ export class Entity extends HashObject { ...@@ -52,8 +52,12 @@ export class Entity extends HashObject {
set enabled(value: boolean) { set enabled(value: boolean) {
if (this._enabled !== value) { if (this._enabled !== value) {
this._enabled = value; this._enabled = value;
let that = this;
traverse(this, function (child: Entity) { traverse(this, function (child: Entity) {
if (child !== that && !child._enabled) {
return true;
}
child._invokeEnabledState(value); child._invokeEnabledState(value);
return false; return false;
}, -1, true) }, -1, true)
...@@ -61,10 +65,17 @@ export class Entity extends HashObject { ...@@ -61,10 +65,17 @@ export class Entity extends HashObject {
} }
_invokeEnabledState(enabled: boolean) { _invokeEnabledState(enabled: boolean) {
if (this._enabled && enabled) { /*if (this._enabled && enabled) {
this.onEnable(); this.onEnable();
} else if (!this._enabled && !enabled) { } else if (!this._enabled && !enabled) {
this.onDisable(); this.onDisable();
}*/
if (this._enabled) {
if(enabled){
this.onEnable();
}else{
this.onDisable();
}
} }
} }
......
...@@ -37,7 +37,7 @@ export class ScillaEngine { ...@@ -37,7 +37,7 @@ export class ScillaEngine {
readonly dataCenterConfig: any = {}; readonly dataCenterConfig: any = {};
private _root: Entity; private _root: Entity;
private canvasElement: HTMLElement; private _canvasElement: HTMLCanvasElement;
private _flush = 0; private _flush = 0;
private _currentFlush = 0; private _currentFlush = 0;
...@@ -68,17 +68,19 @@ export class ScillaEngine { ...@@ -68,17 +68,19 @@ export class ScillaEngine {
injectProp(this.customConfig, _customConfig); injectProp(this.customConfig, _customConfig);
injectProp(this.dataCenterConfig, _dataCenterConfig); injectProp(this.dataCenterConfig, _dataCenterConfig);
for(let item of this.dataCenterConfig.dataCenterRoot){ if(this.dataCenterConfig.dataCenterRoot){
this._dataCenter.register(item); for(let item of this.dataCenterConfig.dataCenterRoot){
this._dataCenter.register(item);
}
} }
const {canvas, designWidth, designHeight, scaleMode, modifyCanvasSize, touchEnabled} = this.engineConfig; const {canvas, designWidth, designHeight, scaleMode, modifyCanvasSize, touchEnabled} = this.engineConfig;
this.canvasElement = typeof canvas == 'string' ? document.getElementById(canvas) : canvas; this._canvasElement = typeof canvas == 'string' ? document.getElementById(canvas) : canvas;
this._interactContext = new InteractContext(this); this._interactContext = new InteractContext(this);
this._interactContext.setup({ this._interactContext.setup({
canvas: this.canvasElement, canvas: this._canvasElement,
touchHandlers: { touchHandlers: {
onTouchBegin: this.onTouchBegin.bind(this), onTouchBegin: this.onTouchBegin.bind(this),
onTouchMove: this.onTouchMove.bind(this), onTouchMove: this.onTouchMove.bind(this),
...@@ -89,7 +91,7 @@ export class ScillaEngine { ...@@ -89,7 +91,7 @@ export class ScillaEngine {
this._renderContext = new RenderContext(this); this._renderContext = new RenderContext(this);
this._renderContext.setup({ this._renderContext.setup({
canvas: this.canvasElement, canvas: this._canvasElement,
designWidth, designWidth,
designHeight, designHeight,
scaleMode, scaleMode,
...@@ -189,6 +191,10 @@ export class ScillaEngine { ...@@ -189,6 +191,10 @@ export class ScillaEngine {
return this._assetsManager; return this._assetsManager;
} }
get canvasElement(): HTMLCanvasElement{
return this._canvasElement;
}
/** /**
* 获取数据中心实例 * 获取数据中心实例
*/ */
...@@ -318,7 +324,7 @@ export class ScillaEngine { ...@@ -318,7 +324,7 @@ export class ScillaEngine {
const {scaleX, scaleY, rotation} = this.renderContext; const {scaleX, scaleY, rotation} = this.renderContext;
let x = pageX, y = pageY; let x = pageX, y = pageY;
let box = this.canvasElement.getBoundingClientRect(); let box = this._canvasElement.getBoundingClientRect();
if (!isLocalPos) { if (!isLocalPos) {
let doc = document.documentElement; let doc = document.documentElement;
let left = box.left + window.pageXOffset - doc.clientLeft; let left = box.left + window.pageXOffset - doc.clientLeft;
...@@ -359,7 +365,7 @@ export class ScillaEngine { ...@@ -359,7 +365,7 @@ export class ScillaEngine {
y = y * scaleY; y = y * scaleY;
if (!isLocalPos) { if (!isLocalPos) {
let box = this.canvasElement.getBoundingClientRect(); let box = this._canvasElement.getBoundingClientRect();
let doc = document.documentElement; let doc = document.documentElement;
let left = box.left + window.pageXOffset - doc.clientLeft; let left = box.left + window.pageXOffset - doc.clientLeft;
let top = box.top + window.pageYOffset - doc.clientTop; let top = box.top + window.pageYOffset - doc.clientTop;
......
...@@ -48,7 +48,7 @@ export default class DataCenter extends EventEmitter{ ...@@ -48,7 +48,7 @@ export default class DataCenter extends EventEmitter{
* @param type * @param type
* @param key * @param key
*/ */
public get(type: string, key: string) { public get(type: string, key?: string) {
if (!key) return this.store[type]; if (!key) return this.store[type];
return this.store[type][key]; return this.store[type][key];
} }
......
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