init framework
This commit is contained in:
56
demo/src/AssetAdapter.ts
Normal file
56
demo/src/AssetAdapter.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014-present, Egret Technology.
|
||||
// All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Egret nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
|
||||
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class AssetAdapter implements eui.IAssetAdapter {
|
||||
/**
|
||||
* @language zh_CN
|
||||
* 解析素材
|
||||
* @param source 待解析的新素材标识符
|
||||
* @param compFunc 解析完成回调函数,示例:callBack(content:any,source:string):void;
|
||||
* @param thisObject callBack的 this 引用
|
||||
*/
|
||||
public getAsset(source: string, compFunc:Function, thisObject: any): void {
|
||||
function onGetRes(data: any): void {
|
||||
compFunc.call(thisObject, data, source);
|
||||
}
|
||||
if (RES.hasRes(source)) {
|
||||
let data = RES.getRes(source);
|
||||
if (data) {
|
||||
onGetRes(data);
|
||||
}
|
||||
else {
|
||||
RES.getResAsync(source, onGetRes, this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
RES.getResByUrl(source, onGetRes, this, RES.ResourceItem.TYPE_IMAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
51
demo/src/LoadingUI.ts
Normal file
51
demo/src/LoadingUI.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014-present, Egret Technology.
|
||||
// All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Egret nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
|
||||
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class LoadingUI extends egret.Sprite implements RES.PromiseTaskReporter {
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
this.createView();
|
||||
}
|
||||
|
||||
private textField: egret.TextField;
|
||||
|
||||
private createView(): void {
|
||||
this.textField = new egret.TextField();
|
||||
this.addChild(this.textField);
|
||||
this.textField.y = 300;
|
||||
this.textField.width = 480;
|
||||
this.textField.height = 100;
|
||||
this.textField.textAlign = "center";
|
||||
}
|
||||
|
||||
public onProgress(current: number, total: number): void {
|
||||
this.textField.text = `Loading...${current}/${total}`;
|
||||
}
|
||||
}
|
||||
95
demo/src/Main.ts
Normal file
95
demo/src/Main.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014-present, Egret Technology.
|
||||
// All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Egret nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
|
||||
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class Main extends eui.UILayer {
|
||||
|
||||
protected createChildren(): void {
|
||||
super.createChildren();
|
||||
|
||||
egret.lifecycle.addLifecycleListener((context) => {
|
||||
// custom lifecycle plugin
|
||||
})
|
||||
|
||||
egret.lifecycle.onPause = () => {
|
||||
egret.ticker.pause();
|
||||
}
|
||||
|
||||
egret.lifecycle.onResume = () => {
|
||||
egret.ticker.resume();
|
||||
}
|
||||
|
||||
//inject the custom material parser
|
||||
//注入自定义的素材解析器
|
||||
let assetAdapter = new AssetAdapter();
|
||||
egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
|
||||
egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
|
||||
|
||||
|
||||
this.runGame();
|
||||
}
|
||||
|
||||
private runGame() {
|
||||
this.createGameScene();
|
||||
}
|
||||
|
||||
private async loadResource() {
|
||||
try {
|
||||
const loadingView = new LoadingUI();
|
||||
this.stage.addChild(loadingView);
|
||||
await RES.loadConfig("resource/default.res.json", "resource/");
|
||||
await this.loadTheme();
|
||||
await RES.loadGroup("preload", 0, loadingView);
|
||||
this.stage.removeChild(loadingView);
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private loadTheme() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// load skin theme configuration file, you can manually modify the file. And replace the default skin.
|
||||
//加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
|
||||
let theme = new eui.Theme("resource/default.thm.json", this.stage);
|
||||
theme.addEventListener(eui.UIEvent.COMPLETE, () => {
|
||||
resolve();
|
||||
}, this);
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建场景界面
|
||||
* Create scene interface
|
||||
*/
|
||||
protected createGameScene(): void {
|
||||
let scene = SceneManager.createScene("main", new Scene(this)).setActive();
|
||||
}
|
||||
}
|
||||
41
demo/src/Platform.ts
Normal file
41
demo/src/Platform.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 平台数据接口。
|
||||
* 由于每款游戏通常需要发布到多个平台上,所以提取出一个统一的接口用于开发者获取平台数据信息
|
||||
* 推荐开发者通过这种方式封装平台逻辑,以保证整体结构的稳定
|
||||
* 由于不同平台的接口形式各有不同,白鹭推荐开发者将所有接口封装为基于 Promise 的异步形式
|
||||
*/
|
||||
declare interface Platform {
|
||||
|
||||
getUserInfo(): Promise<any>;
|
||||
|
||||
login(): Promise<any>
|
||||
|
||||
}
|
||||
|
||||
class DebugPlatform implements Platform {
|
||||
async getUserInfo() {
|
||||
return { nickName: "username" }
|
||||
}
|
||||
async login() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!window.platform) {
|
||||
window.platform = new DebugPlatform();
|
||||
}
|
||||
|
||||
|
||||
|
||||
declare let platform: Platform;
|
||||
|
||||
declare interface Window {
|
||||
|
||||
platform: Platform
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
97
demo/src/ThemeAdapter.ts
Normal file
97
demo/src/ThemeAdapter.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014-present, Egret Technology.
|
||||
// All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Egret nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
|
||||
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class ThemeAdapter implements eui.IThemeAdapter {
|
||||
|
||||
/**
|
||||
* 解析主题
|
||||
* @param url 待解析的主题url
|
||||
* @param onSuccess 解析完成回调函数,示例:compFunc(e:egret.Event):void;
|
||||
* @param onError 解析失败回调函数,示例:errorFunc():void;
|
||||
* @param thisObject 回调的this引用
|
||||
*/
|
||||
public getTheme(url: string, onSuccess: Function, onError: Function, thisObject: any): void {
|
||||
function onResGet(e: string): void {
|
||||
onSuccess.call(thisObject, e);
|
||||
}
|
||||
function onResError(e: RES.ResourceEvent): void {
|
||||
if (e.resItem.url == url) {
|
||||
RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
|
||||
onError.call(thisObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof generateEUI !== 'undefined') {
|
||||
egret.callLater(() => {
|
||||
onSuccess.call(thisObject, generateEUI);
|
||||
}, this);
|
||||
}
|
||||
else if (typeof generateEUI2 !== 'undefined') {
|
||||
RES.getResByUrl("resource/gameEui.json", (data, url) => {
|
||||
window["JSONParseClass"]["setData"](data);
|
||||
egret.callLater(() => {
|
||||
onSuccess.call(thisObject, generateEUI2);
|
||||
}, this);
|
||||
}, this, RES.ResourceItem.TYPE_JSON);
|
||||
}
|
||||
else if (typeof generateJSON !== 'undefined') {
|
||||
if (url.indexOf(".exml") > -1) {
|
||||
let dataPath = url.split("/");
|
||||
dataPath.pop();
|
||||
let dirPath = dataPath.join("/") + "_EUI.json";
|
||||
if (!generateJSON.paths[url]) {
|
||||
RES.getResByUrl(dirPath, (data) => {
|
||||
window["JSONParseClass"]["setData"](data);
|
||||
egret.callLater(() => {
|
||||
onSuccess.call(thisObject, generateJSON.paths[url]);
|
||||
}, this);
|
||||
}, this, RES.ResourceItem.TYPE_JSON);
|
||||
} else {
|
||||
egret.callLater(() => {
|
||||
onSuccess.call(thisObject, generateJSON.paths[url]);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
egret.callLater(() => {
|
||||
onSuccess.call(thisObject, generateJSON);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
|
||||
RES.getResByUrl(url, onResGet, this, RES.ResourceItem.TYPE_TEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare var generateEUI: { paths: string[], skins: any }
|
||||
declare var generateEUI2: { paths: string[], skins: any }
|
||||
declare var generateJSON: { paths: string[], skins: any }
|
||||
Reference in New Issue
Block a user