Commit 29b570c6 by Matt

init egret game project

parent b8fea860
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Wing Player",
"type": "chrome",
"request": "launch",
"file": "index.html",
"runtimeExecutable": "${execPath}",
"useBuildInServer": true,
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"preLaunchTask":"build",
"port":5747
},
{
"name": "Launch Chrome",
"type": "chrome",
"request": "launch",
"file": "index.html",
"useBuildInServer": true,
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"preLaunchTask":"build",
"userDataDir":"${tmpdir}",
"port":5747
}
]
}
\ No newline at end of file
{
"search.exclude": {
"**/bin-debug": true,
"**/bin-release": true
}
}
\ No newline at end of file
{
"version": "0.1.0",
"command": "egret",
"isShellCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "build",
"showOutput": "always",
"args": [
"build",
"-sourcemap"
],
"problemMatcher": "$tsc"
},
{
"taskName": "clean",
"showOutput": "always",
"args": [
"build",
"-e"
],
"problemMatcher": "$tsc"
},
{
"taskName": "publish",
"showOutput": "always",
"args": [
"publish"
],
"problemMatcher": "$tsc"
}
]
}
\ No newline at end of file
//////////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
//////////////////////////////////////////////////////////////////////////////////////
var __reflect = (this && this.__reflect) || function (p, c, t) {
p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) {
function r() {
this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
var LoadingUI = (function (_super) {
__extends(LoadingUI, _super);
function LoadingUI() {
var _this = _super.call(this) || this;
_this.createView();
return _this;
}
LoadingUI.prototype.createView = function () {
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";
};
LoadingUI.prototype.onProgress = function (current, total) {
this.textField.text = "Loading..." + current + "/" + total;
};
return LoadingUI;
}(egret.Sprite));
__reflect(LoadingUI.prototype, "LoadingUI", ["RES.PromiseTaskReporter"]);
var __reflect = (this && this.__reflect) || function (p, c, t) {
p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var DebugPlatform = (function () {
function DebugPlatform() {
}
DebugPlatform.prototype.getUserInfo = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, { nickName: "username" }];
});
});
};
DebugPlatform.prototype.login = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
};
return DebugPlatform;
}());
__reflect(DebugPlatform.prototype, "DebugPlatform", ["Platform"]);
if (!window.platform) {
window.platform = new DebugPlatform();
}
{
"engineVersion": "5.1.10",
"compilerVersion": "5.1.10",
"template": {},
"target": {
"current": "web"
},
"modules": [
{
"name": "egret"
},
{
"name": "game"
},
{
"name": "tween"
},
{
"name": "assetsmanager"
},
{
"name": "promise"
}
]
}
\ No newline at end of file
File added
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Egret</title>
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="full-screen" content="true" />
<meta name="screen-orientation" content="portrait" />
<meta name="x5-fullscreen" content="true" />
<meta name="360-fullscreen" content="true" />
<style>
html, body {
-ms-touch-action: none;
background: #888888;
padding: 0;
border: 0;
margin: 0;
height: 100%;
}
</style>
</head>
<body>
<div style="margin: auto;width: 100%;height: 100%;" class="egret-player"
data-entry-class="Main"
data-orientation="landscape"
data-scale-mode="fixedWidth"
data-frame-rate="30"
data-content-width="640"
data-content-height="1136"
data-multi-fingered="2"
data-show-fps="false" data-show-log="false"
data-show-fps-style="x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9">
</div>
<script>
var loadScript = function (list, callback) {
var loaded = 0;
var loadNext = function () {
loadSingleScript(list[loaded], function () {
loaded++;
if (loaded >= list.length) {
callback();
}
else {
loadNext();
}
})
};
loadNext();
};
var loadSingleScript = function (src, callback) {
var s = document.createElement('script');
s.async = false;
s.src = src;
s.addEventListener('load', function () {
s.parentNode.removeChild(s);
s.removeEventListener('load', arguments.callee, false);
callback();
}, false);
document.body.appendChild(s);
};
var xhr = new XMLHttpRequest();
xhr.open('GET', './manifest.json?v=' + Math.random(), true);
xhr.addEventListener("load", function () {
var manifest = JSON.parse(xhr.response);
var list = manifest.initial.concat(manifest.game);
loadScript(list, function () {
/**
* {
* "renderMode":, //Engine rendering mode, "canvas" or "webgl"
* "audioType": 0 //Use the audio type, 0: default, 2: web audio, 3: audio
* "antialias": //Whether the anti-aliasing is enabled in WebGL mode, true: on, false: off, defaults to false
* "calculateCanvasScaleFactor": //a function return canvas scale factor
* }
**/
egret.runEgret({ renderMode: "webgl", audioType: 0, calculateCanvasScaleFactor:function(context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}});
});
});
xhr.send(null);
</script>
</body>
</html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.ES6Promise=e()}(this,function(){"use strict";function t(t){return"function"==typeof t||"object"==typeof t&&null!==t}function e(t){return"function"==typeof t}function n(t){I=t}function r(t){J=t}function o(){return function(){return process.nextTick(a)}}function i(){return"undefined"!=typeof H?function(){H(a)}:c()}function s(){var t=0,e=new V(a),n=document.createTextNode("");return e.observe(n,{characterData:!0}),function(){n.data=t=++t%2}}function u(){var t=new MessageChannel;return t.port1.onmessage=a,function(){return t.port2.postMessage(0)}}function c(){var t=setTimeout;return function(){return t(a,1)}}function a(){for(var t=0;G>t;t+=2){var e=$[t],n=$[t+1];e(n),$[t]=void 0,$[t+1]=void 0}G=0}function f(){try{var t=require,e=t("vertx");return H=e.runOnLoop||e.runOnContext,i()}catch(n){return c()}}function l(t,e){var n=arguments,r=this,o=new this.constructor(p);void 0===o[ee]&&k(o);var i=r._state;return i?!function(){var t=n[i-1];J(function(){return x(i,o,t,r._result)})}():E(r,o,t,e),o}function h(t){var e=this;if(t&&"object"==typeof t&&t.constructor===e)return t;var n=new e(p);return w(n,t),n}function p(){}function v(){return new TypeError("You cannot resolve a promise with itself")}function d(){return new TypeError("A promises callback cannot return that same promise.")}function _(t){try{return t.then}catch(e){return ie.error=e,ie}}function y(t,e,n,r){try{t.call(e,n,r)}catch(o){return o}}function m(t,e,n){J(function(t){var r=!1,o=y(n,e,function(n){r||(r=!0,e!==n?w(t,n):S(t,n))},function(e){r||(r=!0,j(t,e))},"Settle: "+(t._label||" unknown promise"));!r&&o&&(r=!0,j(t,o))},t)}function b(t,e){e._state===re?S(t,e._result):e._state===oe?j(t,e._result):E(e,void 0,function(e){return w(t,e)},function(e){return j(t,e)})}function g(t,n,r){n.constructor===t.constructor&&r===l&&n.constructor.resolve===h?b(t,n):r===ie?j(t,ie.error):void 0===r?S(t,n):e(r)?m(t,n,r):S(t,n)}function w(e,n){e===n?j(e,v()):t(n)?g(e,n,_(n)):S(e,n)}function A(t){t._onerror&&t._onerror(t._result),P(t)}function S(t,e){t._state===ne&&(t._result=e,t._state=re,0!==t._subscribers.length&&J(P,t))}function j(t,e){t._state===ne&&(t._state=oe,t._result=e,J(A,t))}function E(t,e,n,r){var o=t._subscribers,i=o.length;t._onerror=null,o[i]=e,o[i+re]=n,o[i+oe]=r,0===i&&t._state&&J(P,t)}function P(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r=void 0,o=void 0,i=t._result,s=0;s<e.length;s+=3)r=e[s],o=e[s+n],r?x(n,r,o,i):o(i);t._subscribers.length=0}}function T(){this.error=null}function M(t,e){try{return t(e)}catch(n){return se.error=n,se}}function x(t,n,r,o){var i=e(r),s=void 0,u=void 0,c=void 0,a=void 0;if(i){if(s=M(r,o),s===se?(a=!0,u=s.error,s=null):c=!0,n===s)return void j(n,d())}else s=o,c=!0;n._state!==ne||(i&&c?w(n,s):a?j(n,u):t===re?S(n,s):t===oe&&j(n,s))}function C(t,e){try{e(function(e){w(t,e)},function(e){j(t,e)})}catch(n){j(t,n)}}function O(){return ue++}function k(t){t[ee]=ue++,t._state=void 0,t._result=void 0,t._subscribers=[]}function Y(t,e){this._instanceConstructor=t,this.promise=new t(p),this.promise[ee]||k(this.promise),B(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?S(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&S(this.promise,this._result))):j(this.promise,q())}function q(){return new Error("Array Methods must be provided an Array")}function F(t){return new Y(this,t).promise}function D(t){var e=this;return new e(B(t)?function(n,r){for(var o=t.length,i=0;o>i;i++)e.resolve(t[i]).then(n,r)}:function(t,e){return e(new TypeError("You must pass an array to race."))})}function K(t){var e=this,n=new e(p);return j(n,t),n}function L(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function N(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function U(t){this[ee]=O(),this._result=this._state=void 0,this._subscribers=[],p!==t&&("function"!=typeof t&&L(),this instanceof U?C(this,t):N())}function W(){var t=void 0;if("undefined"!=typeof global)t=global;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var n=t.Promise;if("undefined"!=typeof egret_native&&egret_native.capability&&!egret_native.capability("Promise")&&(n=void 0),n){var r=null;try{r=Object.prototype.toString.call(n.resolve())}catch(e){}if("[object Promise]"===r&&!n.cast)return}t.Promise=U}var z=void 0;z=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var B=z,G=0,H=void 0,I=void 0,J=function(t,e){$[G]=t,$[G+1]=e,G+=2,2===G&&(I?I(a):te())},Q="undefined"!=typeof window?window:void 0,R=Q||{},V=R.MutationObserver||R.WebKitMutationObserver,X="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),Z="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,$=new Array(1e3),te=void 0;te=X?o():V?s():Z?u():void 0===Q&&"function"==typeof require?f():c();var ee=Math.random().toString(36).substring(16),ne=void 0,re=1,oe=2,ie=new T,se=new T,ue=0;return Y.prototype._enumerate=function(){for(var t=this.length,e=this._input,n=0;this._state===ne&&t>n;n++)this._eachEntry(e[n],n)},Y.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,r=n.resolve;if(r===h){var o=_(t);if(o===l&&t._state!==ne)this._settledAt(t._state,e,t._result);else if("function"!=typeof o)this._remaining--,this._result[e]=t;else if(n===U){var i=new n(p);g(i,t,o),this._willSettleAt(i,e)}else this._willSettleAt(new n(function(e){return e(t)}),e)}else this._willSettleAt(r(t),e)},Y.prototype._settledAt=function(t,e,n){var r=this.promise;r._state===ne&&(this._remaining--,t===oe?j(r,n):this._result[e]=n),0===this._remaining&&S(r,this._result)},Y.prototype._willSettleAt=function(t,e){var n=this;E(t,void 0,function(t){return n._settledAt(re,e,t)},function(t){return n._settledAt(oe,e,t)})},U.all=F,U.race=D,U.resolve=h,U.reject=K,U._setScheduler=n,U._setAsap=r,U._asap=J,U.prototype={constructor:U,then:l,"catch":function(t){return this.then(null,t)}},U.polyfill=W,U.Promise=U,U}),ES6Promise.polyfill();
\ No newline at end of file
{
"initial": [
"libs/modules/egret/egret.js",
"libs/modules/egret/egret.web.js",
"libs/modules/game/game.js",
"libs/modules/tween/tween.js",
"libs/modules/assetsmanager/assetsmanager.js",
"libs/modules/promise/promise.js"
],
"game": [
"bin-debug/LoadingUI.js",
"bin-debug/Main.js",
"bin-debug/Platform.js"
]
}
\ No newline at end of file
[
"<font color=0x00ff0c>Open-source</font>,<font color=0x00ff0c>Free</font>,<font color=0x00ff0c>Multi-platform</font>",
"Push <font color=0x00ff0c>Game </font>Forward",
"<font color=0x00ff0c>HTML5 </font>Game Engine"
]
\ No newline at end of file
{
"groups":[
{
"keys":"bg_jpg,egret_icon_png,description_json",
"name":"preload"
}],
"resources":[
{
"name":"bg_jpg",
"type":"image",
"url":"assets/bg.jpg"
},
{
"name":"egret_icon_png",
"type":"image",
"url":"assets/egret_icon.png"
},
{
"name":"description_json",
"type":"json",
"url":"config/description.json"
}]
}
\ No newline at end of file
/**
* ResourceManager 配置文件
*/
type ResourceManagerConfig = {
/**
* 构建与发布配置
*/
buildConfig: (param: BuildConfigParam) => UserConfig,
/**
* 设置资源类型
*/
typeSelector: (path: string) => (string | null | undefined)
/**
* 设置资源的合并策略
*/
mergeSelector?: (path: string) => (string | null | undefined),
/**
* 设置资源的命名策略
* beta 功能,请勿随意使用
*/
nameSelector?: (path: string) => (string | null | undefined)
}
/**
* 构建配置
*/
type UserConfig = {
/**
* 输出路径
*/
outputDir: string,
/**
* 插件
*/
commands: (string | plugins.Command)[]
}
type BuildConfigParam = {
/**
* 当前命令,build 或者 command
*/
readonly command: string;
/**
* 发布平台
*/
readonly target: string;
/**
* 开发者指定的版本号
*/
readonly version: string;
/**
* 项目名称
*/
readonly projectName: string;
/**
* 项目路径
*/
readonly projectRoot: string;
/**
* 项目配置
*/
readonly projectConfig: ProjectConfig;
}
type ProjectConfig = {
entryClassName: string;
orientation: string;
frameRate: number;
scaleMode: string;
contentWidth: number;
contentHeight: number;
showFPS: boolean;
fpsStyles: string;
showLog: boolean;
maxTouches: number;
}
/**
* 匹配机制,将满足 from 的文件输出为 to 格式的文件
* from 采用 glob 表达式 , to 包含 [path][name][hash][ext]四个变量
* 示例:{ from:"resource/**.*" , to:"[path][name]_[hash].[ext]" }
*/
type Matcher = {
from: string[],
to: string
}
declare namespace plugins {
interface CommandContext {
/**
* 可以用此接口进行文件创建
*/
createFile(relativeFilePath: string, contents: Buffer);
/**
* 构建配置
*/
buildConfig: BuildConfigParam;
/**
* 项目绝对路径
*/
projectRoot: string;
/**
* 项目输出绝对路径
*/
outputDir: string;
}
/**
* 构建管线命令
*/
interface Command {
/**
* 项目中的每个文件都会执行此函数,返回 file 表示保留此文件,返回 null 表示将此文件从构建管线中删除,即不会发布
*/
onFile?(file: File): Promise<File | null>
/**
* 项目中所有文件均执行完后,最终会执行此函数。
* 这个函数主要被用于创建新文件
*/
onFinish?(pluginContext?: CommandContext): Promise<void>
[options: string]: any;
}
interface File {
/**
* 文件内容的二进制流,如果开发者需要修改文件内容,请修改此属性
*/
contents: Buffer;
/**
* 文件绝对路径,如果开发者需要对文件进行重命名,请修改此属性
*/
path: string;
/**
* 文件所在的项目的项目路径
*/
readonly base: string;
/**
* 文件的相对于 base 属性的相对路径
*/
readonly relative: string;
/**
* 文件变更历史,history[0] 即 origin 属性
*/
readonly history: ReadonlyArray<string>;
/**
* 文件所在的文件夹的绝对路径
*/
readonly dirname: string;
/**
* 文件的文件名
*/
readonly basename: string;
/**
* 文件的扩展名
*/
readonly extname: string;
/**
* 文件的初始文件名
*/
readonly origin: string;
/**
* 其他自定义属性
*/
[customProperty: string]: any;
}
}
declare module 'built-in' {
/**
* 混淆插件参数,设置源代码和目标代码
*/
type UglifyPluginOption = { sources: string[], target: string };
type UglifyPluginOptions = UglifyPluginOption[];
/**
* 混淆插件
*/
export class UglifyPlugin implements plugins.Command {
constructor(mergeSelector: UglifyPluginOptions);
}
type LibraryType = "debug" | "release";
type CompilePluginOptions = { libraryType: LibraryType, defines?: any };
/**
* 编译命令
*/
export class CompilePlugin implements plugins.Command {
constructor(options: CompilePluginOptions);
}
/**
* EXML 插件,用于发布 EXML 文件
*/
export class ExmlPlugin implements plugins.Command {
constructor(publishPolicy: EXML_Publish_Policy);
}
/**
* 发布策略
* * default : 使用 egretProperties.json 中的 exmlPublishPolicy 中的策略
* * debug : 默认策略,用于开发环境
* * contents : 将 EXML 的内容写入到主题文件中
* * gjs : 将生成的JS文件写入到主题文件中
* * commonjs : 将EXML合并为一个 CommonJS 风格的文件
*/
type EXML_Publish_Policy = "default" | "debug" | "contents" | "gjs" | "commonjs"
/**
* 生成 manifest 文件,这个文件会被用于记录 JavaScript 文件的版本号
*/
export class ManifestPlugin implements plugins.Command {
constructor(options?: ManifestPluginOptions)
}
/**
* 生成文件的文件名
* 支持 json 与 js 两种格式
*/
type ManifestPluginOptions = {
output: string,
hash?: "crc32",
/**
* 是否输出转换过程
*/
verbose?: boolean
}
/**
* EmitResConfigFilePlugin 的参数
* * output: 生成路径,可以指定生成为 *.res.js 文件或者 *.res.json 文件
* * typeSelector: 根据文件路径决定文件类型
* * nameSelector: 根据文件路径决定文件的资源名
* * groupSelector: 根据文件路径决定资源所述的资源组
*/
type EmitResConfigFilePluginOptions = {
output: string,
typeSelector: (path: string) => string | null | undefined,
nameSelector: (path: string) => string | null | undefined,
groupSelector: (path: string) => string | null | undefined,
}
/**
* 生成 res.json 文件或者 res.js 文件
*/
export class EmitResConfigFilePlugin implements plugins.Command {
constructor(options: EmitResConfigFilePluginOptions)
}
/**
* 增量编译
* 这个插件生成的 JavaScript 代码不会被添加到构建管线中,后续其他插件无法获取生成的 js 文件
* 这个功能将会在未来被 watch 模式代替掉
*/
export class IncrementCompilePlugin implements plugins.Command {
}
/**
* 使用 TextureMerger 实现纹理自动合并,依赖 TextureMerger 1.7 以上的版本
*/
export class TextureMergerPlugin implements plugins.Command {
constructor();
}
type CleanPluginOptions = {
matchers: string[]
}
export class CleanPlugin implements plugins.Command {
constructor(options: CleanPluginOptions);
}
type RenamePluginOptions = {
/**
* 是否输出日志
*/
verbose?: boolean
/**
* 采用何种 hash 算法,目前暂时只支持 crc32
*/
hash?: "crc32"
/**
* 设置匹配规则,将指定文件进行改名
* 该参数是个数组,允许设置多个匹配规则
*/
matchers: Matcher[]
}
/**
* 修改文件名插件
*/
export class RenamePlugin implements plugins.Command {
constructor(options: RenamePluginOptions);
}
type ResSplitPluginOptions = {
/**
* 是否输出日志
*/
verbose?: boolean
/**
* 设置匹配规则,将指定文件拷贝至其他文件夹
* 该参数是个数组,允许设置多个匹配规则
*/
matchers: Matcher[]
}
export class ResSplitPlugin implements plugins.Command {
constructor(options: ResSplitPluginOptions);
}
type ZipPluginOptions = {
mergeSelector: (p: string) => string
}
export class ZipPlugin implements plugins.Command {
constructor(option: ZipPluginOptions);
}
}
\ No newline at end of file
import * as fs from 'fs';
import * as path from 'path';
type ManifestConfig = {
initial: string[],
game: string[]
}
export class BricksPlugin implements plugins.Command {
constructor() {
}
async onFile(file: plugins.File) {
const filename = file.origin;
if (filename == 'manifest.json') {
const contents = file.contents.toString();
const jsonData: ManifestConfig = JSON.parse(contents);
let content = '';
for (let item of jsonData.initial) {
if (item != 'js/promise.js' && item != 'js/promise.min.js') {
content += `BK.Script.loadlib("GameRes://${item}");\n`
}
if (item == "js/egret.js" || item == 'js/egret.min.js') {
content += `BK.Script.loadlib("GameRes://egret.bricks.js");\n`
}
}
for (let item of jsonData.game) {
content += `BK.Script.loadlib("GameRes://${item}");\n`
}
file.path = file.dirname + '/manifest.js'
file.contents = new Buffer(content);
} else if (filename == 'main.js') {
const content = file.contents.toString();
let result = content.replace(/RES\.loadConfig\("resource\/default\.res\.json", "resource\/"\)/gm, 'RES.loadConfig("GameRes://resource/default.res.json", "GameRes://resource/")');
result = result.replace(/eui\.Theme\("resource\/default\.thm\.json", _this\.stage\)/gm, 'eui.Theme("GameRes://resource/default.thm.json", _this.stage)');
file.path = file.dirname + '/main.js'
file.contents = new Buffer(result);
}
return file;
}
async onFinish(pluginContext) {
}
}
\ No newline at end of file
/// 阅读 api.d.ts 查看文档
///<reference path="api.d.ts"/>
import * as path from 'path';
import { UglifyPlugin, CompilePlugin, ManifestPlugin, ExmlPlugin, EmitResConfigFilePlugin, TextureMergerPlugin } from 'built-in';
import { BricksPlugin } from './bricks/bricks';
import { CustomPlugin } from './myplugin';
import * as defaultConfig from './config';
const config: ResourceManagerConfig = {
buildConfig: (params) => {
const { target, command, projectName, version } = params;
const outputDir = `../${projectName}_android/assets/game`;
return {
outputDir,
commands: [
// new CompilePlugin({ libraryType: "debug", defines: { DEBUG: false, RELEASE: true } }),
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
new CompilePlugin({ libraryType: "release", defines: { DEBUG: false, RELEASE: true } }),
new UglifyPlugin([{
sources: ["main.js"],
target: "main.min.js"
}]),
new ManifestPlugin({ output: 'manifest.json' })
]
}
},
mergeSelector: defaultConfig.mergeSelector,
typeSelector: defaultConfig.typeSelector
}
export = config;
/// 阅读 api.d.ts 查看文档
///<reference path="api.d.ts"/>
import * as path from 'path';
import { UglifyPlugin, CompilePlugin, ManifestPlugin, ExmlPlugin, EmitResConfigFilePlugin, TextureMergerPlugin } from 'built-in';
import { BricksPlugin } from './bricks/bricks';
import { CustomPlugin } from './myplugin';
import * as defaultConfig from './config';
const config: ResourceManagerConfig = {
buildConfig: (params) => {
const { target, command, projectName, version } = params;
const outputDir = `../${projectName}_bricks/PublicBrickEngineGame/Res`;
return {
outputDir,
commands: [
new CompilePlugin({ libraryType: "debug", defines: { DEBUG: true, RELEASE: false } }),
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
new ManifestPlugin({ output: 'manifest.json' }),
new BricksPlugin()
]
}
},
mergeSelector: defaultConfig.mergeSelector,
typeSelector: defaultConfig.typeSelector
}
export = config;
/// 阅读 api.d.ts 查看文档
///<reference path="api.d.ts"/>
import * as path from 'path';
import { UglifyPlugin, CompilePlugin, ManifestPlugin, ExmlPlugin, EmitResConfigFilePlugin, TextureMergerPlugin } from 'built-in';
import { BricksPlugin } from './bricks/bricks';
import { CustomPlugin } from './myplugin';
import * as defaultConfig from './config';
const config: ResourceManagerConfig = {
buildConfig: (params) => {
const { target, command, projectName, version } = params;
const outputDir = `../${projectName}_ios/assets/game`;
return {
outputDir,
commands: [
new CompilePlugin({ libraryType: "debug", defines: { DEBUG: false, RELEASE: true } }),
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
new CompilePlugin({ libraryType: "release", defines: { DEBUG: false, RELEASE: true } }),
new UglifyPlugin([{
sources: ["main.js"],
target: "main.min.js"
}]),
new ManifestPlugin({ output: 'manifest.json' })
]
}
},
mergeSelector: defaultConfig.mergeSelector,
typeSelector: defaultConfig.typeSelector
}
export = config;
/// 阅读 api.d.ts 查看文档
///<reference path="api.d.ts"/>
import * as path from 'path';
import { UglifyPlugin, IncrementCompilePlugin, CompilePlugin, ManifestPlugin, ExmlPlugin, EmitResConfigFilePlugin, TextureMergerPlugin } from 'built-in';
import { WxgamePlugin } from './wxgame/wxgame';
import { BricksPlugin } from './bricks/bricks';
import { CustomPlugin } from './myplugin';
const config: ResourceManagerConfig = {
buildConfig: (params) => {
const { target, command, projectName, version } = params;
if (command == 'build') {
const outputDir = '.';
return {
outputDir,
commands: [
// new EmitResConfigFilePlugin({
// output: "resource/default.res.json",
// typeSelector: config.typeSelector,
// nameSelector: p => path.basename(p).replace(/\./gi, "_"),
// groupSelector: p => "preload"
// }),
new ExmlPlugin('debug'), // 非 EUI 项目关闭此设置
new IncrementCompilePlugin(),
]
}
}
else if (command == 'publish') {
const outputDir = `bin-release/web/${version}`;
return {
outputDir,
commands: [
new CustomPlugin(),
new CompilePlugin({ libraryType: "release", defines: { DEBUG: false, RELEASE: true } }),
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
new UglifyPlugin([{
sources: ["main.js"],
target: "main.min.js"
}]),
new ManifestPlugin({ output: "manifest.json", hash: "crc32" })
]
}
}
else {
throw `unknown command : ${params.command}`
}
},
mergeSelector: (path) => {
if (path.indexOf("assets/bitmap/") >= 0) {
return "assets/bitmap/sheet.sheet"
}
else if (path.indexOf("armature") >= 0 && path.indexOf(".json") >= 0) {
return "assets/armature/1.zip";
}
},
typeSelector: (path) => {
const ext = path.substr(path.lastIndexOf(".") + 1);
const typeMap = {
"jpg": "image",
"png": "image",
"webp": "image",
"json": "json",
"fnt": "font",
"pvr": "pvr",
"mp3": "sound",
"zip": "zip",
"sheet": "sheet",
"exml": "text"
}
let type = typeMap[ext];
if (type == "json") {
if (path.indexOf("sheet") >= 0) {
type = "sheet";
} else if (path.indexOf("movieclip") >= 0) {
type = "movieclip";
};
}
return type;
}
}
export = config;
/// 阅读 api.d.ts 查看文档
///<reference path="api.d.ts"/>
import * as path from 'path';
import { UglifyPlugin, CompilePlugin, ManifestPlugin, ExmlPlugin, EmitResConfigFilePlugin, TextureMergerPlugin, CleanPlugin } from 'built-in';
import { WxgamePlugin } from './wxgame/wxgame';
import { CustomPlugin } from './myplugin';
import * as defaultConfig from './config';
const config: ResourceManagerConfig = {
buildConfig: (params) => {
const { target, command, projectName, version } = params;
const outputDir = `../${projectName}_wxgame`;
if (command == 'build') {
return {
outputDir,
commands: [
new CleanPlugin({ matchers: ["js", "resource"] }),
new CompilePlugin({ libraryType: "debug", defines: { DEBUG: true, RELEASE: false } }),
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
new WxgamePlugin(),
new ManifestPlugin({ output: 'manifest.js' })
]
}
}
else if (command == 'publish') {
return {
outputDir,
commands: [
new CleanPlugin({ matchers: ["js", "resource"] }),
new CompilePlugin({ libraryType: "release", defines: { DEBUG: false, RELEASE: true } }),
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
new WxgamePlugin(),
new UglifyPlugin([{
sources: ["main.js"],
target: "main.min.js"
}
]),
new ManifestPlugin({ output: 'manifest.js' })
]
}
}
else {
throw `unknown command : ${params.command}`;
}
},
mergeSelector: defaultConfig.mergeSelector,
typeSelector: defaultConfig.typeSelector
}
export = config;
/**
* 示例自定义插件,您可以查阅 http://developer.egret.com/cn/2d/projectConfig/cmdExtensionPluginin/
* 了解如何开发一个自定义插件
*/
export class CustomPlugin implements plugins.Command {
constructor() {
}
async onFile(file: plugins.File) {
return file;
}
async onFinish(commandContext: plugins.CommandContext) {
}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
"lib": [
"es5",
"es2015.promise"
], /* Specify library files to be included in the compilation: */
"allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
/* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}
\ No newline at end of file
import * as fs from 'fs';
import * as path from 'path';
export class WxgamePlugin implements plugins.Command {
constructor() {
}
async onFile(file: plugins.File) {
if (file.extname == '.js') {
const filename = file.origin;
if (filename == "libs/modules/promise/promise.js" || filename == 'libs/modules/promise/promise.min.js') {
return null;
}
if (filename == 'libs/modules/egret/egret.js' || filename == 'libs/modules/egret/egret.min.js') {
let content = file.contents.toString();
content += `;window.egret = egret;`;
content = content.replace(/definition = __global/, "definition = window");
file.contents = new Buffer(content);
}
else {
let content = file.contents.toString();
if (
filename == "libs/modules/res/res.js" ||
filename == 'libs/modules/res/res.min.js' ||
filename == 'libs/modules/assetsmanager/assetsmanager.min.js' ||
filename == 'libs/modules/assetsmanager/assetsmanager.js'
) {
content += ";window.RES = RES;"
}
if (filename == "libs/modules/eui/eui.js" || filename == 'libs/modules/eui/eui.min.js') {
content += ";window.eui = eui;"
}
if (filename == 'libs/modules/dragonBones/dragonBones.js' || filename == 'libs/modules/dragonBones/dragonBones.min.js') {
content += ';window.dragonBones = dragonBones';
}
content = "var egret = window.egret;" + content;
if (filename == 'main.js') {
content += ";window.Main = Main;"
}
file.contents = new Buffer(content);
}
}
return file;
}
async onFinish(pluginContext: plugins.CommandContext) {
//同步 index.html 配置到 game.js
const gameJSPath = path.join(pluginContext.outputDir, "game.js");
let gameJSContent = fs.readFileSync(gameJSPath, { encoding: "utf8" });
const projectConfig = pluginContext.buildConfig.projectConfig;
const optionStr =
`entryClassName: ${projectConfig.entryClassName},\n\t\t` +
`orientation: ${projectConfig.orientation},\n\t\t` +
`frameRate: ${projectConfig.frameRate},\n\t\t` +
`scaleMode: ${projectConfig.scaleMode},\n\t\t` +
`contentWidth: ${projectConfig.contentWidth},\n\t\t` +
`contentHeight: ${projectConfig.contentHeight},\n\t\t` +
`showFPS: ${projectConfig.showFPS},\n\t\t` +
`fpsStyles: ${projectConfig.fpsStyles},\n\t\t` +
`showLog: ${projectConfig.showLog},\n\t\t` +
`maxTouches: ${projectConfig.maxTouches},`;
const reg = /\/\/----auto option start----[\s\S]*\/\/----auto option end----/;
const replaceStr = '\/\/----auto option start----\n\t\t' + optionStr + '\n\t\t\/\/----auto option end----';
gameJSContent = gameJSContent.replace(reg, replaceStr);
fs.writeFileSync(gameJSPath, gameJSContent);
//修改横竖屏
let orientation;
if (projectConfig.orientation == '"landscape"') {
orientation = "landscape";
}
else {
orientation = "portrait";
}
const gameJSONPath = path.join(pluginContext.outputDir, "game.json");
let gameJSONContent = JSON.parse(fs.readFileSync(gameJSONPath, { encoding: "utf8" }));
gameJSONContent.deviceOrientation = orientation;
fs.writeFileSync(gameJSONPath, JSON.stringify(gameJSONContent, null, "\t"));
}
}
\ No newline at end of file
//////////////////////////////////////////////////////////////////////////////////////
//
// 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}`;
}
}
//////////////////////////////////////////////////////////////////////////////////////
//
// 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 egret.DisplayObjectContainer {
public constructor() {
super();
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
}
private onAddToStage(event: egret.Event) {
egret.lifecycle.addLifecycleListener((context) => {
// custom lifecycle plugin
context.onUpdate = () => {
}
})
egret.lifecycle.onPause = () => {
egret.ticker.pause();
}
egret.lifecycle.onResume = () => {
egret.ticker.resume();
}
this.runGame().catch(e => {
console.log(e);
})
}
private async runGame() {
await this.loadResource()
this.createGameScene();
const result = await RES.getResAsync("description_json")
this.startAnimation(result);
await platform.login();
const userInfo = await platform.getUserInfo();
console.log(userInfo);
}
private async loadResource() {
try {
const loadingView = new LoadingUI();
this.stage.addChild(loadingView);
await RES.loadConfig("resource/default.res.json", "resource/");
await RES.loadGroup("preload", 0, loadingView);
this.stage.removeChild(loadingView);
}
catch (e) {
console.error(e);
}
}
private textfield: egret.TextField;
/**
* 创建游戏场景
* Create a game scene
*/
private createGameScene() {
let sky = this.createBitmapByName("bg_jpg");
this.addChild(sky);
let stageW = this.stage.stageWidth;
let stageH = this.stage.stageHeight;
sky.width = stageW;
sky.height = stageH;
let topMask = new egret.Shape();
topMask.graphics.beginFill(0x000000, 0.5);
topMask.graphics.drawRect(0, 0, stageW, 172);
topMask.graphics.endFill();
topMask.y = 33;
this.addChild(topMask);
let icon = this.createBitmapByName("egret_icon_png");
this.addChild(icon);
icon.x = 26;
icon.y = 33;
let line = new egret.Shape();
line.graphics.lineStyle(2, 0xffffff);
line.graphics.moveTo(0, 0);
line.graphics.lineTo(0, 117);
line.graphics.endFill();
line.x = 172;
line.y = 61;
this.addChild(line);
let colorLabel = new egret.TextField();
colorLabel.textColor = 0xffffff;
colorLabel.width = stageW - 172;
colorLabel.textAlign = "center";
colorLabel.text = "Hello Egret";
colorLabel.size = 24;
colorLabel.x = 172;
colorLabel.y = 80;
this.addChild(colorLabel);
let textfield = new egret.TextField();
this.addChild(textfield);
textfield.alpha = 0;
textfield.width = stageW - 172;
textfield.textAlign = egret.HorizontalAlign.CENTER;
textfield.size = 24;
textfield.textColor = 0xffffff;
textfield.x = 172;
textfield.y = 135;
this.textfield = textfield;
}
/**
* 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
* Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
*/
private createBitmapByName(name: string) {
let result = new egret.Bitmap();
let texture: egret.Texture = RES.getRes(name);
result.texture = texture;
return result;
}
/**
* 描述文件加载成功,开始播放动画
* Description file loading is successful, start to play the animation
*/
private startAnimation(result: string[]) {
let parser = new egret.HtmlTextParser();
let textflowArr = result.map(text => parser.parse(text));
let textfield = this.textfield;
let count = -1;
let change = () => {
count++;
if (count >= textflowArr.length) {
count = 0;
}
let textFlow = textflowArr[count];
// 切换描述内容
// Switch to described content
textfield.textFlow = textFlow;
let tw = egret.Tween.get(textfield);
tw.to({ "alpha": 1 }, 200);
tw.wait(2000);
tw.to({ "alpha": 0 }, 200);
tw.call(change, this);
};
change();
}
}
\ No newline at end of file
/**
* 平台数据接口。
* 由于每款游戏通常需要发布到多个平台上,所以提取出一个统一的接口用于开发者获取平台数据信息
* 推荐开发者通过这种方式封装平台逻辑,以保证整体结构的稳定
* 由于不同平台的接口形式各有不同,白鹭推荐开发者将所有接口封装为基于 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
}
require("launcher/native_require.js");
egret_native.egtMain = function () {
egret_native.nativeType = "native";
egret_native.egretInit();
egret_native.egretStart();
};
var manifest = JSON.parse(egret_native.readFileSync("manifest.json"));
var game_file_list = manifest.initial.concat(manifest.game);
var window = this;
egret_native.setSearchPaths([""]);
egret_native.requireFiles = function () {
for (var key in game_file_list) {
var src = game_file_list[key];
require(src);
}
};
egret_native.egretInit = function () {
if(egret_native.featureEnable) {
//控制一些优化方案是否开启
//Control whether some optimization options are open
var result = egret_native.featureEnable({
});
}
egret_native.requireFiles();
egret.dom = {};
egret.dom.drawAsCanvas = function () {
};
};
egret_native.egretStart = function () {
var option = {
//以下为自动修改,请勿修改
//The following is automatically modified, please do not modify
//----auto option start----
//----auto option end----
};
egret.native.NativePlayer.option = option;
egret.runEgret();
egret_native.Label.createLabel("/system/fonts/DroidSansFallback.ttf", 20, "", 0);
egret_native.EGTView.preSetOffScreenBufferEnable(true);
};
\ No newline at end of file
require("launcher/native_require.js");
egret_native.egtMain = function () {
egret_native.nativeType = "runtime";
egret_native.egretInit();
egret_native.egretStart();
};
\ No newline at end of file
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Egret</title>
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="full-screen" content="true" />
<meta name="screen-orientation" content="portrait" />
<meta name="x5-fullscreen" content="true" />
<meta name="360-fullscreen" content="true" />
<style>
html, body {
-ms-touch-action: none;
background: #888888;
padding: 0;
border: 0;
margin: 0;
height: 100%;
}
</style>
</head>
<body>
<div style="margin: auto;width: 100%;height: 100%;" class="egret-player"
data-entry-class="Main"
data-orientation="landscape"
data-scale-mode="fixedWidth"
data-frame-rate="30"
data-content-width="640"
data-content-height="1136"
data-show-paint-rect="false"
data-multi-fingered="2"
data-show-fps="false" data-show-log="false"
data-show-fps-style="x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9">
</div>
<script>
var loadScript = function (list, callback) {
var loaded = 0;
var loadNext = function () {
loadSingleScript(list[loaded], function () {
loaded++;
if (loaded >= list.length) {
callback();
}
else {
loadNext();
}
})
};
loadNext();
};
var loadSingleScript = function (src, callback) {
var s = document.createElement('script');
s.async = false;
s.src = src;
s.addEventListener('load', function () {
s.parentNode.removeChild(s);
s.removeEventListener('load', arguments.callee, false);
callback();
}, false);
document.body.appendChild(s);
};
var xhr = new XMLHttpRequest();
xhr.open('GET', './manifest.json?v=' + Math.random(), true);
xhr.addEventListener("load", function () {
var manifest = JSON.parse(xhr.response);
var list = manifest.initial.concat(manifest.game);
loadScript(list, function () {
/**
* {
* "renderMode":, //Engine rendering mode, "canvas" or "webgl"
* "audioType": 0 //Use the audio type, 0: default, 2: web audio, 3: audio
* "antialias": //Whether the anti-aliasing is enabled in WebGL mode, true: on, false: off, defaults to false
* "calculateCanvasScaleFactor": //a function return canvas scale factor
* }
**/
egret.runEgret({ renderMode: "webgl", audioType: 0, calculateCanvasScaleFactor:function(context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}});
});
});
xhr.send(null);
</script>
</body>
</html>
\ No newline at end of file
{
"compilerOptions": {
"target": "es5",
"outDir": "bin-debug",
"experimentalDecorators": true,
"lib": [
"es5",
"dom",
"es2015.promise"
],
"types": []
},
"include": [
"src",
"libs"
]
}
\ No newline at end of file
{
"resourcePlugin":{
"configs":[{
"configPath":"resource/default.res.json",
"relativePath":"resource/"
}]
},
"theme":"resource/default.thm.json"
}
\ No newline at end of file
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