Commit 217c86c6 authored by rockyl's avatar rockyl

增加HtmlRenderer组件

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