Commit 5a93cefd authored by haiyoucuv's avatar haiyoucuv

1

parents
Pipeline #257427 failed with stages
in 0 seconds
# project ignores
node_modules
./released
.DS_Store
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/qiaqia_qx.iml" filepath="$PROJECT_DIR$/.idea/qiaqia_qx.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PropertiesComponent">
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="editor.preferences.fonts.default" />
</component>
</project>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</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" />
<!-- <meta name="viewport" content="width=device-width,minimum-scale=1.0,user-scalable=no"> -->
<!-- <script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> -->
<!-- 小程序分享得用这个 -->
<!-- <script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script> -->
<!-- 易盾js -->
<!-- <script type="text/javascript" src="//cstaticdun.126.net/load.min.js"></script> -->
<!-- <script src="libs/zepto.min.js"></script> -->
<!-- <script src="libs/p2.js"></script> -->
<script src="libs/fyge.min.js"></script>
<script src="libs/svgaParser.min.js"></script>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: #000000;
}
</style>
</head>
<body>
<script src="output.js"></script>
<!-- <div id="__loading__" style="position:absolute;left:50%;top:50%;margin-left:-45px;color:#ffffff">拼命加载中...</div> -->
<!-- <img src="" id="img" /> -->
<div id="cusEngine" style="line-height:0;font-size:0">
<canvas id="canvas" style="width: 100%;height: 100%"></canvas>
</div>
</body>
<!-- 帧率检测 -->
<!-- <script src="libs/stats.js"></script> -->
<script>
window.addEventListener("load", function () {
//获取canvas
var canvas = document.getElementById("canvas");
canvas.width = document.body.clientWidth * (window.devicePixelRatio || 1)
canvas.height = document.body.clientHeight * (window.devicePixelRatio || 1)
var main = new Main(canvas);
console.log(main.stage)
var mouseEvent = main.stage.onMouseEvent.bind(main.stage);
canvas.addEventListener("touchstart", mouseEvent, false);
canvas.addEventListener('touchmove', mouseEvent, false);
canvas.addEventListener('touchend', mouseEvent, false);
})
</script>
</html>
\ No newline at end of file
import { Main } from './Main';
Page({
//暂时先不用吧,有问题
data: {
},
onLoad(query) {
// 页面加载
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
},
onReady() {
return
my.development = true;
// my._createCanvas({
// id: 'canvas',
// success: (ccc) => {
// const dpr = my.getSystemInfoSync().pixelRatio
// const windowWidth = my.getSystemInfoSync().windowWidth;
// const windowHeight = my.getSystemInfoSync().windowHeight;
// ccc.width = windowWidth * dpr;
// ccc.height = windowHeight * dpr;
// // const context = canvas.getContext("2d");
// console.log(ccc.width, ccc.height, dpr)
// //初始化
// FYGE.initedByCanvas(ccc);
// //测试
// var aa = ccc.createImage();
// aa.src = "https://yun.duiba.com.cn/db_games/activity/etc/optionImages/%E5%8D%8E%E4%B8%BAP30.jpg";
// console.log(aa)
// //帧率控制
// FYGE.Stage.addFPS("canva4stats")
// this.main = new Main(ccc)
// console.log(ccc.width, ccc.height)
// }
// })
},
onCanvasReady() {
my.development = true;
my._createCanvas({
id: 'canvas',
success: (ccc) => {
const dpr = my.getSystemInfoSync().pixelRatio
const windowWidth = my.getSystemInfoSync().windowWidth;
const windowHeight = my.getSystemInfoSync().windowHeight;
ccc.width = windowWidth * dpr;
ccc.height = windowHeight * dpr;
this.main = new Main(ccc)
}
})
},
onShow() {
// 页面显示
// FYGE.Stage.pause = false
if (this.main) this.main.run();
},
onHide() {
// 页面隐藏
// FYGE.Stage.pause = true
if (this.main) this.main.pause();
},
onUnload() {
// 页面被关闭
// Stage.stop()
this.main.destroy();
},
onTitleClick() {
// 标题被点击
},
onPullDownRefresh() {
// 页面被下拉
},
onReachBottom() {
// 页面被拉到底部
},
onShareAppMessage() {
// 返回自定义分享信息
return {
title: 'My App',
desc: 'My App description',
path: 'pages/index/index',
};
},
log(e) {
if (this.main) this.main.stage.onMouseEvent(e)
},
});
This source diff could not be displayed because it is too large. You can view the blob instead.
declare module SvgaParser {
/**
* 加载方法
* @param url 资源路径
* @param success
* @param failure
*/
export function loadSvga(url: string, success: (videoItem: VideoEntity) => void, failure?: (err: string) => void): void;
/**
* 导出只是当作类型接口用
*/
export interface VideoEntity {
/**
* SVGA 文件版本
*/
version: string;
/**
* 影片尺寸
*/
videoSize: {
width: number;
height: number;
};
/**
* 帧率,60,30等每秒
*/
FPS: number;
/**
* 总帧数
*/
frames: number;
/**
* base64图片数据记录
*/
images: {
[key: string]: string
};
/**
* 图片是否已被缓存,缓存全局,注意名字覆盖
*/
hasBeenCached: boolean;
/**
* sprite对象数据
*/
sprites: SpriteEntity[];
}
interface SpriteEntity {
/**
* 标识
*/
matteKey: string;
/**
* 图片key值
*/
imageKey: string;
/**
* 帧数据数组
*/
frames: FrameEntity[];
}
/**
* 还有很多其他数据,暂不需要,比如矢量路径和遮罩路径暂时都无
*/
interface FrameEntity {
/**
* 透明度
*/
alpha: number;
/**
* 2维矩阵数据
*/
transform: {
a: number,
b: number,
c: number,
d: number,
tx: number,
ty: number,
};
}
}
declare module "svga-parser" { export = SvgaParser; }
\ 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.
var Stats = function () {
var startTime = Date.now(), prevTime = startTime;
var ms = 0, msMin = Infinity, msMax = 0;
var fps = 0, fpsMin = Infinity, fpsMax = 0;
var frames = 0, mode = 0;
var container = document.createElement('div');
container.id = 'stats';
container.addEventListener('mousedown', function (event) { event.preventDefault(); setMode(++mode % 2) }, false);
container.style.cssText = 'width:80px;opacity:0.9;cursor:pointer';
var fpsDiv = document.createElement('div');
fpsDiv.id = 'fps';
fpsDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#002';
container.appendChild(fpsDiv);
var fpsText = document.createElement('div');
fpsText.id = 'fpsText';
fpsText.style.cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';
fpsText.innerHTML = 'FPS';
fpsDiv.appendChild(fpsText);
var fpsGraph = document.createElement('div');
fpsGraph.id = 'fpsGraph';
fpsGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0ff';
fpsDiv.appendChild(fpsGraph);
while (fpsGraph.children.length < 74) {
var bar = document.createElement('span');
bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#113';
fpsGraph.appendChild(bar);
}
var msDiv = document.createElement('div');
msDiv.id = 'ms';
msDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none';
container.appendChild(msDiv);
var msText = document.createElement('div');
msText.id = 'msText';
msText.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';
msText.innerHTML = 'MS';
msDiv.appendChild(msText);
var msGraph = document.createElement('div');
msGraph.id = 'msGraph';
msGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0f0';
msDiv.appendChild(msGraph);
while (msGraph.children.length < 74) {
var bar = document.createElement('span');
bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#131';
msGraph.appendChild(bar);
}
var setMode = function (value) {
mode = value;
switch (mode) {
case 0:
fpsDiv.style.display = 'block';
msDiv.style.display = 'none';
break;
case 1:
fpsDiv.style.display = 'none';
msDiv.style.display = 'block';
break;
}
}
var updateGraph = function (dom, value) {
var child = dom.appendChild(dom.firstChild);
child.style.height = value + 'px';
}
return {
REVISION: 11,
domElement: container,
setMode: setMode,
begin: function () {
startTime = Date.now();
},
end: function () {
var time = Date.now();
ms = time - startTime;
msMin = Math.min(msMin, ms);
msMax = Math.max(msMax, ms);
msText.textContent = ms + ' MS (' + msMin + '-' + msMax + ')';
updateGraph(msGraph, Math.min(30, 30 - (ms / 200) * 30));
frames++;
if (time > prevTime + 1000) {
fps = Math.round((frames * 1000) / (time - prevTime));
fpsMin = Math.min(fpsMin, fps);
fpsMax = Math.max(fpsMax, fps);
fpsText.textContent = fps + ' FPS (' + fpsMin + '-' + fpsMax + ')';
updateGraph(fpsGraph, Math.min(30, 30 - (fps / 100) * 30));
prevTime = time;
frames = 0;
}
return time;
},
update: function () {
startTime = this.end();
}
}
};
//执行
var stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
document.body.appendChild(stats.domElement);
aa();
function aa() {
stats.update();
requestAnimationFrame(aa)
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
const path = require('path');
const config = {
'/ngame/new/datapash': {
data: './json/datapash.json'
}
}
for (let item in config) {
if (config.hasOwnProperty(item))
config[item].path = path.resolve(__dirname, config[item].data);
}
module.exports = config;
\ No newline at end of file
{
"success": true,
"code": "1111",
"data": {}
}
\ No newline at end of file
interface ResData {
/**
* 分组数据
*/
groups: GroupInt[];
//暂时没有工具,不用
resources?: any;
path?: string;
}
interface GroupInt {
/**
* 所有的资源名字,根据,分割,根据后缀区分类型
*
*/
keys: string;//"aa.png,bb.jpg,name.json"
/**
* 文件夹名字吧
*/
name: string;
/**
* 图集
* 线上打包合图可能有多张,暂时发现texturePacker版本问题只有一张
*/
atlas: {
[name: string]: {
"x": number,
"y": number,
"w": number,
"h": number,
"ox": number,
"oy": number,
"sw": number,
"sh": number,
"ro": boolean
},
};
}
/**
* 简单点,有工具的话像egret那样玩,可以自动生成图片组数据
*/
export namespace RES {
let resData: ResData
/**
* 资源路径
*/
export let resPath: string;
/**
* movieClip的ve数据
*/
let videoEntityHash: {
// [name: string]: FYGE.VideoEntity
} = {};
/**
* 音频的加载
*/
let soundHash = {}
/**
* 记录组加载完成
*/
let groupsCompleteHash: {
[name: string]: boolean
} = {}
/**
* 记录加载的promise
*/
let groupsPromiseHash: {
[name: string]: Promise<any>
} = {}
/**
* 单独资源加载的promise记录
*/
let singleResPromiseHash: {
[name: string]: Promise<any>
} = {}
/**
*
* @param res 资源数据,就是对象,不考虑加载json先
* res格式{
* path:1111/
* groups: [
* {
*
* }
* ];
* }
* @param path
*/
export function loadConfig(res) {
resData = res;
resPath = res.path;
}
/**
* 根据组名加载一组资源,通常用于加载一个视图的的所有资源
* 里的promise的resolve并没有返回值
* @param name
*/
export function loadGroup(name: string): Promise<any> {
//已经加载完成的直接返回
if (groupsCompleteHash[name]) {
return new Promise((resolve) => {
resolve()
})
}
//如果是正在加载中的,返回正在加载中的promise
if (groupsPromiseHash[name]) {
return groupsPromiseHash[name];
}
//如果首次加载
//获取资源组
let arr = getGroupResByName(name);
//如果不存在arr,直接返回空p,且标记完成
if (!arr || !arr.length) {
groupsCompleteHash[name] = true;
return new Promise((resolve) => {
resolve()
})
}
// 建一个promise
let p = new Promise((resolve, reject) => {
loadResList((s) => {
//移除
delete groupsPromiseHash[name];
if (s) {
groupsCompleteHash[name] = true;
resolve()
} else {
reject();
}
}, arr/*, resPath + name*/)
})
groupsPromiseHash[name] = p;
return p;
}
/**
* var textue = await RES.getResAsync(str);
* @param str 可以是网络图片路径或键值
* @param comFun 加载回调
* @param thisObj this指向
*/
export function getResAsync(str: string, comFun?: (res: any, str: string) => void, thisObj?: any): Promise<any> {
// var arr = str.split(".");
var type = str.substring(str.lastIndexOf(".") + 1, str.length);
//如果是图片
if (type == "png" || type == "jpg") {
//原先就有了,加载过的,且已加载完成的
if (FYGE.TextureCache[str]) {
//回调形式
comFun && comFun.call(thisObj, FYGE.TextureCache[str], str)
// return FYGE.TextureCache[str];
new Promise((r) => {
r(FYGE.TextureCache[str])
})
}
//未加载完成的
else if (singleResPromiseHash[str]) {
return returnSingleResPromise(str, comFun, thisObj)
}
else {
//判断是否在资源里,判断是否要加载图集,注意已排除jpg
var groupName = hasRes(str);
if (groupName && type != "jpg") {
var group = getGroupByName(groupName);
if (group && group.atlas) {
//加载图集,现在就一张,以后有机会改
var json = groupName + ".json"//group.atlas.split(",")[0];
//找json是否在加载中
if (singleResPromiseHash[json]) {
return singleResPromiseHash[json].then(
(r) => {
//只返回需要的
comFun && comFun.call(thisObj, FYGE.TextureCache[str], str)
return FYGE.TextureCache[str]
},
() => {
comFun && comFun.call(thisObj, null, str)
return null
}
)
} else {
return getResAsync(json)
.then(() => {
comFun && comFun.call(thisObj, FYGE.TextureCache[str], str)
return FYGE.TextureCache[str]
}, () => {
comFun && comFun.call(thisObj, null, str)
return null
})
}
}
}
var src = groupName ? resPath + groupName + "/" + str : str;
var p = new Promise((resolve, reject) => {
FYGE.GlobalLoader.loadImage((s, image) => {
//移除
delete singleResPromiseHash[str];
//入缓存
if (s) {
//@ts-ignore
FYGE.Texture.addToCache(FYGE.Texture.from(image), str);
comFun && comFun.call(thisObj, FYGE.TextureCache[str], str)
resolve(FYGE.TextureCache[str])
} else {
comFun && comFun.call(thisObj, null, str)
reject()
}
}, src)
})
singleResPromiseHash[str] = p
return p
}
}
else if (type == "svga") {
if (videoEntityHash[str]) {
comFun && comFun.call(thisObj, videoEntityHash[str], str)
return new Promise((r) => {
r(videoEntityHash[str])
})
}
//未加载完成的
else if (singleResPromiseHash[str]) {
return returnSingleResPromise(str, comFun, thisObj)
} else {
var groupName = hasRes(str);
var src = groupName ? resPath + groupName + "/" + str : str;
var p = new Promise((resolve, reject) => {
//@ts-ignore //以后要加
FYGE.GlobalLoader.loadSvga((s, v) => {
//移除
delete singleResPromiseHash[str];
//入缓存
if (s) {
if (s) videoEntityHash[str] = v;
comFun && comFun.call(thisObj, v, str)
resolve(v)
} else {
comFun && comFun.call(thisObj, null, str)
reject()
}
}, src)
})
singleResPromiseHash[str] = p;
return p
}
}
//json图集的话,不晓得用啥判断加载完成,所以不删除promise吧,其实json可能只是数据,不管先
else if (type == "json") {
if (singleResPromiseHash[str]) {
return returnSingleResPromise(str, comFun, thisObj)
} else {
var groupName = hasRes(str);//json现在肯定在内,暂时不能加载其他域名的json
var src = groupName ? resPath + groupName + "/" + str : str;
var p = new Promise((resolve, reject) => {
var jsonData = getGroupByName(groupName).atlas
FYGE.GlobalLoader.loadImage((s, data) => {
if (s) {
var t = FYGE.createTextureSheet(new FYGE.BaseTexture(data/*.img*/), jsonData)
comFun && comFun.call(thisObj, t, str)
resolve(t)
} else {
comFun && comFun.call(thisObj, null, str)
reject()
}
}, src.replace("json", "png"))
})
singleResPromiseHash[str] = p
return p
}
}
}
/**
* 待写,根据网络路径加载图片
*/
export function getResByUrl() {
}
/**
* 获取素材,
* @param str
* @return 已加载好得素材或null
*/
export function getRes(str: string)/*: Texture | VideoEntity*/ {
var type = str.substring(str.lastIndexOf(".") + 1, str.length);
if (type == "png" || type == "jpg") {
return FYGE.TextureCache[str] || null;
}
else if (type == "svga") {
return videoEntityHash[str] || null;
}
else if (type == "mp3") {
return soundHash[str] || null;
}
}
/**
* 判断是否在资源组里
* 考虑是否init就做表
* 有就返回组名,为了加载路径,不然以后有工具可以放入resources
*/
function hasRes(str: string): string {
for (var i = 0; i < resData.groups.length; i++) {
var group = resData.groups[i];
var keys = group.keys;
if (keys && keys.split(",").indexOf(str) > -1) {
return group.name;
}
//如果是图集的json,altas现在是图集
if (group.atlas && group.name + ".json" == str) {
return group.name;
}
}
return null
}
/**
* 处理数据,获得所有资源单项
* @param name
*/
function getGroupResByName(name: string) {
var group: GroupInt = getGroupByName(name);
if (!group) return null;
//判断加载图集还是单图
if (group.atlas) {
// var arr: string[] = [].concat(group.atlas.split(","));
var arr = [name + ".json"]
//再添加非图片的资源,和图集已排除jpg
if (group.keys) {
arr = arr.concat(group.keys.split(",").filter((k: string) => {
return k.substr(-4) != ".png" //&& k.substr(-4) != ".jpg"
}))
}
return arr
}
else if (group.keys) {
return group.keys.split(",")
} else {
return null
}
}
/**
* 根据名字找组
* @param name
*/
function getGroupByName(name: string): GroupInt {
var groups = resData.groups;
var group: GroupInt;
for (var i = 0; i < groups.length; i++) {
if (groups[i].name === name) {
group = groups[i];
break;
}
}
return group
}
/**
* 新版的加载一列资源
* @param callback
* @param arr
*/
function loadResList(callback: (allLoaded: boolean) => void, arr: string[]) {
let count = 0;
let countAll = arr.length;
if (!countAll) callback(true);
let mark = true;
for (var i = 0; i < countAll; i++) {
let resName = arr[i];
getResAsync(resName, (res, str) => {
//标记失败,如果有一项资源加载失败,标记下
if (!res) mark = false
if (++count == countAll) callback(mark);
}, this)
}
}
/**
*
* @param str
* @param comFun
* @param thisObj
*/
function returnSingleResPromise(str: string, comFun?: (res: any, str: string) => void, thisObj?: any) {
//已判断是否存在
singleResPromiseHash[str].then(
(r) => {
comFun && comFun.call(thisObj, r, str)
},
() => {
comFun && comFun.call(thisObj, null, str)
}
)
return singleResPromiseHash[str];
}
//貌似不需要,为了加载过一次的资源不用重新加载
function destroyRES() {
}
}
import { destroyWaiting } from "./waitingCtrl";
import { Panel } from "../views/Panel";
import PanelCtrl from "./panelCtrl";
import SceneCtrl from "./sceneCtrl";
import { Scene } from "../views/Scene";
import { destroyToast } from "./toastCtrl";
export { showToast } from "./toastCtrl";
export * from "./waitingCtrl";
/**
* 展示弹框
* @param panel 弹框类
* @param data 数据
*/
export const showPanel = (panel: any, data?: any) => {
PanelCtrl.instance.show(panel, data)
}
/**
* 关闭所有弹框
*/
export const closeAllPanels = () => {
PanelCtrl.instance.closeAll();
}
/**
* 关闭当前弹框
*/
export const closeCurrentPanel = () => {
PanelCtrl.instance.closeCurrent();
}
/**
* 替换场景
* @param scene
* @param data
*/
export const changeScene = (scene: any, data?: any) => {
SceneCtrl.instance.change(scene, data)
}
/**
* 获取当前场景
*/
export function getCurrentScene(): any {
return SceneCtrl.instance.currentScene
}
/**
* 淘宝小程序的alert
* @param {string} title
* @param {string} content
*/
export const showAlert = (title?: string, content?: string) => {
//@ts-ignore
if (my) {
//@ts-ignore
my.alert({
title: title || "",
content: content || ""
});
} else {
console.log(title, content)
}
}
/**
* 替换setTimeout 因为页面销毁时setTimeout不会停
* 所以干脆用Tween的
* @param {Function} callback
* @param {number} time 毫秒计
*/
export function wait(callback: () => void, time: number): {} {
let obj = {};
FYGE.Tween.get(obj)
.wait(time)
.call(callback)
return obj
}
export function clearWait(obj: {}) {
FYGE.Tween.removeTweens(obj);
}
/**
* 销毁方法
*/
export function destroyAllCtrls() {
destroyToast();
destroyWaiting();
PanelCtrl.instance.destroy();
SceneCtrl.instance.destroy();
}
\ No newline at end of file
import { Panel } from "../views/Panel";
import { layers } from "../views/layers";
import { showWaiting, hideWaiting } from "./waitingCtrl";
import { showToast } from "./toastCtrl";
export default class PanelCtrl {
/**
* 父级容器
*/
private _parent: FYGE.Container;
/**
* 半透明黑色背景
*/
private _bg: FYGE.Graphics;
/**
* 所有的弹框
*/
private stacks: Panel[] = [];
private static _instance: PanelCtrl;
static get instance() {
return PanelCtrl._instance || (PanelCtrl._instance = new PanelCtrl())
}
init(parent: FYGE.Container) {
this._parent = parent;
let bg = new FYGE.Graphics();
bg.beginFill(0, 1);
bg.drawRect(//引用适配
layers.stageOffsetX - parent.x,
layers.stageOffsetY - parent.y,
layers.stageWidth,
layers.stageHeight
);
bg.endFill();
bg.visible = false;
this._parent.addChild(bg);
this._bg = bg;
}
/**
* 关闭所有弹框
*/
closeAll() {
this.stacks.forEach(e => e.hidePanel());
}
show<T extends Panel>(cls: any, data?: any): T {
showWaiting()
const panel: T = new cls(data);
this.add(panel);
this.stacks.push(panel);
panel.onLoaded = () => {
hideWaiting();
this.updateView();
//start只执行一边
panel.start(data);
}
//资源加载失败时
panel.onLoadError = () => {
hideWaiting();
showToast("资源加载失败")
panel.removeEventListener('onDestroy', this.onPanelHide, this);
this.remove(panel);
}
return panel;
}
private updateView() {
if (!this.stacks.length) {
this._bg.visible = false;
this._current = null;
this._parent.visible = false;
} else {
//显示弹框层
this._parent.visible = true;
//如果首次出现弹框,加个动画
if (this._bg.visible === false) {
this._bg.visible = true;
this._bg.alpha = 0;
FYGE.Tween.removeTweens(this._bg);
FYGE.Tween.get(this._bg).to({ alpha: 0.7 }, 200, FYGE.Ease.cubicOut)
}
}
for (let i = 0; i < this.stacks.length; i++) {
if (i < this.stacks.length - 1) {
this.stacks[i].visible = false;
} else {
this.stacks[i].visible = true;
this.stacks[i].showAni();
this._current = this.stacks[i];
}
}
}
/**
* 添加进父级并添加事件
* @param panel
*/
private add(panel: Panel) {
this._parent.addChild(panel);
panel.addEventListener('onDestroy', this.onPanelHide, this);
}
/**
* 移除
* @param panel
*/
private remove(panel: Panel) {
this._parent.removeChild(panel);
this.stacks = this.stacks.filter(e => e != panel);
}
/**
* 弹框移除时执行
* @param e
*/
private onPanelHide(e: FYGE.Event) {
const panel = e.target as Panel;
panel.removeEventListener('onDestroy', this.onPanelHide, this);
this.remove(panel);
this.updateView();
}
//当前弹框
private _current: Panel;
/**
* 关闭当前弹框
*/
closeCurrent() {
if (this._current) {
this._current.hidePanel();
// this._current.removeEventListener('onDestroy', this.onPanelHide, this);
// this.remove(this._current);
// this.updateView();
}
}
destroy() {
PanelCtrl._instance = null;
this.stacks = null;
this._current = null;
this._parent = null;
this._bg.destroy();
this._bg = null;
}
}
\ No newline at end of file
import { Scene } from "../views/Scene";
import { showWaiting, hideWaiting } from "./waitingCtrl";
import { showToast } from "./toastCtrl";
export default class SceneCtrl {
private _parent: FYGE.Container;
private _currentScene: Scene;
private static _instance: SceneCtrl;
static get instance() {
return SceneCtrl._instance || (SceneCtrl._instance = new SceneCtrl())
}
init(parent: FYGE.Container) {
this._parent = parent;
}
change(cls: any, data?: any) {
//如果是同一个场景,考虑是替换还是return
if (this._currentScene && this._currentScene instanceof cls) return;
let scene: Scene = new cls(data);
scene.visible = false;
showWaiting();
let preScene: Scene = this._currentScene;
scene.onLoaded = () => {
hideWaiting();
scene.showAni(() => {
if (preScene) preScene.destroy();
})
scene.visible = true;
//start里可能处理资源信息,所以在onLoaded后执行
scene.start();
}
//加载失败,继续用之前的场景,移除scene
scene.onLoadError = () => {
hideWaiting();
showToast("资源加载失败")
this._currentScene = preScene || null;
this._parent.removeChild(scene);
}
this._currentScene = scene;
this._parent.addChild(scene);
}
get currentScene() {
return this._currentScene
}
destroy() {
SceneCtrl._instance = null;
this._currentScene = null;
this._parent = null;
}
}
\ No newline at end of file
import { layers } from "../views/layers";
import { RES } from "../RES";
let inited = false;
let _toast: Toast;
let _parent: FYGE.Container;
let startY: number
let endY: number
const initToast = () => {
if (!inited) {
inited = true;
_toast = new Toast();
_parent = layers.toastLayer;
_toast.alpha = 0;
_toast.x = layers.stageOffsetX - _parent.x + (layers.stageWidth - _toast.width) / 2;
var h = _toast.height;
var y = layers.stageOffsetY - _parent.y;
startY = y - h;
endY = y + (layers.stageHeight - h) / 2;
}
}
export const showToast = (msg: string) => {
initToast();
_toast.show(msg)
_parent.addChild(_toast);
FYGE.Tween.removeTweens(_toast);
FYGE.Tween.get(_toast)//动画看需求
.set({ y: startY, alpha: 1 })
.to({ y: endY }, 500, FYGE.Ease.quartOut)
.wait(800)
.to({ alpha: 0 }, 300)
.call(() => {
_parent.removeChild(_toast);
})
}
/**
* 对于之前淘宝小程序遇到的问题,需要销毁,否则会出问题
*/
export const destroyToast = () => {
if (inited && _toast && !_toast.destroyed) {
_toast.destroy();
_toast = null;
_parent = null;
inited = false;
}
}
/**
* toast类,不对外导出,适配居中有问题,有时间改
* 自身居中,
*/
class Toast extends FYGE.Container {
msg: FYGE.TextField;
bg: FYGE.Sprite;
PADDING = 40;
constructor() {
super();
this.mouseChildren = false;
this.mouseEnable = false;
var toastBgTexture: FYGE.Texture = RES.getRes("toastBg.png");
this.bg = new FYGE.Sprite(toastBgTexture);
// this.bg.x = (750 - 460) / 2// (layers.stageWidth - this.bg.width) / 2
this.addChild(this.bg);
this.msg = new FYGE.TextField();
this.msg.size = 28;
this.msg.fillColor = "0xffffff";
this.msg.text = "";
this.msg.verticalAlign = FYGE.VERTICAL_ALIGN.MIDDLE;
this.msg.textHeight = toastBgTexture.height;
this.msg.textAlign = FYGE.TEXT_ALIGN.CENTER;
this.addChild(this.msg)
}
/**
* 显示时调用
* @param msg
*/
show(msg: string) {
this.msg.text = msg;
//文本居中适配
this.msg.x = (this.bg.width - this.msg.textWidth) / 2//(layers.stageWidth - this.msg.textWidth) / 2;
//是否需要根据文本宽度缩放背景
// this.bg.width = Math.min(this.msg.textWidth + this.PADDING * 2, 523);
//背景居中适配,由于上面一行注释,那这行就构造函数里只执行一次吧
// this.bg.x = (layers.stageWidth - this.bg.width) / 2
}
destroy() {
super.destroy();
this.msg = null
this.bg = null;
}
}
\ No newline at end of file
import { RES } from "../RES";
import { layers } from "../views/layers";
import { showAlert } from ".";
let inited = false;
let _waiting: Waiting;
let _parent: FYGE.Container
const initWaiting = () => {
if (!inited) {
inited = true;
const waiting = new Waiting();
_parent = layers.topLayer;
_waiting = waiting;
//居中偏移
var offX = (layers.stageWidth - 160/*_waiting.width*/) / 2;
var offY = (layers.stageHeight - _waiting.height) / 2;
//位置适配
_waiting.x = layers.stageOffsetX - _parent.x + offX;
_waiting.y = layers.stageOffsetY - _parent.y + offY;
//阻止事件用
var bg: FYGE.Graphics = new FYGE.Graphics()
.beginFill(0x000000)
.drawRect(-offX, -offY, layers.stageWidth, layers.stageHeight)
.endFill();
bg.alpha = 0;
_waiting.addChildAt(bg, 0);
}
}
/**
* 显示菊花圈
* @param msg 尽量三个字
*/
export const showWaiting = (msg?: string) => {
initWaiting();
_waiting.show(msg)
_parent.addChild(_waiting);
}
/**
* 隐藏菊花圈
*/
export const hideWaiting = () => {
_parent.removeChild(_waiting);
}
export const destroyWaiting = () => {
if (inited && _waiting && !_waiting.destroyed) {
_waiting.destroy();
_waiting = null;
_parent = null;
inited = false;
}
}
/**
* 菊花圈,有机会重写,应该适应所有场景居中
*/
class Waiting extends FYGE.Container {
msg: FYGE.TextField;
constructor() {
super();
//圆角矩形背景
var rectBgTexture: FYGE.Texture = RES.getRes("waitingBg.png")
var rectBg = new FYGE.Sprite(rectBgTexture);
this.addChild(rectBg);
var rotTexture: FYGE.Texture = RES.getRes("waitingRot.png")
let rot = new FYGE.Sprite(rotTexture);
rot.x = (rectBgTexture.width - rotTexture.width) / 2
rot.y = 47//533;
rot.anchorX = rotTexture.width / 2;
rot.anchorY = rotTexture.height / 2;
this.addChild(rot);
let count = 0;
rot.addEventListener(FYGE.Event.ENTER_FRAME, () => {
count++;
if (count % 30 == 0) rot.rotation += 45;
}, this)
this.msg = new FYGE.TextField();
this.msg.y = 125;
this.msg.textWidth = rectBgTexture.width;
this.msg.textAlign = FYGE.TEXT_ALIGN.CENTER;
this.msg.size = 26
this.msg.fillColor = "#ffffff";
this.addChild(this.msg);
}
show(msg: string = "加载中") {
this.msg.text = msg;
}
destroy() {
super.destroy();
this.msg = null;
}
}
const _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
/**
* base64编码汉字,
* 一般用于链接参数传递,
* 先base64.encode,再encodeURIComponent后带入,取参数时会decodeURIComponent,然后再base64.decode后
* 直接调用Base64.ins
*/
export class Base64 {
// private property
// _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
private static instance: Base64;
public static get ins(): Base64 {
if (!this.instance) {
this.instance = new Base64();
}
return this.instance;
}
constructor() {
}
// public method for encoding
encode(input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = this._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
}
return output;
}
// public method for decoding
decode(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = _keyStr.indexOf(input.charAt(i++));
enc2 = _keyStr.indexOf(input.charAt(i++));
enc3 = _keyStr.indexOf(input.charAt(i++));
enc4 = _keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = this._utf8_decode(output);
return output;
}
// private method for UTF-8 encoding
private _utf8_encode(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
// private method for UTF-8 decoding
private _utf8_decode(utftext) {
var string = "";
var i = 0;
var c = 0;
var c2 = 0;
var c3 = 0
while (i < utftext.length) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if ((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}
\ No newline at end of file
/**
* 回收池
*/
export class GPool {
private static pool = {};
/**
* 取出
* @param name
*/
public static takeOut(name: string) {
if (this.pool[name] && this.pool[name].length) {
return this.pool[name].shift();
}
return null;
}
/**
* 回收
* @param name
* @param obj
*/
public static recover(name: string, obj) {
if (!this.pool[name]) {
this.pool[name] = [];
}
this.pool[name].push(obj);
}
}
\ No newline at end of file
/**
* 用到的和业务相关的
* 各种静态方法汇总
*
* 获取修改链接参数
* 获取cookie
* 缓存相关
* 数组相关
*
*/
export class GTool {
/**
* 替换或添加url里的参数
* @param url 修改的url
* @param arg 参数名
* @param arg_val 参数值
*/
public static changeURLArg(url: string, arg: string, arg_val: string | number) {
var pattern = arg + '=([^&]*)';
var replaceText = arg + '=' + arg_val;
if (url.match(pattern)) {
var tmp = '/(' + arg + '=)([^&]*)/gi';
// tmp = url.replace(eval(tmp), replaceText);
tmp = url.replace(new RegExp(tmp), replaceText);
return tmp;
} else {
if (url.match('[\?]')) {
return url + '&' + replaceText;
} else {
return url + '?' + replaceText;
}
}
}
/**
* 读取缓存 用到时重写
*/
public static readCache(key: string, type: string = 'localStorage') {
if (!window.localStorage) {
return false;
}
return window[type].getItem(key);
}
/**
* 写缓存 用到时重写
*/
public static writeCache(key: string, value: any = 'true', type: string = 'localStorage') {
if (!window.localStorage) {
// trace(Func.replace(SysLang.lang_012, [type]));
return;
}
window[type].setItem(key, value);
}
/**
* 获得cacheKey今日次数
* 第二天归0重新计数 用到时重写
* @param cacheKey
*/
public static returnTodayTimes(cacheKey: string): number {
var year1 = this.readCache("year" + cacheKey);
var month1 = this.readCache("month" + cacheKey);
var day1 = this.readCache("day" + cacheKey);
var date = new Date();
var year2 = date.getFullYear().toString();
var month2 = date.getMonth().toString();
var day2 = date.getDate().toString();
if (this.int(year2) <= this.int(year1)) {
if (this.int(month2) <= this.int(month1)) {
if (this.int(day2) <= this.int(day1)) {
return this.int(this.readCache(cacheKey));
}
}
}
//如果不是同一天了,归0
var today = "0";
this.writeCache("year" + cacheKey, year2);
this.writeCache("month" + cacheKey, month2);
this.writeCache("day" + cacheKey, day2);
this.writeCache(cacheKey, today);
return 0;
}
/**
* 随机,两个参数时是数值范围,比如randomT(1,10),一个参数时是数组
* @param e
* @param n
*/
public static randomT(e, n?) {
return e && "number" == typeof e.length && e.length ? e[Math.floor(Math.random() * e.length)] : ("number" != typeof n && (n = e || 1, e = 0), e + Math.random() * (n - e))
}
/**
* 从数组中移除一个元素
* @param e 元素
* @param arr 数组
*/
public static removeEle(e, arr) {
var index = arr.indexOf(e);
if (index >= 0) {
arr.splice(index, 1)
}
}
/**
* 数组中插入一个数值,按顺序的
* 数组是从小到大的
* @param num
* @param arr
*/
public static insert(num, arr) {
for (var i = arr.length - 1; i >= 0; i--) {
if (num > arr[i]) {
//在arr[i]后加num
arr.splice(i + 1, 0, num);
break
}
}
}
/**
* 获取start到end里的n个整数
* @param start 0
* @param end 19
* @param n 3
*/
public static getRandomNumber(start: number, end: number, n: number): number[] {
var arr = [];
for (var i = 0; i < n; i++) {
var number = Math.floor(Math.random() * (end - start + 1) + start);
if (arr.indexOf(number) < 0) {
arr.push(number);
} else {
i--;
}
}
return arr;
}
/**
* 打乱数字数组,改变原数组
* @param arr
*/
public static disturbNumberArr(arr: number[]) {
arr.sort(function () {
return (0.5 - Math.random());
});
}
/**
* 其实打乱数组取前几个就行
* 随机取数组arr中count个元素,不改变原数组
* @param arr
* @param count
*/
public static getRandomArrayElements(arr: any[], count: number) {
var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
//如果count大于等于数组长度,返回所有数组
if (min <= 0) return shuffled;
if (count <= 0) return [];
//随机排序,然后取出后面的元素
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(min);
}
/**
* 随机取数组arr中count个元素,原数组减少count个
* @param arr
* @param count
*/
public static getRandomArrayElementsEx(arr: any[], count: number): any[] {
//如果count大于等于数组长度,返回所有数组
if (arr.length <= count) return arr.slice();
if (count <= 0) return [];
var arrCopy = arr.slice();
var outArr = [];
while (count--) {
var rand = Math.floor(Math.random() * arrCopy.length);
var ele = arrCopy.splice(rand, 1)[0];
outArr.push(ele);
}
return outArr
}
/**
* 向下取整,或把字符串执行parseInt(字符串转数字取整数部分)
* @param n 数字或字符串
*/
private static int(n: any): number {
return n >> 0;//~~n
};
/**
* emoji正则式
*/
public static emojiReg = /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/ig
/**
* 在字符串间加空格
* @param str
*/
public static addSpaceInString(str: string) {
if (!str.length || str.length == 1) return str;
var txt = "";
//每个字符后加空格
for (var i = 0; i < str.length - 1; i++) {
txt = txt + str[i] + " ";
}
txt = txt + str[str.length - 1]
return txt
}
}
\ No newline at end of file
import { RES } from "../RES";
/**
*
*/
export class Module extends FYGE.Container {
protected data: any;
constructor(data?: any) {
super();
this.data = data;
this.init();
}
/**
* 初始化资源和皮肤
*/
private init() {
this.preLoadRes().then(
() => {
this.initUi();
this.onLoaded && this.onLoaded();
},
() => {
this.onLoadError && this.onLoadError();
}
);
}
/**
* 提前加载的资源
*/
protected preLoadRes() {
return new Promise((resolve, reject) => {
if (this.groupNames && this.groupNames.length) {
var arr: Promise<any>[] = [];
for (var i = 0; i < this.groupNames.length; i++) {
arr.push(RES.loadGroup(this.groupNames[i]))
}
Promise.all(arr).then(resolve, reject)
} else {
resolve()
}
})
}
/**
* 初始化ui
*/
protected initUi() {
}
/**
* 资源加载完成后执行,用于场景及弹框控制
*/
onLoaded: () => void
/**
* 资源加载失败时执行,用于场景及弹框控制
*/
onLoadError: () => void;
/**
* 可以有多个组
*/
get groupNames(): string[] { return null }
/**
* 在构造函数后执行
*/
start(data?: any) {
this.initEvents();
}
/**
* 添加事件
*/
initEvents(): void {
}
/**
* 移除事件
*/
removeEvents(): void {
}
/**
* 鼠标事件
* @param enable
*/
protected enableMouseEvt(enable: boolean): void {
this.mouseEnable = enable;
this.mouseChildren = enable;
}
public destroy(): void {
this.data = null;//看情况吧,有时候hidePanel后用了data,注意
//移除事件
this.removeEvents();
//派发销毁事件,主要用于场景及弹框控制
this.dispatchEvent("onDestroy");
super.destroy();
}
}
\ No newline at end of file
import { Module } from "./Module";
export class Panel extends Module {
private isShowing: boolean
showAni() {
if (this.isShowing) return;
this.isShowing = true;
let oriY = this.y || 0;
this.y = -200;
FYGE.Tween.get(this)
.to({ y: oriY }, 500, FYGE.Ease.quartOut)
.call(() => {
this.isShowing = false;
})
}
initEvents() {
this.closeBtns.forEach(
btn => { if (btn) btn.addEventListener(FYGE.MouseEvent.CLICK, this.hidePanel, this) }
)
}
removeEvents() {
this.closeBtns.forEach(
btn => { if (btn) btn.removeEventListener(FYGE.MouseEvent.CLICK, this.hidePanel, this) }
)
}
/**
* 需要的放入,不重复写关闭按钮事件
*/
protected get closeBtns(): any[] { return [this['closeBtn']] }
hidePanel() {
this.destroy();
}
}
\ No newline at end of file
import { Module } from "./Module";
export class Scene extends Module {
/**
* 显示动画
* 继承时注意,回调要加
* 因为这种动画基本原场景最好不消失
*/
showAni(callback: Function) {
callback()
}
/**
* 统一更新方法
*/
updateScene() {
}
}
\ No newline at end of file
import PanelCtrl from "../ctrls/panelCtrl";
import SceneCtrl from "../ctrls/sceneCtrl";
/**
* 添加进舞台的所有层级
* 仿白鹭的那套
*/
class Layers extends FYGE.Container {
private _bottomLayer: FYGE.Container;
private _sceneLayer: FYGE.Container;
private _popupLayer: FYGE.Container;
private _toastLayer: FYGE.Container;
private _topLayer: FYGE.Container;
private _shareLayer: FYGE.Container;
init(stage: FYGE.Stage) {
stage.addChild(this);
var arr = [
"_bottomLayer",
"_sceneLayer",
"_popupLayer",
"_toastLayer",
"_topLayer",
"_shareLayer"
];
for (var i = 0; i < arr.length; i++) {
this[arr[i]] = new FYGE.Container();
//有些时候,定宽的时候,部分layer置顶,部分居中,再处理
//为了都置顶和置左,stage的方式永远居中视窗,要么改stage永远左上为00
// this[arr[i]].y = this.stageOffsetY;
//如果定宽这里没必要,肯定是0
// this[arr[i]].x = this.stageOffsetX;//去掉,定高时就居中了
this.addChild(this[arr[i]]);
}
//初始化场景层级
SceneCtrl.instance.init(this.sceneLayer)
//初始化弹框层级
PanelCtrl.instance.init(this.popupLayer)
}
/**
* 底图所在层级,比如统一的背景
*/
get bottomLayer() { return this._bottomLayer }
/**
* 场景
*/
get sceneLayer() { return this._sceneLayer }
/**
* 弹框
*/
get popupLayer() { return this._popupLayer }
/**
* toast所在层级
*/
get toastLayer() { return this._toastLayer }
/**
* 顶层,比如统一标题栏等
*/
get topLayer() { return this._topLayer }
/**
* 分享引导层
*/
get shareLayer() { return this._shareLayer }
/**
* 舞台信息都放在layers里吧
* 舞台可见高度,初始化后才能使用
*/
get stageHeight() {
if (!this.stage) return 0;
return this.stage.viewRect.height;
}
/**
* 舞台可见宽度
*/
get stageWidth() {
if (!this.stage) return 0;
return this.stage.viewRect.width;
}
/**
* 适配方式x两边偏移的量,固定宽度x为0
*/
get stageOffsetX() {
if (!this.stage) return 0;
return this.stage.viewRect.x;
}
get stageOffsetY() {
if (!this.stage) return 0;
return this.stage.viewRect.y;
}
/**
* 舞台中心点位置x
*/
// get stageCenterX(): number {
// return this.stage.viewRect.x + this.stage.viewRect.width >> 1;
// }
/**
* 舞台中心点位置y,layer位置做过偏移的就不对了,所以还是自行算吧
*/
// get stageCenterY(): number {
// return this.stage.viewRect.y + this.stage.viewRect.height >> 1;
// }
}
export const layers = new Layers();
//先执行,在淘宝小程序中重新进入会再次初始化
export function destroyLayers() {
//所有层级移除,init会重新建
layers.removeChildren();
//从父级stage移除自己,init会重新加
if (layers.parent) layers.parent.removeChild(layers)
}
\ No newline at end of file
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(window,(function(){return n={},t.m=e=[function(t,e,n){"use strict";var o,r,i,s,a,u,c;function l(t,e,n){var r=t.substring(t.lastIndexOf(".")+1,t.length);if("png"==r||"jpg"==r){if(!FYGE.TextureCache[t]){if(c[t])return f(t,e,n);if((y=h(t))&&"jpg"!=r){var s=p(y);if(s&&s.atlas){var a=y+".json";return c[a]?c[a].then((function(o){return e&&e.call(n,FYGE.TextureCache[t],t),FYGE.TextureCache[t]}),(function(){return e&&e.call(n,null,t),null})):l(a).then((function(){return e&&e.call(n,FYGE.TextureCache[t],t),FYGE.TextureCache[t]}),(function(){return e&&e.call(n,null,t),null}))}}var u=y?o.resPath+y+"/"+t:t,d=new Promise((function(o,r){FYGE.GlobalLoader.loadImage((function(i,s){delete c[t],i?(FYGE.Texture.addToCache(FYGE.Texture.from(s),t),e&&e.call(n,FYGE.TextureCache[t],t),o(FYGE.TextureCache[t])):(e&&e.call(n,null,t),r())}),u)}));return c[t]=d}e&&e.call(n,FYGE.TextureCache[t],t),new Promise((function(e){e(FYGE.TextureCache[t])}))}else{if("svga"==r)return i[t]?(e&&e.call(n,i[t],t),new Promise((function(e){e(i[t])}))):c[t]?f(t,e,n):(u=(y=h(t))?o.resPath+y+"/"+t:t,d=new Promise((function(o,r){FYGE.GlobalLoader.loadSvga((function(s,a){delete c[t],s?(s&&(i[t]=a),e&&e.call(n,a,t),o(a)):(e&&e.call(n,null,t),r())}),u)})),c[t]=d);if("json"==r){if(c[t])return f(t,e,n);var y;u=(y=h(t))?o.resPath+y+"/"+t:t,d=new Promise((function(o,r){var i=p(y).atlas;FYGE.GlobalLoader.loadImage((function(s,a){var u;s?(u=FYGE.createTextureSheet(new FYGE.BaseTexture(a),i),e&&e.call(n,u,t),o(u)):(e&&e.call(n,null,t),r())}),u.replace("json","png"))}));return c[t]=d}}}function h(t){for(var e=0;e<r.groups.length;e++){var n=r.groups[e],o=n.keys;if(o&&-1<o.split(",").indexOf(t))return n.name;if(n.atlas&&n.name+".json"==t)return n.name}return null}function p(t){for(var e,n=r.groups,o=0;o<n.length;o++)if(n[o].name===t){e=n[o];break}return e}function f(t,e,n){return c[t].then((function(o){e&&e.call(n,o,t)}),(function(){e&&e.call(n,null,t)})),c[t]}Object.defineProperty(e,"__esModule",{value:!0}),o=e.RES||(e.RES={}),i={},s={},a={},u={},c={},o.loadConfig=function(t){r=t,o.resPath=t.path},o.loadGroup=function(t){if(a[t])return new Promise((function(t){t()}));if(u[t])return u[t];var e=function(t){var e=p(t);if(!e)return null;if(e.atlas){var n=[t+".json"];return e.keys&&(n=n.concat(e.keys.split(",").filter((function(t){return".png"!=t.substr(-4)})))),n}return e.keys?e.keys.split(","):null}(t);if(!e||!e.length)return a[t]=!0,new Promise((function(t){t()}));var n=new Promise((function(n,o){!function(t,e){var n=0,o=e.length;o||t(!0);for(var r=!0,i=0;i<o;i++)l(e[i],(function(e,i){e||(r=!1),++n==o&&t(r)}),this)}((function(e){delete u[t],e?(a[t]=!0,n()):o()}),e)}));return u[t]=n},o.getResAsync=l,o.getResByUrl=function(){},o.getRes=function(t){var e=t.substring(t.lastIndexOf(".")+1,t.length);return"png"==e||"jpg"==e?FYGE.TextureCache[t]||null:"svga"==e?i[t]||null:"mp3"==e?s[t]||null:void 0}},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s=n(6),a=n(7),u=(r(c,i=FYGE.Container),c.prototype.init=function(t){t.addChild(this);for(var e=["_bottomLayer","_sceneLayer","_popupLayer","_toastLayer","_topLayer","_shareLayer"],n=0;n<e.length;n++)this[e[n]]=new FYGE.Container,this.addChild(this[e[n]]);a.default.instance.init(this.sceneLayer),s.default.instance.init(this.popupLayer)},Object.defineProperty(c.prototype,"bottomLayer",{get:function(){return this._bottomLayer},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"sceneLayer",{get:function(){return this._sceneLayer},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"popupLayer",{get:function(){return this._popupLayer},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"toastLayer",{get:function(){return this._toastLayer},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"topLayer",{get:function(){return this._topLayer},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"shareLayer",{get:function(){return this._shareLayer},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"stageHeight",{get:function(){return this.stage?this.stage.viewRect.height:0},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"stageWidth",{get:function(){return this.stage?this.stage.viewRect.width:0},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"stageOffsetX",{get:function(){return this.stage?this.stage.viewRect.x:0},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"stageOffsetY",{get:function(){return this.stage?this.stage.viewRect.y:0},enumerable:!0,configurable:!0}),c);function c(){return null!==i&&i.apply(this,arguments)||this}e.layers=new u,e.destroyLayers=function(){e.layers.removeChildren(),e.layers.parent&&e.layers.parent.removeChild(e.layers)}},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s,a=n(0),u=n(1),c=!1;e.showWaiting=function(t){var e,n,o,r;c||(c=!0,e=new h,s=u.layers.topLayer,i=e,n=(u.layers.stageWidth-160)/2,o=(u.layers.stageHeight-i.height)/2,i.x=u.layers.stageOffsetX-s.x+n,i.y=u.layers.stageOffsetY-s.y+o,(r=(new FYGE.Graphics).beginFill(0).drawRect(-n,-o,u.layers.stageWidth,u.layers.stageHeight).endFill()).alpha=0,i.addChildAt(r,0)),i.show(t),s.addChild(i)},e.hideWaiting=function(){s.removeChild(i)},e.destroyWaiting=function(){c&&i&&!i.destroyed&&(i.destroy(),s=i=null,c=!1)};var l,h=(r(p,l=FYGE.Container),p.prototype.show=function(t){void 0===t&&(t="加载中"),this.msg.text=t},p.prototype.destroy=function(){l.prototype.destroy.call(this),this.msg=null},p);function p(){var t=l.call(this)||this,e=a.RES.getRes("waitingBg.png"),n=new FYGE.Sprite(e);t.addChild(n);var o=a.RES.getRes("waitingRot.png"),r=new FYGE.Sprite(o);r.x=(e.width-o.width)/2,r.y=47,r.anchorX=o.width/2,r.anchorY=o.height/2,t.addChild(r);var i=0;return r.addEventListener(FYGE.Event.ENTER_FRAME,(function(){++i%30==0&&(r.rotation+=45)}),t),t.msg=new FYGE.TextField,t.msg.y=125,t.msg.textWidth=e.width,t.msg.textAlign=FYGE.TEXT_ALIGN.CENTER,t.msg.size=26,t.msg.fillColor="#ffffff",t.addChild(t.msg),t}},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s,a,u,c=n(1),l=n(0),h=!1;e.showToast=function(t){var e,n;h||(h=!0,i=new f,s=c.layers.toastLayer,i.alpha=0,i.x=c.layers.stageOffsetX-s.x+(c.layers.stageWidth-i.width)/2,e=i.height,n=c.layers.stageOffsetY-s.y,a=n-e,u=n+(c.layers.stageHeight-e)/2),i.show(t),s.addChild(i),FYGE.Tween.removeTweens(i),FYGE.Tween.get(i).set({y:a,alpha:1}).to({y:u},500,FYGE.Ease.quartOut).wait(800).to({alpha:0},300).call((function(){s.removeChild(i)}))},e.destroyToast=function(){h&&i&&!i.destroyed&&(i.destroy(),s=i=null,h=!1)};var p,f=(r(d,p=FYGE.Container),d.prototype.show=function(t){this.msg.text=t,this.msg.x=(this.bg.width-this.msg.textWidth)/2},d.prototype.destroy=function(){p.prototype.destroy.call(this),this.msg=null,this.bg=null},d);function d(){var t=p.call(this)||this;t.PADDING=40,t.mouseChildren=!1,t.mouseEnable=!1;var e=l.RES.getRes("toastBg.png");return t.bg=new FYGE.Sprite(e),t.addChild(t.bg),t.msg=new FYGE.TextField,t.msg.size=28,t.msg.fillColor="0xffffff",t.msg.text="",t.msg.verticalAlign=FYGE.VERTICAL_ALIGN.MIDDLE,t.msg.textHeight=e.height,t.msg.textAlign=FYGE.TEXT_ALIGN.CENTER,t.addChild(t.msg),t}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=n(2),r=n(6),i=n(7),s=n(3),a=n(3);e.showToast=a.showToast,function(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}(n(2)),e.showPanel=function(t,e){r.default.instance.show(t,e)},e.closeAllPanels=function(){r.default.instance.closeAll()},e.closeCurrentPanel=function(){r.default.instance.closeCurrent()},e.changeScene=function(t,e){i.default.instance.change(t,e)},e.getCurrentScene=function(){return i.default.instance.currentScene},e.showAlert=function(t,e){my?my.alert({title:t||"",content:e||""}):console.log(t,e)},e.wait=function(t,e){var n={};return FYGE.Tween.get(n).wait(e).call(t),n},e.clearWait=function(t){FYGE.Tween.removeTweens(t)},e.destroyAllCtrls=function(){s.destroyToast(),o.destroyWaiting(),r.default.instance.destroy(),i.default.instance.destroy()}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=n(0),r=(i.init=function(){},i.getSprite=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=0);var r=new FYGE.Sprite(o.RES.getRes(t));return r.x=e,r.y=n,r},i.getText=function(t,e,n,o,r,i,s){void 0===n&&(n="#000000"),void 0===o&&(o=0),void 0===r&&(r=FYGE.TEXT_ALIGN.CENTER),void 0===i&&(i=0),void 0===s&&(s=0);var a=new FYGE.TextField;return a.fillColor=n,a.size=e,a.textWidth=o,a.textAlign=r,a.x=i,a.y=s,a.text=t,a},i.getRect=function(t,e,n,o,r,i,s){void 0===n&&(n=16711680),void 0===o&&(o=1),void 0===r&&(r=0),void 0===i&&(i=0),void 0===s&&(s=0);var a=new FYGE.Graphics;return a.beginFill(n),a.alpha=o,r?a.drawRoundedRect(0,0,t,e,r):a.drawRect(0,0,t,e),a.endFill(),a.position.set(i,s),a},i.initLatData=function(){for(var t=this.width+11,e=this.height+11,n=this.offsetX+this.width/2,o=this.offsetY+this.height/2,r=0;r<this.rowNum;r++)for(var i=0;i<this.colNum;i++)this.rcToIndexMap[""+r+i]=r*this.colNum+i,this.indexToRcMap[r*this.colNum+i]=[r,i],this.rowColPositions[""+r+i]=[n+i*t,o+r*e],this.indexPositions[r*this.colNum+i]=[n+i*t,o+r*e]},i.rcToIndex=function(t,e){var n=""+t+e;return this.rcToIndexMap[n]},i.indexToRc=function(t){return this.indexToRcMap[t]},i.getPositionByRc=function(t,e){var n=""+t+e;return this.rowColPositions[n]},i.getPositionByIndex=function(t){return this.indexPositions[t]},i.cacheKey="hadCompleteHaokelai",i.rowNum=4,i.colNum=4,i.width=125,i.height=125,i.offsetX=106,i.offsetY=600,i.rcToIndexMap={},i.indexToRcMap=[],i.rowColPositions={},i.indexPositions=[],i);function i(){}e.Tool=r},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=n(1),r=n(2),i=n(3),s=(Object.defineProperty(a,"instance",{get:function(){return a._instance||(a._instance=new a)},enumerable:!0,configurable:!0}),a.prototype.init=function(t){this._parent=t;var e=new FYGE.Graphics;e.beginFill(0,1),e.drawRect(o.layers.stageOffsetX-t.x,o.layers.stageOffsetY-t.y,o.layers.stageWidth,o.layers.stageHeight),e.endFill(),e.visible=!1,this._parent.addChild(e),this._bg=e},a.prototype.closeAll=function(){this.stacks.forEach((function(t){return t.hidePanel()}))},a.prototype.show=function(t,e){var n=this;r.showWaiting();var o=new t(e);return this.add(o),this.stacks.push(o),o.onLoaded=function(){r.hideWaiting(),n.updateView(),o.start(e)},o.onLoadError=function(){r.hideWaiting(),i.showToast("资源加载失败"),o.removeEventListener("onDestroy",n.onPanelHide,n),n.remove(o)},o},a.prototype.updateView=function(){this.stacks.length?!(this._parent.visible=!0)===this._bg.visible&&(this._bg.visible=!0,this._bg.alpha=0,FYGE.Tween.removeTweens(this._bg),FYGE.Tween.get(this._bg).to({alpha:.7},200,FYGE.Ease.cubicOut)):(this._bg.visible=!1,this._current=null,this._parent.visible=!1);for(var t=0;t<this.stacks.length;t++)t<this.stacks.length-1?this.stacks[t].visible=!1:(this.stacks[t].visible=!0,this.stacks[t].showAni(),this._current=this.stacks[t])},a.prototype.add=function(t){this._parent.addChild(t),t.addEventListener("onDestroy",this.onPanelHide,this)},a.prototype.remove=function(t){this._parent.removeChild(t),this.stacks=this.stacks.filter((function(e){return e!=t}))},a.prototype.onPanelHide=function(t){var e=t.target;e.removeEventListener("onDestroy",this.onPanelHide,this),this.remove(e),this.updateView()},a.prototype.closeCurrent=function(){this._current&&this._current.hidePanel()},a.prototype.destroy=function(){a._instance=null,this.stacks=null,this._current=null,this._parent=null,this._bg.destroy(),this._bg=null},a);function a(){this.stacks=[]}e.default=s},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=n(2),r=n(3),i=(Object.defineProperty(s,"instance",{get:function(){return s._instance||(s._instance=new s)},enumerable:!0,configurable:!0}),s.prototype.init=function(t){this._parent=t},s.prototype.change=function(t,e){var n,i,s=this;this._currentScene&&this._currentScene instanceof t||((n=new t(e)).visible=!1,o.showWaiting(),i=this._currentScene,n.onLoaded=function(){o.hideWaiting(),n.showAni((function(){i&&i.destroy()})),n.visible=!0,n.start()},n.onLoadError=function(){o.hideWaiting(),r.showToast("资源加载失败"),s._currentScene=i||null,s._parent.removeChild(n)},this._currentScene=n,this._parent.addChild(n))},Object.defineProperty(s.prototype,"currentScene",{get:function(){return this._currentScene},enumerable:!0,configurable:!0}),s.prototype.destroy=function(){s._instance=null,this._currentScene=null,this._parent=null},s);function s(){}e.default=i},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s=n(9),a=(r(u,i=s.Module),u.prototype.showAni=function(t){t()},u.prototype.updateScene=function(){},u);function u(){return null!==i&&i.apply(this,arguments)||this}e.Scene=a},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s=n(0),a=(r(u,i=FYGE.Container),u.prototype.init=function(){var t=this;this.preLoadRes().then((function(){t.initUi(),t.onLoaded&&t.onLoaded()}),(function(){t.onLoadError&&t.onLoadError()}))},u.prototype.preLoadRes=function(){var t=this;return new Promise((function(e,n){if(t.groupNames&&t.groupNames.length){for(var o=[],r=0;r<t.groupNames.length;r++)o.push(s.RES.loadGroup(t.groupNames[r]));Promise.all(o).then(e,n)}else e()}))},u.prototype.initUi=function(){},Object.defineProperty(u.prototype,"groupNames",{get:function(){return null},enumerable:!0,configurable:!0}),u.prototype.start=function(t){this.initEvents()},u.prototype.initEvents=function(){},u.prototype.removeEvents=function(){},u.prototype.enableMouseEvt=function(t){this.mouseEnable=t,this.mouseChildren=t},u.prototype.destroy=function(){this.data=null,this.removeEvents(),this.dispatchEvent("onDestroy"),i.prototype.destroy.call(this)},u);function u(t){var e=i.call(this)||this;return e.data=t,e.init(),e}e.Module=a},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=(r.takeOut=function(t){return this.pool[t]&&this.pool[t].length?this.pool[t].shift():null},r.recover=function(t,e){this.pool[t]||(this.pool[t]=[]),this.pool[t].push(e)},r.pool={},r);function r(){}e.GPool=o},function(t,e,n){"use strict";var o=this&&this.__awaiter||function(t,e,n,o){return new(n=n||Promise)((function(r,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){t.done?r(t.value):new n((function(e){e(t.value)})).then(s,a)}u((o=o.apply(t,e||[])).next())}))},r=this&&this.__generator||function(t,e){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s={next:a(0),throw:a(1),return:a(2)};return"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=0<(r=i.trys).length&&r[r.length-1])&&(6===s[0]||2===s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(1),s=n(0),a=n(4),u=n(12),c=n(20),l=n(21);e.GDispatcher=new FYGE.EventDispatcher;var h=(p.prototype.onAddToStage=function(){return o(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return i.layers.init(this.stage),console.log("初始化层级完成"),s.RES.loadConfig(c.ResJson),console.log("初始化资源配置完成"),[4,s.RES.loadGroup("common")];case 1:return t.sent(),console.log("通用资源加载完成"),a.changeScene(u.StartScene),console.log("恶趣味去"),[2]}}))}))},p.prototype.run=function(){this._pause=!1},p.prototype.pause=function(){this._pause=!0},p.prototype.addGlobalEvent=function(t,n,o,r){void 0===r&&(r=!1),r?e.GDispatcher.once(t,n,o):e.GDispatcher.addEventListener(t,n,o)},p.prototype.dispatchGlobalEvent=function(t,n){e.GDispatcher.dispatchEvent(t,n)},p.prototype.removeGlobalEvent=function(t,n,o){e.GDispatcher.removeEventListener(t,n,o)},p.prototype.destroy=function(){FYGE.Tween.removeAllTweens(),FYGE.getCancelAnimationFrame()(this.requestID),i.destroyLayers(),a.destroyAllCtrls(),this.stage.destroy(),e.GDispatcher.removeAllEventListener(),l.destroyNetData()},p);function p(t){var e;my&&(FYGE.initedByCanvas(t),e=my.getSystemInfoSync());var n=new FYGE.Stage(t,750,1624,e&&e.windowWidth||document.body.clientWidth,e&&e.windowHeight||document.body.clientHeight,FYGE.RENDERER_TYPE.CANVAS);(this.stage=n).addEventListener(FYGE.Event.INIT_STAGE,this.onAddToStage,this);var o=this;!function t(){o._pause||(FYGE.Tween.flush(),n.flush()),o.requestID=FYGE.getRequestAnimationFrame()(t)}()}e.Main=h},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i=n(8),s=n(0),a=n(4),u=n(1),c=n(13);e.svgaPool={};var l,h=(r(p,l=i.Scene),Object.defineProperty(p.prototype,"groupNames",{get:function(){return["startScene"]},enumerable:!0,configurable:!0}),p.prototype.initUi=function(){l.prototype.initUi.call(this),this.addChild(new FYGE.Sprite(s.RES.getRes("startBg.jpg")))},p.prototype.start=function(){l.prototype.start.call(this),a.showToast("点击下方按钮\n开始游戏"),a.wait((function(){a.showToast("下一句文案\n是否覆盖")}),2e3),this.testMove(),this.testMv();var t=new FYGE.Button(s.RES.getRes("startBtn.png"));t.position.set(151.5,1e3),this.addChild(t),t.addEventListener(FYGE.MouseEvent.CLICK,(function(){console.log("9999546"),a.changeScene(c.PlayScene)}),this)},p.prototype.testMove=function(){var t=new FYGE.Sprite(s.RES.getRes("silverDraft.png"));t.x=500,t.y=0,this.addChild(t),this.addEventListener(FYGE.Event.ENTER_FRAME,(function(){t.y+=5,t.y=Math.round(t.y),1300<t.y&&(t.y=0)}),this)},p.prototype.testScroll=function(){var t=new FYGE.Sprite(s.RES.getRes("startBg.jpg")),e=new FYGE.ScrollPage(750,u.layers.stageHeight,1624,!0,!0);e.view.addChild(t),this.addChild(e),e.x=100,e.y=100;var n=new FYGE.ScrollPage(750,200,1624,!1,!1);n.maxDistance=2090,n.y=900,e.view.addChild(n);for(var o=0;o<10;o++){var r=new FYGE.Sprite(s.RES.getRes("silverDraft.png"));r.width=200,r.height=200,r.x=10*o+200*o,n.view.addChild(r)}},p.prototype.testGraphics=function(){var t=new FYGE.Graphics;t.beginFill(16711680,.7),t.drawEllipse(200,200,200,300),t.endFill(),this.addChild(t)},p.prototype.testSprite=function(){for(var t=s.RES.getRes("silverDraft.png"),e=0;e<2500;e++){var n=new FYGE.Sprite(t);n.x=750*Math.random(),n.y=1206*Math.random(),this.addChild(n)}},p.prototype.testMv=function(){var t=this;SvgaParser.loadSvga("cloud://A8673B47AAA58993A24A6718E203B967//dice.svga",(function(e){var n=new FYGE.MovieClip(e);t.addChild(n)}),(function(){console.log(123)}))},p);function p(){return null!==l&&l.apply(this,arguments)||this}e.StartScene=h},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s,a=n(8),u=n(4),c=n(5),l=n(10),h=n(14),p=n(15),f=n(16),d=n(17);(s=i=i||{})[s.left=0]="left",s[s.right=1]="right",s[s.up=2]="up",s[s.down=3]="down";var y,g=(r(v,y=a.Scene),Object.defineProperty(v.prototype,"groupNames",{get:function(){return["playScene"]},enumerable:!0,configurable:!0}),v.prototype.initUi=function(){this.addChild(c.Tool.getSprite("playBg.jpg")),c.Tool.initLatData(),this.lats=new Array(16),u.showToast("啊哦,没法移动了\n重置中")},v.prototype.start=function(){y.prototype.start.call(this),this.resetGame()},v.prototype.resetGame=function(){for(var t,e=0;e<this.lats.length;e++)this.lats[e]&&(t=this.lats[e],this.removeChild(t),l.GPool.recover("gameEle",t),this.lats[e]=null);this.generateOne(),this.generateOne()},v.prototype.generateOne=function(t,e){var n=this,o=(t=void 0===t?this.getOneEmptyIndex():t,void 0===e?Math.random()<.5?2:4:e),r=l.GPool.takeOut("gameEle");r?r.reset(o):r=new p.GameEle(o),this.addChild(r),r.position.set(c.Tool.getPositionByIndex(t)[0],c.Tool.getPositionByIndex(t)[1]),(this.lats[t]=r).index=t,r.scale.set(.1,.1),FYGE.Tween.get(r).to({scaleX:1,scaleY:1},100,FYGE.Ease.backOut).call((function(){!function(t){if(!function(t){for(var e=0;e<t.length;e++)if(!t[e])return 1}(t)){for(var e=0;e<t.length;e++){var n=t[e],o=c.Tool.indexToRc(e);if(o[1]<c.Tool.colNum-1&&n.type==t[e+1].type)return;if(o[0]<c.Tool.rowNum-1&&n.type==t[e+c.Tool.colNum].type)return}return 1}}(n.lats)?n.moveMark=!0:(u.showToast("啊哦,没法移动了\n重置中"),setTimeout((function(){n.resetGame()}),1600))}))},v.prototype.getOneEmptyIndex=function(){for(var t=[],e=0;e<this.lats.length;e++)this.lats[e]||t.push(e);return t.length?(h.GTool.disturbNumberArr(t),t[0]):null},v.prototype.onMouseDown=function(t){var e,n,o,r;function i(t){o=t.stageX-e,r=t.stageY-n}function s(){this.removeEventListener(FYGE.MouseEvent.MOUSE_MOVE,i,this),this.removeEventListener(FYGE.MouseEvent.MOUSE_UP,s,this),this.removeEventListener(FYGE.MouseEvent.MOUSE_OUT,s,this),this.checkMove(o,r),this.hasDown=!1}this.moveMark&&(this.hasDown||(this.hasDown=!0,e=t.stageX,n=t.stageY,this.addEventListener(FYGE.MouseEvent.MOUSE_MOVE,i,this),this.addEventListener(FYGE.MouseEvent.MOUSE_UP,s,this),this.addEventListener(FYGE.MouseEvent.MOUSE_OUT,s,this)))},v.prototype.checkMove=function(t,e){var n,o=this;if(Math.abs(t)>Math.abs(e)?(0<t&&(n=this.checkRight()),t<0&&(n=this.checkLeft())):0<e?n=this.checkDown():e<0&&(n=this.checkUp()),n&&n.length){this.moveMark=!1;for(var r=0,i=n.length,s=0;s<n.length;s++){var a=n[s];this.lats[a.startEle1.index]=null,a.startEle1.index=a.endIndex,this.lats[a.endIndex]=a.startEle1,a.startEle2&&(this.lats[a.startEle2.index]=null,a.startEle1.tempType=2*a.startEle1.type),f.moveAni((function(){++r==i&&(o.check2048()?u.showPanel(d.UnlockPanel,{closeFun:function(){o.resetGame()},grade:2048}):o.generateOne())}),a.startEle1,a.endIndex,a.startEle2)}}},v.prototype.checkLeft=function(){for(var t=[],e=0;e<c.Tool.rowNum;e++){for(var n=[],o=0;o<c.Tool.colNum;o++)n.push(e*c.Tool.colNum+o);t=t.concat(w(n,this.lats))}return t},v.prototype.checkRight=function(){for(var t=[],e=0;e<c.Tool.rowNum;e++){for(var n=[],o=c.Tool.colNum-1;0<=o;o--)n.push(e*c.Tool.colNum+o);t=t.concat(w(n,this.lats))}return t},v.prototype.checkUp=function(){for(var t=[],e=0;e<c.Tool.colNum;e++){for(var n=[],o=0;o<c.Tool.rowNum;o++)n.push(e+c.Tool.rowNum*o);t=t.concat(w(n,this.lats))}return t},v.prototype.checkDown=function(){for(var t=[],e=0;e<c.Tool.colNum;e++){for(var n=[],o=c.Tool.rowNum-1;0<=o;o--)n.push(e+c.Tool.rowNum*o);t=t.concat(w(n,this.lats))}return t},v.prototype.check2048=function(){for(var t=0;t<this.lats.length;t++)if(this.lats[t]&&2048==(this.lats[t].tempType||this.lats[t].type))return!0;return!1},v.prototype.initEvents=function(){y.prototype.initEvents.call(this),this.addEventListener(FYGE.MouseEvent.MOUSE_DOWN,this.onMouseDown,this)},v.prototype.removeEvents=function(){y.prototype.removeEvents.call(this),this.removeEventListener(FYGE.MouseEvent.MOUSE_DOWN,this.onMouseDown,this)},v.prototype.unlock=function(){},v);function v(){var t=null!==y&&y.apply(this,arguments)||this;return t.score=0,t}function w(t,e){for(var n,o,r=[],i=[],s=0;s<t.length;s++)e[o=t[s]]?n&&n.startEle1.type==e[o].type?(n.startEle2=e[o],-1==r.indexOf(n)&&r.push(n),n=null,i.push(o)):i.length?(n={startEle1:e[o],endIndex:i.shift()},r.push(n),i.push(o)):n={startEle1:e[o],endIndex:o}:i.push(o);return r}e.PlayScene=g},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=(r.changeURLArg=function(t,e,n){var o=e+"=([^&]*)",r=e+"="+n;if(t.match(o)){var i="/("+e+"=)([^&]*)/gi";return t.replace(new RegExp(i),r)}return t.match("[?]")?t+"&"+r:t+"?"+r},r.readCache=function(t,e){return void 0===e&&(e="localStorage"),!!window.localStorage&&window[e].getItem(t)},r.writeCache=function(t,e,n){void 0===e&&(e="true"),void 0===n&&(n="localStorage"),window.localStorage&&window[n].setItem(t,e)},r.returnTodayTimes=function(t){var e=this.readCache("year"+t),n=this.readCache("month"+t),o=this.readCache("day"+t),r=new Date,i=r.getFullYear().toString(),s=r.getMonth().toString(),a=r.getDate().toString();return this.int(i)<=this.int(e)&&this.int(s)<=this.int(n)&&this.int(a)<=this.int(o)?this.int(this.readCache(t)):(this.writeCache("year"+t,i),this.writeCache("month"+t,s),this.writeCache("day"+t,a),this.writeCache(t,"0"),0)},r.randomT=function(t,e){return t&&"number"==typeof t.length&&t.length?t[Math.floor(Math.random()*t.length)]:("number"!=typeof e&&(e=t||1,t=0),t+Math.random()*(e-t))},r.removeEle=function(t,e){var n=e.indexOf(t);0<=n&&e.splice(n,1)},r.insert=function(t,e){for(var n=e.length-1;0<=n;n--)if(t>e[n]){e.splice(n+1,0,t);break}},r.getRandomNumber=function(t,e,n){for(var o=[],r=0;r<n;r++){var i=Math.floor(Math.random()*(e-t+1)+t);o.indexOf(i)<0?o.push(i):r--}return o},r.disturbNumberArr=function(t){t.sort((function(){return.5-Math.random()}))},r.getRandomArrayElements=function(t,e){var n,o,r=t.slice(0),i=t.length,s=i-e;if(s<=0)return r;if(e<=0)return[];for(;i-- >s;)n=r[o=Math.floor((i+1)*Math.random())],r[o]=r[i],r[i]=n;return r.slice(s)},r.getRandomArrayElementsEx=function(t,e){if(t.length<=e)return t.slice();if(e<=0)return[];for(var n=t.slice(),o=[];e--;){var r=Math.floor(Math.random()*n.length),i=n.splice(r,1)[0];o.push(i)}return o},r.int=function(t){return t>>0},r.addSpaceInString=function(t){if(!t.length||1==t.length)return t;for(var e="",n=0;n<t.length-1;n++)e=e+t[n]+" ";return e+t[t.length-1]},r.emojiReg=/[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/gi,r);function r(){}e.GTool=o},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s=n(0),a=n(5),u=(r(c,i=FYGE.Sprite),Object.defineProperty(c.prototype,"type",{get:function(){return this._type},set:function(t){this._type=t,this.texture=s.RES.getRes("ele"+t+".png")},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"tempType",{get:function(){return this._tempType},set:function(t){this._tempType=t},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"row",{get:function(){return a.Tool.indexToRc(this.index)[0]},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"col",{get:function(){return a.Tool.indexToRc(this.index)[1]},enumerable:!0,configurable:!0}),c.prototype.reset=function(t){this.type=t,this.scale.set(1,1)},c);function c(t){var e=i.call(this)||this;return e._tempType=null,e.type=t,e.anchorTexture.set(.5,.5),e}e.GameEle=u},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=n(5),r=n(10);e.moveAni=function(t,e,n,i){var s=2*e.type,a=o.Tool.getPositionByIndex(n);FYGE.Tween.get(e).to({x:a[0],y:a[1]},200).call((function(){t(),i&&FYGE.Tween.get(e).to({scaleX:.1,scaleY:.1},100).call((function(){e.type=s,e.tempType=null})).to({scaleX:1,scaleY:1},100,FYGE.Ease.backOut)})),i&&FYGE.Tween.get(i).to({x:a[0],y:a[1]},200).call((function(){i.parent.removeChild(i),r.GPool.recover("gameEle",i)}))}},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s,a=n(5),u=n(18),c=n(0),l=n(19),h=(r(p,i=u.Panel),Object.defineProperty(p.prototype,"groupNames",{get:function(){return["unlockPanel"]},enumerable:!0,configurable:!0}),p.prototype.initUi=function(){this.addChild(new l.Light).position.set(375,735),this.addChild(a.Tool.getSprite("unlockPanelBg.png")),this.closeBtn=new FYGE.Button(c.RES.getRes("comCloseBtn.png")),this.closeBtn.position.set(614,460),this.addChild(this.closeBtn),this.addChild(new FYGE.Button(c.RES.getRes("zailaiyiju.png"))).once(FYGE.MouseEvent.CLICK,this.onClick_closeBtn,this).position.set(258.5,938),this.addChild(new FYGE.Sprite(c.RES.getRes("unlock"+this.data.grade+".png"))).position.set(130.5,600)},p.prototype.start=function(t){i.prototype.start.call(this)},p.prototype.initEvents=function(){this.closeBtn.addEventListener(FYGE.MouseEvent.CLICK,this.onClick_closeBtn,this)},p.prototype.onClick_closeBtn=function(){this.data.closeFun(),this.hidePanel()},p.prototype.removeEvents=function(){this.closeBtn.removeEventListener(FYGE.MouseEvent.CLICK,this.onClick_closeBtn,this)},p);function p(){return null!==i&&i.apply(this,arguments)||this}e.UnlockPanel=h,r((function(t){var e=s.call(this)||this,n=new FYGE.Sprite(c.RES.getRes("unlockMsg.png"));e.addChild(n);for(var o={},r=0;r<10;r++)o[r]=c.RES.getRes("n"+r+".png");var i=new FYGE.BitmapText(o);i.textAlign=FYGE.TEXT_ALIGN.LEFT,i.text=t+"",e.addChild(i);var a=n.width+i.width;return n.position.set((750-a)/2,548),i.position.set(n.x+n.width,552),e}),s=FYGE.Container)},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s=n(9),a=(r(u,i=s.Module),u.prototype.showAni=function(){var t,e=this;this.isShowing||(this.isShowing=!0,t=this.y||0,this.y=-200,FYGE.Tween.get(this).to({y:t},500,FYGE.Ease.quartOut).call((function(){e.isShowing=!1})))},u.prototype.initEvents=function(){var t=this;this.closeBtns.forEach((function(e){e&&e.addEventListener(FYGE.MouseEvent.CLICK,t.hidePanel,t)}))},u.prototype.removeEvents=function(){var t=this;this.closeBtns.forEach((function(e){e&&e.removeEventListener(FYGE.MouseEvent.CLICK,t.hidePanel,t)}))},Object.defineProperty(u.prototype,"closeBtns",{get:function(){return[this.closeBtn]},enumerable:!0,configurable:!0}),u.prototype.hidePanel=function(){this.destroy()},u);function u(){return null!==i&&i.apply(this,arguments)||this}e.Panel=a},function(t,e,n){"use strict";var o,r=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i,s=n(0),a=(r(u,i=FYGE.Sprite),u);function u(){var t=i.call(this)||this;return t.texture=s.RES.getRes("light.png"),t.anchorTexture.set(.5,.5),t.addEventListener(FYGE.Event.ENTER_FRAME,(function(){t.rotation+=1}),t),t}e.Light=a},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ResJson={groups:[{keys:"comCloseBtn.png,toastBg.png,waitingBg.png,waitingRot.png",name:"common",atlas:{"comCloseBtn.png":{x:646,y:60,w:48,h:48,ox:0,oy:0,sw:48,sh:48,ro:!1},"toastBg.png":{x:184,y:2,w:460,h:130,ox:0,oy:0,sw:460,sh:130,ro:!1},"waitingBg.png":{x:2,y:2,w:160,h:180,ox:0,oy:0,sw:160,sh:180,ro:!0},"waitingRot.png":{x:646,y:2,w:56,h:56,ox:0,oy:0,sw:56,sh:56,ro:!1}}},{keys:"ele1024.png,ele128.png,ele16.png,ele2.png,ele2048.png,ele256.png,ele32.png,ele4.png,ele512.png,ele64.png,ele8.png,guideArrow.png,guideFinger.png,playBg.jpg",name:"playScene",atlas:{"ele1024.png":{x:2,y:858,w:100,h:99,ox:0,oy:0,sw:100,sh:99,ro:!1},"ele128.png":{x:2,y:385,w:106,h:92,ox:0,oy:0,sw:106,sh:92,ro:!1},"ele16.png":{x:2,y:755,w:102,h:101,ox:0,oy:0,sw:102,sh:101,ro:!1},"ele2.png":{x:2,y:664,w:103,h:89,ox:0,oy:0,sw:103,sh:89,ro:!1},"ele2048.png":{x:2,y:93,w:110,h:92,ox:0,oy:0,sw:110,sh:92,ro:!1},"ele256.png":{x:2,y:571,w:104,h:91,ox:0,oy:0,sw:104,sh:91,ro:!1},"ele32.png":{x:2,y:187,w:108,h:92,ox:0,oy:0,sw:108,sh:92,ro:!1},"ele4.png":{x:2,y:959,w:129,h:92,ox:0,oy:0,sw:129,sh:92,ro:!0},"ele512.png":{x:2,y:479,w:106,h:90,ox:0,oy:0,sw:106,sh:90,ro:!1},"ele64.png":{x:2,y:281,w:107,h:102,ox:0,oy:0,sw:107,sh:102,ro:!1},"ele8.png":{x:2,y:2,w:111,h:89,ox:0,oy:0,sw:111,sh:89,ro:!1},"guideArrow.png":{x:82,y:1090,w:51,h:14,ox:0,oy:0,sw:51,sh:14,ro:!0},"guideFinger.png":{x:2,y:1090,w:53,h:78,ox:0,oy:0,sw:53,sh:78,ro:!0}}},{keys:"silverDraft.png,startBg.jpg,startBtn.png",name:"startScene",atlas:{"silverDraft.png":{x:2,y:2,w:112,h:132,ox:0,oy:0,sw:112,sh:132,ro:!0},"startBtn.png":{x:136,y:2,w:447,h:106,ox:0,oy:0,sw:447,sh:106,ro:!1}}},{keys:"light.png,unlock1024.png,unlock128.png,unlock16.png,unlock2.png,unlock2048.png,unlock256.png,unlock32.png,unlock512.png,unlock64.png,unlock8.png,unlockMsg.png,unlockPanelBg.png,zailaiyiju.png",name:"unlockPanel",atlas:{"light.png":{x:2,y:2,w:1158,h:1190,ox:0,oy:90,sw:1162,sh:1280,ro:!0},"unlock1024.png":{x:1194,y:754,w:227,h:191,ox:143,oy:93,sw:449,sh:363,ro:!1},"unlock128.png":{x:1868,y:2,w:197,h:165,ox:142,oy:101,sw:449,sh:363,ro:!0},"unlock16.png":{x:1835,y:955,w:183,h:179,ox:150,oy:87,sw:449,sh:363,ro:!1},"unlock2.png":{x:1868,y:201,w:185,h:163,ox:143,oy:96,sw:449,sh:363,ro:!0},"unlock2048.png":{x:1423,y:754,w:229,h:187,ox:127,oy:74,sw:449,sh:363,ro:!1},"unlock256.png":{x:1853,y:754,w:199,h:169,ox:137,oy:96,sw:449,sh:363,ro:!0},"unlock32.png":{x:1632,y:943,w:201,h:175,ox:139,oy:92,sw:449,sh:363,ro:!1},"unlock512.png":{x:1423,y:943,w:207,h:171,ox:127,oy:87,sw:449,sh:363,ro:!1},"unlock64.png":{x:1654,y:754,w:197,h:187,ox:134,oy:81,sw:449,sh:363,ro:!1},"unlock8.png":{x:1194,y:947,w:225,h:179,ox:101,oy:88,sw:449,sh:363,ro:!1},"unlockMsg.png":{x:1868,y:388,w:276,h:40,ox:0,oy:0,sw:276,sh:40,ro:!0},"unlockPanelBg.png":{x:1194,y:2,w:672,h:750,ox:30,oy:386,sw:750,sh:1624,ro:!1},"zailaiyiju.png":{x:1910,y:388,w:233,h:77,ox:0,oy:0,sw:233,sh:77,ro:!0}}}],path:"https://yun.duiba.com.cn/db_games/activity/anything/1590719783/resource/"}},function(t,e,n){"use strict";var o=this&&this.__awaiter||function(t,e,n,o){return new(n=n||Promise)((function(r,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){t.done?r(t.value):new n((function(e){e(t.value)})).then(s,a)}u((o=o.apply(t,e||[])).next())}))},r=this&&this.__generator||function(t,e){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s={next:a(0),throw:a(1),return:a(2)};return"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=0<(r=i.trys).length&&r[r.length-1])&&(6===s[0]||2===s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var i,s=n(4);(i=e.TbNetName||(e.TbNetName={})).aaa="aaa",i.getCredits="getCredits",i.startGame="startGame",i.submit="submit",i.getTools="getTools",i.getTaskList="getTaskList",i.getToolsByType="getToolsByType",i.useTools="useTools";var a,u={};e.sendTbNet=function(t,e,n,i){void 0===i&&(i=!1);var l=s.wait((function(){i||s.showToast("网络超时"),n(!1)}),5e3);my?(a=a||getApp().cloud.function).invoke("becheery",e,t).then((function(e){s.clearWait(l),u[t]=e,i||e.success||s.showToast(c[e.code]||e.message||"网络异常"),n(e.success,e)})):function(t){return o(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,fetch(t)];case 1:return[4,e.sent().json()];case 2:return[2,e.sent()]}}))}))}("../../mock/miniTb/"+t+".json").then((function(t){s.clearWait(l),u[name]=t,i||t.success||s.showToast(t.message||"网络异常"),n(t.success,t)}),(function(){}))},e.getTbData=function(t){return u[t]||null},e.destroyNetData=function(){u={}};var c={210001:"服务器异常",210002:"用户不存在",210003:"邀请已达上限",210004:"无法邀请自己",210006:"该活动ID无效",210009:"该活动暂未开始",210010:"该分享ID不存在",210012:"该用户暂未获奖",210013:"领取失败",210015:"该活动已删除",210016:"该活动已经结束",210017:"该奖品已达领取上线",210018:"请先分享好友",210019:"暂有奖品未领取",210020:"暂有奖品未完成",210021:"请先玩一局游戏",210022:"请先选择奖品",210023:"领取失败,库存不足",210024:"请先成为会员",210025:"奖品已经过期",210026:"不能重复助力",210028:"请至我的奖品页重新领取"}}],t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)t.d(o,r,function(t){return e[t]}.bind(null,r));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},t.p="",t(t.s=11);function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var e,n}));
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "tbgame",
"version": "1.0.0",
"description": "",
"main": "index.html",
"devDependencies": {
"ali-oss": "^4.11.4",
"chalk": "^2.3.0",
"co": "^4.6.0",
"del": "^2.2.1",
"fs": "0.0.2",
"imagemin": "^7.0.1",
"imagemin-mozjpeg": "^8.0.0",
"imagemin-pngquant": "^8.0.0",
"mock-webpack-plugin": "^2.0.0",
"path": "^0.12.7",
"progress": "^2.0.0",
"ts-loader": "^4.0.0",
"tslint": "^5.9.1",
"typescript": "^2.7.2",
"webpack": "^4.1.0",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.0",
"webpack-merge": "^4.1.2",
"uglifyjs-webpack-plugin": "^2.1.2"
},
"dependencies": {},
"scripts": {
"flushRes": "node scripts/flushRes",
"handleRes": "node scripts/delRel && node scripts/copyRes && node scripts/createTm && node scripts/textureMerge && node scripts/delTm && node scripts/imageMin",
"upload": "node scripts/upload",
"build": "npm run handleRes && node scripts/mergeJson && npm run upload && npm run buildTS",
"watch": "webpack --watch",
"dev": "webpack-dev-server --open --config webpack.dev.js --host 0.0.0.0",
"buildTS": "webpack --config webpack.prod.js && node scripts/mergeJs",
"copyJs": "node scripts/copyJs"
},
"author": "MrKwon",
"license": "ISC"
}
\ No newline at end of file
{
"type": "activity",
"name": "anything"
}
\ No newline at end of file
{
"comCloseBtn.png": {
"x": 646,
"y": 60,
"w": 48,
"h": 48,
"ox": 0,
"oy": 0,
"sw": 48,
"sh": 48,
"ro": false
},
"toastBg.png": {
"x": 184,
"y": 2,
"w": 460,
"h": 130,
"ox": 0,
"oy": 0,
"sw": 460,
"sh": 130,
"ro": false
},
"waitingBg.png": {
"x": 2,
"y": 2,
"w": 160,
"h": 180,
"ox": 0,
"oy": 0,
"sw": 160,
"sh": 180,
"ro": true
},
"waitingRot.png": {
"x": 646,
"y": 2,
"w": 56,
"h": 56,
"ox": 0,
"oy": 0,
"sw": 56,
"sh": 56,
"ro": false
}
}
\ No newline at end of file
{
"btn_浠撳簱.png": {
"x": 1964,
"y": 2,
"w": 121,
"h": 133,
"ox": 0,
"oy": 0,
"sw": 121,
"sh": 133,
"ro": false
},
"btn_鍏戞崲璁板綍.png": {
"x": 2960,
"y": 2,
"w": 100,
"h": 104,
"ox": 0,
"oy": 0,
"sw": 100,
"sh": 104,
"ro": false
},
"btn_鍟嗗簵.png": {
"x": 2208,
"y": 2,
"w": 119,
"h": 133,
"ox": 0,
"oy": 0,
"sw": 119,
"sh": 133,
"ro": false
},
"btn_瑙勫垯.png": {
"x": 2765,
"y": 2,
"w": 99,
"h": 107,
"ox": 0,
"oy": 0,
"sw": 99,
"sh": 107,
"ro": false
},
"btn_棰嗘按婊�.png": {
"x": 2087,
"y": 2,
"w": 119,
"h": 133,
"ox": 0,
"oy": 0,
"sw": 119,
"sh": 133,
"ro": false
},
"game_鏀惰幏.png": {
"x": 3246,
"y": 97,
"w": 82,
"h": 93,
"ox": 0,
"oy": 0,
"sw": 82,
"sh": 93,
"ro": true
},
"game_娴囨按.png": {
"x": 3154,
"y": 2,
"w": 90,
"h": 101,
"ox": 0,
"oy": 0,
"sw": 90,
"sh": 101,
"ro": false
},
"game_绉嶆.png": {
"x": 3062,
"y": 2,
"w": 90,
"h": 101,
"ox": 0,
"oy": 0,
"sw": 90,
"sh": 101,
"ro": false
},
"骞垮憡.png": {
"x": 1828,
"y": 2,
"w": 103,
"h": 156,
"ox": 0,
"oy": 0,
"sw": 103,
"sh": 156,
"ro": false
},
"鐢ㄦ埛_bg.png": {
"x": 2329,
"y": 2,
"w": 434,
"h": 129,
"ox": 0,
"oy": 0,
"sw": 434,
"sh": 129,
"ro": false
},
"鐢ㄦ埛_澶村儚.png": {
"x": 3246,
"y": 2,
"w": 93,
"h": 93,
"ox": 0,
"oy": 0,
"sw": 93,
"sh": 93,
"ro": false
},
"鐢ㄦ埛_姘�.png": {
"x": 2024,
"y": 137,
"w": 39,
"h": 48,
"ox": 0,
"oy": 0,
"sw": 39,
"sh": 48,
"ro": true
},
"鐢癬鍒濆.png": {
"x": 812,
"y": 2,
"w": 403,
"h": 177,
"ox": 0,
"oy": 0,
"sw": 403,
"sh": 177,
"ro": false
},
"鐢癬绉嶆.png": {
"x": 407,
"y": 2,
"w": 403,
"h": 177,
"ox": 0,
"oy": 0,
"sw": 403,
"sh": 177,
"ro": false
},
"鐢癬閫夋嫨.png": {
"x": 2,
"y": 2,
"w": 403,
"h": 177,
"ox": 0,
"oy": 0,
"sw": 403,
"sh": 177,
"ro": false
},
"绉嶆妗哶bg.png": {
"x": 1217,
"y": 2,
"w": 609,
"h": 160,
"ox": 0,
"oy": 0,
"sw": 609,
"sh": 160,
"ro": false
},
"绉嶆妗哶left.png": {
"x": 1828,
"y": 160,
"w": 19,
"h": 34,
"ox": 0,
"oy": 0,
"sw": 19,
"sh": 34,
"ro": true
},
"绉嶆妗哶right.png": {
"x": 1864,
"y": 160,
"w": 18,
"h": 34,
"ox": 0,
"oy": 0,
"sw": 18,
"sh": 34,
"ro": true
},
"绉嶆妗哶灞辨牳妗�.png": {
"x": 2119,
"y": 137,
"w": 35,
"h": 44,
"ox": 0,
"oy": 0,
"sw": 35,
"sh": 44,
"ro": true
},
"绉嶆妗哶寮€蹇冩灉.png": {
"x": 1933,
"y": 143,
"w": 35,
"h": 46,
"ox": 0,
"oy": 0,
"sw": 35,
"sh": 46,
"ro": true
},
"绉嶆妗哶鏉挎牀.png": {
"x": 1981,
"y": 137,
"w": 42,
"h": 41,
"ox": 0,
"oy": 0,
"sw": 42,
"sh": 41,
"ro": true
},
"绉嶆妗哶鐡滃瓙.png": {
"x": 2414,
"y": 133,
"w": 26,
"h": 48,
"ox": 0,
"oy": 0,
"sw": 26,
"sh": 48,
"ro": true
},
"绉嶆妗哶鑵版灉.png": {
"x": 2074,
"y": 137,
"w": 38,
"h": 43,
"ox": 0,
"oy": 0,
"sw": 38,
"sh": 43,
"ro": true
},
"绉嶆妗哶鑺辩敓.png": {
"x": 2363,
"y": 133,
"w": 26,
"h": 49,
"ox": 0,
"oy": 0,
"sw": 26,
"sh": 49,
"ro": true
},
"绉嶆妗哶琚嬪瓙.png": {
"x": 2866,
"y": 2,
"w": 107,
"h": 92,
"ox": 0,
"oy": 0,
"sw": 107,
"sh": 92,
"ro": true
},
"杩涘害_bg.png": {
"x": 2165,
"y": 137,
"w": 196,
"h": 31,
"ox": 0,
"oy": 0,
"sw": 196,
"sh": 31,
"ro": false
},
"杩涘害_fill.png": {
"x": 1933,
"y": 2,
"w": 139,
"h": 29,
"ox": 0,
"oy": 0,
"sw": 139,
"sh": 29,
"ro": true
}
}
\ No newline at end of file
{
"groups": [
{
"keys": "comCloseBtn.png,toastBg.png,waitingBg.png,waitingRot.png",
"name": "common",
"atlas": "common.json"
},
{
"keys": "btn_仓库.png,btn_兑换记录.png,btn_商店.png,btn_规则.png,btn_领水滴.png,game_bg.jpg,game_收获.png,game_浇水.png,game_种植.png,广告.png,用户_bg.png,用户_头像.png,用户_水.png,田_初始.png,田_种植.png,田_选择.png,种植框_bg.png,种植框_left.png,种植框_right.png,种植框_山核桃.png,种植框_开心果.png,种植框_板栗.png,种植框_瓜子.png,种植框_腰果.png,种植框_花生.png,种植框_袋子.png,进度_bg.png,进度_fill.png",
"name": "gameScene",
"atlas": "gameScene.json"
}
],
"path": "./resource/"
}
\ No newline at end of file
{
"groups": [
{
"keys": "comCloseBtn.png,toastBg.png,waitingBg.png,waitingRot.png",
"name": "common"
},
{
"keys": "btn_仓库.png,btn_兑换记录.png,btn_商店.png,btn_规则.png,btn_领水滴.png,game_bg.jpg,game_收获.png,game_浇水.png,game_种植.png,广告.png,用户_bg.png,用户_头像.png,用户_水.png,田_初始.png,田_种植.png,田_选择.png,种植框_bg.png,种植框_left.png,种植框_right.png,种植框_山核桃.png,种植框_开心果.png,种植框_板栗.png,种植框_瓜子.png,种植框_腰果.png,种植框_花生.png,种植框_袋子.png,进度_bg.png,进度_fill.png",
"name": "gameScene"
}
],
"path": "./resource/"
}
\ No newline at end of file
var fs = require("fs");
// fs.writeFileSync(
// "./released/output.js",
// fs.readFileSync("./output.js")
// )
var endPath = 'D:/duibaGame/测试项目0527/taobaominiTest/client/pages/index1/';
var version = Math.round(new Date().getTime() / 1000);
fs.writeFileSync(endPath + "output." + version + ".js", fs.readFileSync("./released/output.js"));
// console.log("js覆盖完成")
console.log(`版本号:
${version}`)
\ No newline at end of file
var fs = require('fs');
var path = require("path");
function writeFile(p, text) {
fs.writeFile(p, text, function (err) {
// if (!err)
// console.log("写入成功!")
})
}
//递归创建目录 同步方法
function mkdirsSync(dirname) {
if (fs.existsSync(dirname)) {
return true;
} else {
if (mkdirsSync(path.dirname(dirname))) {
// console.log("mkdirsSync = " + dirname);
fs.mkdirSync(dirname);
return true;
}
}
}
function _copy(src, dist) {
var paths = fs.readdirSync(src)
paths.forEach(function (p) {
var _src = src + '/' + p;
var _dist = dist + '/' + p;
var stat = fs.statSync(_src)
if (stat.isFile()) {// 判断是文件还是目录
fs.writeFileSync(_dist, fs.readFileSync(_src));
} else if (stat.isDirectory()) {
copyDir(_src, _dist)// 当是目录是,递归复制
}
})
}
/*
* 复制目录、子目录,及其中的文件
* @param src {String} 要复制的目录
* @param dist {String} 复制到目标目录
*/
function copyDir(src, dist) {
var b = fs.existsSync(dist)
// console.log("dist = " + dist)
if (!b) {
// console.log("mk dist = ",dist)
mkdirsSync(dist);//创建目录
}
// console.log("_copy start")
_copy(src, dist);
}
function createDocs(src, dist, callback) {
// console.log("createDocs...")
copyDir(src, dist);
// console.log("copyDir finish exec callback")
if (callback) {
callback();
}
}
createDocs("./resource", "./released/resource/", function () {
console.log("资源拷贝成功")
})
\ No newline at end of file
var fs = require("fs");
var iconv = require('iconv-lite');
var del = require('del');
var readPath = "./released/resource/";
//读取json文件
var data = iconv.decode(fs.readFileSync(readPath + "res.json"), "utf-8");
//反序列化
data = JSON.parse(data); //eval(data)
//取出里面的图片,暂存到tm文件夹中,同时删除文件夹里的,和本身json里的
if (!fs.existsSync("./released/tm"))
fs.mkdirSync("./released/tm");
for (var i = 0; i < data.groups.length; i++) {
var name = data.groups[i].name;
var path = readPath + name + "/";
var arr = data.groups[i].keys.split(",");
//取出图片的,注意已排除jpg
var images = arr.filter((f) => { return (f.substr(-4) == ".png" /*|| f.substr(-4) == ".jpg"*/) })
//没有图片,
if (!images.length) continue;
//去掉原先数据里的
// data.groups[i].keys = arr.filter((f) => { return (f.substr(-4) != ".png" && f.substr(-4) != ".jpg") }).join(",");
//添加新的json,加到atlas里
// if (data.groups[i].keys) data.groups[i].keys += ","
data.groups[i].atlas = name + ".json"
//读取原先路径里的图片,写到tm的文件夹里,并删除原文件夹里的图片
fs.mkdirSync("./released/tm/" + name);
for (var m = 0; m < images.length; m++) {
fs.writeFileSync(
"./released/tm/" + name + "/" + images[m],
fs.readFileSync(path + images[m])
)
del(path + images[m])
}
}
//序列化
fs.writeFileSync(readPath + "res.json", JSON.stringify(data, "", "\t"));
var fs = require("fs");
var del = require('del');
function delDir(path, isSelf) {
let files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach((file, index) => {
let curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) {
delDir(curPath); //递归删除文件夹
} else {
fs.unlinkSync(curPath); //删除文件
}
});
if (!isSelf) fs.rmdirSync(path);
}
}
var paths = './released/';//设置删除路径
// delDir(paths, true);//删除文件夹
del(paths).then(() => {
fs.mkdirSync(paths);
}).catch(()=>{
fs.mkdirSync(paths);
})
// var tasks = [];
// function addTask(task) {
// tasks.push(task);
// }
// function next() {
// if (tasks.length > 0) {
// tasks.shift()();
// } else {
// return;
// }
// }
// var delRel = function () {
// del(paths).then(() => {
// // console.log("del")
// next();
// })
// }
// var createRel = function () {
// fs.mkdirSync(paths);
// // console.log("create")
// next();
// }
// addTask(delRel)
// addTask(createRel)
// next();
\ No newline at end of file
var del = require('del');
del("./released/tm")
\ No newline at end of file
//生成res.json
//遍历资源文件夹,生成
var fs = require('fs');
var path = require("path");
var readPath = "./resource/"
var files = fs.readdirSync(readPath);
var obj = { groups: [] };//每项包括keys合name
files.forEach(function (file) {
//路径
let fPath = path.join(readPath, file);
//只处理文件夹
if (fs.statSync(fPath).isDirectory()) {
//继续读每个子文件夹,json和png名字有相同的,只留json,
var sonFiles = fs.readdirSync(fPath);
//没有文件
if (!sonFiles.length) return
//取出所有json
var jsons = sonFiles.filter((f) => { return f.substr(-5) == ".json" })
sonFiles = sonFiles.filter((f) => { return jsons.indexOf(f.substring(0, f.length - 4) + ".json") == -1 })
sonFiles = sonFiles.filter((f) => { return f != '.DS_Store' })
var group = {
keys: "",
name: file
}
for (var i = 0; i < sonFiles.length; i++) {
if (i != 0) group.keys += ",";
group.keys += sonFiles[i]
}
obj.groups.push(group)
}
})
obj.path="./resource/"
console.log("资源更新完成")
//生成json
fs.writeFileSync(readPath + "res.json", JSON.stringify(obj, "", "\t"));
//TS也更新
var endPath = './src/';
var endFile = `export const ResJson = ${JSON.stringify(obj, "", "\t")}`
fs.writeFileSync(endPath + "ResJson.ts", endFile);
const imagemin = require('imagemin');
// const imageminJpegtran = require('imagemin-jpegtran');imagemin-mozjpeg
const imageminJpegtran = require('imagemin-mozjpeg');
const imageminPngquant = require('imagemin-pngquant');
var fs = require('fs');
var path = require('path');
// 要处理的图片文件夹路径
var altasPath = "./released/resource/"
var folders = getFolders(altasPath);
folders.map(async function (folder) {
const files = await imagemin([altasPath + folder + '/*.{png,jpg}'], {
destination: altasPath + folder,
plugins: [
imageminJpegtran(),
imageminPngquant({
quality: [0.6, 0.8]
})
]
});
if (files && files.length) {
files.forEach((v) => {
console.log("压缩图片成功:", v.sourcePath.substring(v.sourcePath.lastIndexOf("/") + 1, v.sourcePath.length))
})
}
});
function getFolders(dir) {
return fs.readdirSync(dir)
.filter(function (file) {
return fs.statSync(path.join(dir, file)).isDirectory();
});
}
\ No newline at end of file
var fs = require("fs");
// fs.writeFileSync(
// "./released/output.js",
// fs.readFileSync("./output.js")
// )
var endPath = './released/';
fs.writeFileSync(endPath + "output.js",
'import * as FYGE from "fyge-tbmini";\n' +
'import * as SvgaParser from "svga-parser";\n' +
fs.readFileSync("./output.js"));
console.log("js生成")
var fs = require("fs");
var path = require('path');
var del = require('del');
var iconv = require('iconv-lite');
const join = require('path').join;
//写入图集的文件夹,将文件夹内所有的json合并,并删除原先json
var readPath = "./released/resource/";
//读取json文件
var data = iconv.decode(fs.readFileSync(readPath + "res.json"), "GBK");
//反序列化
data = JSON.parse(data);
var files = fs.readdirSync(readPath);
// let obj = {};
let count = 0;
let countAll = files.length
files.forEach(function (file) {
//路径
let fPath = join(readPath, file);
//只处理文件夹
if (fs.statSync(fPath).isDirectory()) {
//读文件夹fPath里的json文件
fs.readdir(fPath, function (err, files) {
if (err) {
console.warn(err)
} else {
//遍历
for (var i = 0; i < files.length; i++) {
let filename = files[i];
if (filename.indexOf(".json") == -1) continue
//获取当前文件的绝对路径
let filedir = path.join(fPath, filename);
let content = fs.readFileSync(filedir, 'utf-8');
let group = getGroupByName(filename.replace(".json", ""), data.groups)
group.atlas = JSON.parse(content);
//删除原先json
del(filedir)
if (++count == countAll) endFun();
}
//序列化,不格式化,节省内存
}
})
} else {
if (++count == countAll) endFun();
}
})
function endFun() {
console.log("资源配置js生成完毕")
// del(join(readPath, "res.json"))
fs.writeFileSync(readPath + "res.json", JSON.stringify(data, "", "\t"));
}
function getGroupByName(name, groups) {
var group;
for (var i = 0; i < groups.length; i++) {
if (groups[i].name === name) {
group = groups[i];
break;
}
}
return group
}
var fs = require("fs");
var exec = require('child_process').exec;
var iconv = require('iconv-lite');
var del = require('del');
const join = require('path').join;
//写入图集的文件夹
var outPath = "./released/resource/";
//读取散图的文件夹
var readPath = "./released/tm/";
var files = fs.readdirSync(readPath);
files.forEach(function (file) {
//路径
let fPath = join(readPath, file);
//只处理文件夹
if (fs.statSync(fPath).isDirectory()) {
//判断文件夹内是否有图片
if (!judgeHasImage(fPath)) return;
var cli = getTmCmd(fPath, outPath + file + "/", file);
//如果文件夹不存在
if (!fs.existsSync(outPath + file)) {
fs.mkdirSync(outPath + file);
}
else {
//图集文件存在就删除
if (fs.existsSync(outPath + file + "/" + file + ".json")) {
del(outPath + file + "/" + file + ".json")
}
if (fs.existsSync(outPath + file + "/" + file + ".png")) {
del(outPath + file + "/" + file + ".png")
}
}
//执行合图指令
exec(cli, { encoding: 'utf8' }, function (err, stdout, stderr) {
if (err) {
console.log(err);
return;
}
// console.log('stdout:' + stdout);
// console.log('stderr:' + stderr);
console.log('生成图集:' + file);
var pathname = outPath + file + "/" + file + ".json";
//有中文命名时处理
var data = iconv.decode(fs.readFileSync(pathname), "GBK");
//反序列化
data = JSON.parse(data); //eval(data)
//重写数据
var obj = {};
var frames = data.frames;
var frameKeys = Object.keys(frames);
for (var i = 0; i < frameKeys.length; i++) {
const name = frameKeys[i];
const data = frames[name];
if (!data.frame) continue;
const sourceSize = data.trimmed !== false && data.sourceSize
? data.sourceSize : data.frame;
obj[name] = {
"x": data.frame.x,
"y": data.frame.y,
"w": data.frame.w,
"h": data.frame.h,
"ox": data.trimmed ? data.spriteSourceSize.x : 0,
"oy": data.trimmed ? data.spriteSourceSize.y : 0,
"sw": sourceSize.w,
"sh": sourceSize.h,
"ro": data.rotated,
}
}
//序列化,不格式化,节省内存
fs.writeFileSync(pathname, JSON.stringify(obj, "", "\t"));
})
}
})
//不同版本参数可能不同,具体情况具体分析
function getTmCmd(src, outPath, name) {
var cli =
'TexturePacker ' + //基础指令
src + //要合图集的文件夹路径
' --format json' + //图集数据格式
' --max-size 4096' + //最大尺寸
' --allow-free-size' +//允许使用最小尺寸输出,webgl最好别设置,现在小程序只有canvas模式,所以用最小尺寸导出吧
' --shape-padding 2' + //图片间隔
' --border-padding 2' + //边界间隔
' --enable-rotation' + //旋转 diable-rotation
' --opt RGBA8888' + //图片像素格式
' --trim' + //裁切透明像素 no-trim
' --sheet ' + outPath + name + '.png' + //图片名字
' --data ' + outPath + name + '.json'; //数据名字
return cli
}
/**
* 对文件使用utf8编码
* @param {string} pathname
*/
function applyUtf8(pathname) {
fs.writeFile(pathname, iconv.decode(fs.readFileSync(pathname), "GBK"), {
encoding: "UTF8"
}, function (err) {
if (err) {
throw err;
}
});
}
/**
* 判断文件夹内是否有图片
* @param {*} path
*/
function judgeHasImage(path) {
var files = fs.readdirSync(path);
for (var i = 0; i < files.length; i++) {
var itm = files[i]
var stat = fs.statSync(path + "/" + itm);
if (stat.isDirectory()) {
//递归读取文件
if (judgeHasImage(path + "/" + itm + "/")) return true;
} else {
if (itm.substr(-4) == ".jpg" || itm.substr(-4) == ".png") return true;
}
}
return false;
}
\ No newline at end of file
var fs = require('fs');
var path = require('path');
const co = require('co');
const OSS = require('ali-oss');
const chalk = require('chalk');
const ProgressBar = require('progress');
class TuiaAutoUpload {
constructor(props, type) {
this.type = type;
const defaultOptions = {
dir: undefined,
originDir: undefined
}
this.options = Object.assign({}, defaultOptions, props);
if (!this.options.dir || !this.options.originDir) {
console.log(chalk.red('缺少参数,初始化失败'))
return;
}
this.init();
}
init() {
var _this = this;
this.client = new OSS({
region: 'oss-cn-hangzhou',
accessKeyId: 'LTAI4Fw25WcfcGv7FvcHoiHK',
accessKeySecret: 'NZk1NtT9J5HFaAolNbtQdzTzLLvLYm',
bucket: _this.type === 'prod' ? 'duiba' : 'daily-duiba'
});
this.bar = new ProgressBar(chalk.yellow(` 文件上传中 [:bar] :current/${this.files().length} :percent :elapseds`), {
complete: '●',
incomplete: '○',
width: 20,
total: this.files().length,
callback: () => {
console.log(chalk.green('\n All complete.'));
console.log(chalk.blue(`\n 本次队列文件共${this.files().length}个,已存在文件${this.existFiles}个,上传文件${this.uploadFiles}个,上传失败文件${this.errorFiles}个\n`));
}
})
return this;
}
files() {
var _this = this;
if (this._files) return this._files;
this._files = [];
/**
* 文件遍历方法
* @param filePath 需要遍历的文件路径
*/
function fileDisplay(filePath) {
//根据文件路径读取文件,返回文件列表
var files = fs.readdirSync(filePath);
files.forEach(function (filename) {
//获取当前文件的绝对路径
var filedir = path.join(filePath, filename);
//根据文件路径获取文件信息,返回一个fs.Stats对象
var stats = fs.statSync(filedir);
var isFile = stats.isFile();//是文件
var isDir = stats.isDirectory();//是文件夹
if (isFile) {
var sep = '/';
if ('win32' == process.platform)
sep = '\\';
var newDirArr = filedir.split(sep);
newDirArr.shift();
_this._files.push(newDirArr.join('/'));
}
if (isDir) {
fileDisplay(filedir);//递归,如果是文件夹,就继续遍历该文件夹下面的文件
}
});
}
//调用文件遍历方法
fileDisplay(this.options.dir);
return this._files;
}
start() {
this.files().map((file, index) => {
let _this = this;
const path1 = path.join(path.resolve(__dirname, '..'), 'released', file);
let originFile;
this.existFiles = 0;
this.uploadFiles = 0;
this.errorFiles = 0;
co(function* () {
const originPath = `${_this.options.originDir}${file}`;
try {
originFile = yield _this.client.head(originPath);
} catch (error) {
originFile = error;
}
if (_this.type === 'prod') {
if (originFile.status === 404) {
yield _this.client.put(originPath, path1);
_this.uploadFiles += 1;
} else {
_this.existFiles += 1;
}
} else if (_this.type === 'dev') {
if (originFile.status === 404 || originFile.status === 200) {
_this.existFiles += 1;
}
yield _this.client.put(originPath, path1, {
headers: {
'Cache-Control': 'no-cache'
}
})
_this.uploadFiles += 1;
}
_this.bar.tick();
}).catch(function (err) {
_this.errorFiles += 1;
console.log(err);
});
});
}
}
const configFileName = 'project.json';
if (!fs.existsSync(configFileName)) {
throw new Error(`${configFileName}不存在.`)
}
let config = fs.readFileSync('project.json');
config = JSON.parse(config + '');
if (!config.type) {
throw new Error(`${configFileName}的type不存在.`)
}
if (!config.name) {
throw new Error(`${configFileName}的name不存在.`)
}
const now = new Date();
const version = Math.round(now.getTime() / 1000);
console.log(`版本号:
${version}`)
const autoupload = new TuiaAutoUpload({
dir: './released/',
// dir: path.join(__dirname, './released/'),
originDir: `/db_games/${config.type}/${config.name}/${version}/`
}, "prod")
autoupload.start()
var iconv = require('iconv-lite');
var readPath = "./released/resource/";
//读取json文件
var data = iconv.decode(fs.readFileSync(readPath + "res.json"), "GBK");
//反序列化
data = JSON.parse(data);
data.path = `https://yun.duiba.com.cn/db_games/${config.type}/${config.name}/${version}/resource/`
//写入目标文件夹,可配置,每个项目必须修改,或者直接和project的保持一致(淘宝项目文件固定后)
var endPath = './src/';
var endFile = `export const ResJson = ${JSON.stringify(data, "", "\t")}`
fs.writeFileSync(endPath + "ResJson.ts", endFile);
\ No newline at end of file
import { Tool } from "./Tools";
import { layers, destroyLayers } from "../module/views/layers";
import { RES } from "../module/RES";
import { changeScene, showWaiting, destroyAllCtrls } from "../module/ctrls";
import { ResJson } from "./ResJson";
import { destroyNetData, sendTbNet, TbNetName } from "./TaoBaoNet";
import { GameScene } from "./scenes/GameScene";
/**
* 全局事件,为了和小程序交互
* 有可能多处页面用到,所以单开
*/
export const GDispatcher = new FYGE.EventDispatcher();
export class Main {
//主舞台
stage: FYGE.Stage;
private requestID;
private _pause: boolean;
constructor(canvas: HTMLCanvasElement) {
var sysInfo;
//@ts-ignore 存在my就初始化
if (my) {
FYGE.initedByCanvas(canvas)
//@ts-ignore 存在my就初始化
sysInfo = my.getSystemInfoSync()
}
var stage = new FYGE.Stage(
canvas,
750,
1624,
sysInfo && sysInfo.windowWidth || document.body.clientWidth,
sysInfo && sysInfo.windowHeight || document.body.clientHeight,
FYGE.RENDERER_TYPE.CANVAS
);
this.stage = stage;
//开始循环
// FYGE.Stage.flushAll();
//stage初始化
stage.addEventListener(FYGE.Event.INIT_STAGE, this.onAddToStage, this);
//帧率
// var stats = new FYGE.Stats("canva4stats");
//循环
var self = this;
// console.log(FYGE)
loop();
function loop() {
if (!self._pause) {
// stats.begin();
FYGE.Tween.flush()
stage.flush();
// stats.end();
}
//@ts-ignore
self.requestID = FYGE.getRequestAnimationFrame()(loop);
}
}
private async onAddToStage() {
//初始化层级
layers.init(this.stage);
console.log("初始化层级完成")
//初始化资源配置
RES.loadConfig(ResJson);
console.log("初始化资源配置完成")
//加载通用资源
await RES.loadGroup("common");
console.log("通用资源加载完成")
//隐藏加载中
// if (document.getElementById("__loading__")) document.getElementById("__loading__").style.display = "none";
//打开开始场景
changeScene(GameScene);
//测试
// sendTbNet(TbNetName.aaa, {}, (s, res) => {
// console.log(res)
// })
//获取数据,,必成功
// showWaiting();
// sendTbNet(TbNetName.getAppData, {}, (s, res) => {
// hideWaiting();
// Tool.globalData = res.data;
// changeScene(PlayScene);
// //先去获取下任务列表的商品信息吧
// sendTbNet(TbNetName.getTaskList, { activityId: Tool.globalData.activityId }, (s, res) => {
// if (s) Tool.browseItems = res.data.browseItemIds.content;
// })
// })
}
//在小程序显示时调用onShow
run() {
this._pause = false
}
//在小程序隐藏时调用onHide
pause() {
this._pause = true
}
/**
* 添加全局事件,用于小程序的交互调用
* 一直很犹豫要不要放在main的实例里,还是和Main同级导出,还有上面的pause,run,下面的事件等
* @param name
* @param fun
* @param thisObj
*/
addGlobalEvent(name: string, fun: Function, thisObj?: any, once: boolean = false) {
if (once) {
GDispatcher.once(name, fun, thisObj)
} else {
GDispatcher.addEventListener(name, fun, thisObj)
}
}
/**
* 派发全局事件,用于小程序的交互调用
* @param name
* @param data
*/
dispatchGlobalEvent(name: string, data?: any) {
GDispatcher.dispatchEvent(name, data)
}
/**
* 移除全局事件,用于小程序交互调用
* @param name
* @param fun
* @param thisObj
*/
removeGlobalEvent(name: string, fun: Function, thisObj?: any) {
GDispatcher.removeEventListener(name, fun, thisObj)
}
//在小程序页面卸载时调用onUnload,多次销毁后会有问题,再检查
destroy() {
//Tween都移除,注意吧,可能原先的也被移除
FYGE.Tween.removeAllTweens()
// removeAllTimeoutId();//这个再看,尽量用tween的修改
//停掉计时器
FYGE.getCancelAnimationFrame()(this.requestID);
//层级销毁
destroyLayers()
//销毁控制器
destroyAllCtrls();
//舞台销毁
this.stage.destroy();
//全局事件置空
GDispatcher.removeAllEventListener();
//网络数据记录清空
destroyNetData();
}
}
export const ResJson = {
"groups": [
{
"keys": "comCloseBtn.png,toastBg.png,waitingBg.png,waitingRot.png",
"name": "common"
},
{
"keys": "btn_仓库.png,btn_兑换记录.png,btn_商店.png,btn_规则.png,btn_领水滴.png,game_bg.jpg,game_收获.png,game_浇水.png,game_种植.png,广告.png,用户_bg.png,用户_头像.png,用户_水.png,田_初始.png,田_种植.png,田_选择.png,种植框_bg.png,种植框_left.png,种植框_right.png,种植框_山核桃.png,种植框_开心果.png,种植框_板栗.png,种植框_瓜子.png,种植框_腰果.png,种植框_花生.png,种植框_袋子.png,进度_bg.png,进度_fill.png",
"name": "gameScene"
}
],
"path": "./resource/"
}
\ No newline at end of file
import { showToast, wait, clearWait } from "../module/ctrls";
//接口枚举,包括需要调用淘宝的api,用是否含有兑吧区分,或者单独区分
export enum TbNetName {
aaa = "aaa",
/**
* 查询积分
* activityId
*/
getCredits = "getCredits",
/**
* 开始接口
* activityId,nickName
*/
startGame = "startGame",
/**
* 提交分数接口
* activityId,grade,score,type(0:解锁 1:提交), playId
*/
submit = "submit",
/**
* 查询道具数量
* actitvityId
*/
getTools = "getTools",
/**
* 获取任务列表
* activityId
*/
getTaskList = "getTaskList",
/**
* 领取道具
* activityId,taskName
*/
getToolsByType = "getToolsByType",
/**
* 消耗道具
* activityId,type,playId
*/
useTools = "useTools",
}
//返回数据类型,到时再调整
interface dataIn {
netName: TbNetName
data: any
}
//返回数据类型
interface dataOut {
success: boolean,
data?: any
code?: string,
message?: string
}
//记录数据
let dataRecord: {
[name: string]: any
} = {};
//云函数
let fc;
/**
* 发送接口
* @param netName
* @param parameter
* @param callback
*/
export function sendTbNet(netName: TbNetName, parameter: any, callback: Function, hideMsg: boolean = false) {
//网络超时
let waitObj = wait(() => {
if (!hideMsg) showToast("网络超时")
callback(false)
}, 5000)
//@ts-ignore 本地开发,直接取数据
if (!my) {
var url = "../../mock/miniTb/" + netName + ".json";
fetchAsync(url)
.then((data) => {
//清除超时
clearWait(waitObj)
//记录数据
dataRecord[name] = data;
//统一错误信息提示
if (!hideMsg && !data.success) showToast(data.message || "网络异常")
//回调
callback(data.success, data);
}, () => { })
return
}
//@ts-ignore
if (!fc) fc = getApp().cloud.function;
//第一个参数视项目而定
fc.invoke("becheery", parameter, netName)
.then((res: dataOut) => {
clearWait(waitObj);
//记录数据
dataRecord[netName] = res;
// console.log("返回数据" + JSON.stringify(res));
//统一错误信息提示
if (!hideMsg && !res.success) showToast(codeMsg[res.code] || res.message || "网络异常")
//回调
callback(res.success, res);
})
}
/**
* 获取数据
* @param netName
*/
export function getTbData(netName: TbNetName): dataOut {
return dataRecord[netName] || null;
}
//销毁数据
export function destroyNetData() {
dataRecord = {}
}
//webview里调用无效,用postMessage去调
// export const navigateToOutside = (url) => {
// my.call("navigateToOutside", {
// url
// }, (res) => {
// // my.alert({ content: "success - " + JSON.stringify(res)})
// });
// }
async function fetchAsync(url: string) {
// await response of fetch call
let response = await fetch(url);
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
return data;
}
// const { cloud } = window["getApp"]();
// const { function: fc } = cloud;
// fc.invoke("duiba.sign.doJoin", { signActivityId: 1 })
// .then(res => {
// console.log(res);
// })
/**
* 错误码列表,字段不设枚举了
*/
const codeMsg = {
"210001": "服务器异常",
"210002": "用户不存在",
"210003": "邀请已达上限",
"210004": "无法邀请自己",
"210006": "该活动ID无效",
"210009": "该活动暂未开始",
"210010": "该分享ID不存在",
"210012": "该用户暂未获奖",
"210013": "领取失败",
"210015": "该活动已删除",
"210016": "该活动已经结束",
"210017": "该奖品已达领取上线",
"210018": "请先分享好友",
"210019": "暂有奖品未领取",
"210020": "暂有奖品未完成",
"210021": "请先玩一局游戏",
"210022": "请先选择奖品",
"210023": "领取失败,库存不足",
"210024": "请先成为会员",
"210025": "奖品已经过期",
"210026": "不能重复助力",
"210028": "请至我的奖品页重新领取",//重新领取
}
\ No newline at end of file
import { RES } from "../module/RES";
/**
* 定制,记录一些全局量和方法
*/
export class Tool {
/**
* 状态,1为正常流程,2为注册返回页,3为分享落地页,4为喜哥链接返回
*/
public static status;
/**
* 是否第一次
*/
public static isFirst: boolean
/**
* 缓存key
*/
public static cacheKey: string = "hadCompleteHaokelai"
/**
* 初始化一些数据,比如环境参数等
*/
public static init() {
//是否第一次
// if (GTool.readCache(this.cacheKey)) {
// this.isFirst = true
// }
}
public static getSprite(imageName: string, x: number = 0, y: number = 0) {
var sprite = new FYGE.Sprite(RES.getRes(imageName));
sprite.x = x;
sprite.y = y
return sprite
}
/**
*
* @param txt
* @param size
* @param color
* @param textWidth
* @param align
* @param x
* @param y
*/
public static getText(
txt: string,
size: number,
color: string = "#000000",
textWidth: number = 0,
align: FYGE.TEXT_ALIGN = FYGE.TEXT_ALIGN.CENTER,
x: number = 0,
y: number = 0
) {
var text = new FYGE.TextField();
text.fillColor = color;
text.size = size;
text.textWidth = textWidth;
text.textAlign = align;
text.x = x;
text.y = y;
text.text = txt;
return text
}
/**
* 左上角原点
* @param width
* @param height
* @param color
* @param alpha
* @param radius
* @param x
* @param y
*/
public static getRect(
width: number,
height: number,
color: number = 0xff0000,
alpha: number = 1,
radius: number = 0,
x: number = 0,
y: number = 0,
) {
var g = new FYGE.Graphics();
g.beginFill(color);
g.alpha = alpha;
if (!radius) {
g.drawRect(0, 0, width, height)
} else {
g.drawRoundedRect(0, 0, width, height, radius)
}
g.endFill();
g.position.set(x, y);
return g
}
/**
* 总行数
*/
public static rowNum = 4;
/**
* 总列数
*/
public static colNum = 4;
/**
* 格子宽度
*/
public static width = 125;
/**
* 格子高度
*/
public static height = 125;
//整体偏移X,
public static offsetX = 106;
//整体偏移Y
public static offsetY = 600;
/**
* row和col转换到index的hashMap
*/
private static rcToIndexMap = {};
/**
* index到row和col的hashMap
*/
private static indexToRcMap: [number, number][] = [];
/**
* 行列位置,记录每个格子中心点的位置吧
*/
private static rowColPositions = {};
/**
* 索引位置
*/
private static indexPositions: [number, number][] = [];
/**
* 初始化数据
* 提前的缓存数据,千万别修改,因为给出的数据都没有深拷贝过
*/
public static initLatData() {
//位置信息
var spaceX = this.width+11,
spaceY = this.height+11,
offsetX = this.offsetX + this.width / 2,
offsetY = this.offsetY + this.height / 2;
for (var i = 0; i < this.rowNum; i++) {
for (var j = 0; j < this.colNum; j++) {
this.rcToIndexMap["" + i + j] = i * this.colNum + j;
this.indexToRcMap[i * this.colNum + j] = [i, j];
this.rowColPositions["" + i + j] = [offsetX + j * spaceX, offsetY + i * spaceY];
this.indexPositions[i * this.colNum + j] = [offsetX + j * spaceX, offsetY + i * spaceY];
}
}
}
/**
* row和col获得index值
* @param row
* @param col
*/
public static rcToIndex(row: number, col: number): number {
var key = "" + row + col;
return this.rcToIndexMap[key]
}
/**
* index获得row和col,返回的是数组,0是row,1是col
* @param index
*/
public static indexToRc(index: number): [number, number] {
return this.indexToRcMap[index]
}
/**
* 根据row,col得到位置信息
* @param row
* @param col
* @return 类似数组[111,222],0是x坐标,1是y坐标
*/
public static getPositionByRc(row: number, col: number): [number, number] {
var key = "" + row + col;
return this.rowColPositions[key]
}
/**
* 根据index得到位置信息
* @param index
* @return 类似数组[111,222],0是x坐标,1是y坐标
*/
public static getPositionByIndex(index: number): [number,number] {
return this.indexPositions[index]
}
}
\ No newline at end of file
import { layers } from "../../module/views/layers";
export function getAdjustBottomHeight(target, percent: number) {
return layers.stageHeight - layers.stageHeight * percent - target.height + layers.stageOffsetY;
}
export function getAdjustTopHeight(target, percent: number) {
return layers.stageHeight * percent + layers.stageOffsetY;
}
export enum PLANT {
'NONE' = 'NONE',
'Chestnut' = 'Chestnut', // 板栗
'Pecan' = 'Pecan', // 山核桃
'Peanut' = 'Peanut', // 花生
'Sunflower' = 'Sunflower', // 瓜子
'Pistachio' = 'Pistachio', // 开心果
'Cashew' = 'Cashew', // 腰果
}
export const s_PlantData = {
Chestnut: {
name: '板栗',
time: 1,
},
Pecan: {
name: '山核桃',
time: 2,
},
Peanut: {
name: '花生',
time: 3,
},
Sunflower: {
name: '瓜子',
time: 4,
},
Pistachio: {
name: '开心果',
time: 5,
},
Cashew: {
name: '腰果',
time: 6,
},
}
import { Tool } from "../Tools";
import { Panel } from "../../module/views/Panel";
import { RES } from "../../module/RES";
import { Light } from "../parts/Light";
const foodData: {
[key: number]: { name: string, des: string }
} = {
8: { name: "爆浆麻薯150g*2袋", des: "" },
16: { name: "面筋卷120g*2袋", des: "" },
32: { name: "岩焗乳酪吐司500g", des: "" },
64: { name: "鱼豆腐170g", des: "" },
128: { name: "猪肉脯200g", des: "解锁后可在首页领取奖励哦~" },
256: { name: "卤藕168g*2袋", des: "解锁后可在首页领取奖励哦~" },
512: { name: "手撕面包1050g", des: "解锁后可在首页领取奖励哦~" },
1024: { name: "枣夹核桃700g", des: "解锁后可在首页领取奖励哦~" },
2048: { name: "甜辣鸭脖190g", des: "解锁后可在首页领取奖励哦~" },
}
/**
* 解锁弹框
*/
export class UnlockPanel extends Panel {
get groupNames() { return ["unlockPanel"] }
closeBtn:FYGE. Button;
data: {
grade: number,
closeFun:Function
}
initUi() {
//加光
this.addChild(new Light()).position.set(375, 735);
//背景
this.addChild(Tool.getSprite("unlockPanelBg.png"));
//关闭按钮
this.closeBtn = new FYGE.Button(RES.getRes("comCloseBtn.png"));
this.closeBtn.position.set(614, 460);
this.addChild(this.closeBtn);
//继续游戏
this.addChild(new FYGE.Button(RES.getRes("zailaiyiju.png")))
.once(FYGE.MouseEvent.CLICK, this.onClick_closeBtn, this)
.position.set((750 - 233) / 2, 938)
//标题文案
// this.addChild(new Title(this.data.grade))
//奖品图片 246;
this.addChild(new FYGE.Sprite(RES.getRes("unlock" + this.data.grade + ".png")))
.position.set((750 - 449) / 2-20, 580+20)
//名字
// this.addChild(Tool.addText(
// foodData[this.data.grade].name,
// 28,
// "#ffffff",
// undefined,
// 560,
// (750 - 560) / 2,
// 890
// ))
//描述
// this.addChild(Tool.addText(
// foodData[this.data.grade].des,
// 22,
// "#dac5fc",
// undefined,
// 560,
// (750 - 560) / 2,
// 931
// ))
}
start(data) {
super.start();
}
initEvents() {
this.closeBtn.addEventListener(FYGE.MouseEvent.CLICK,this.onClick_closeBtn, this)
}
onClick_closeBtn() {
this.data.closeFun()
this.hidePanel();
}
removeEvents() {
this.closeBtn.removeEventListener(FYGE.MouseEvent.CLICK,this.onClick_closeBtn, this)
}
}
class Title extends FYGE.Container {
grade: number
constructor(grade: number) {
super();
var msg = new FYGE.Sprite(RES.getRes("unlockMsg.png"))
this.addChild(msg);
var textures = {}
for (var i = 0; i < 10; i++)textures[i] = RES.getRes("n" + i + ".png");
var num = new FYGE.BitmapText(textures);
num.textAlign = FYGE.TEXT_ALIGN.LEFT;
num.text = grade + "";
this.addChild(num);
var w = msg.width + num.width;
msg.position.set((750 - w) / 2, 548);
num.position.set(msg.x + msg.width, 548 + 4)
}
}
\ No newline at end of file
import Container = FYGE.Container;
export default class GameLayer extends Container{
constructor() {
super();
}
}
import Container = FYGE.Container;
class Land extends Container {
constructor() {
super();
}
}
import { PLANT, s_PlantData } from "../../const/staticData";
import { Tool } from "../../Tools";
import Container = FYGE.Container;
import IScrollListItem = FYGE.IScrollListItem;
import ScrollList = FYGE.ScrollList;
import TextField = FYGE.TextField;
import TEXT_ALIGN = FYGE.TEXT_ALIGN;
import VERTICAL_ALIGN = FYGE.VERTICAL_ALIGN;
import Sprite = FYGE.Sprite;
import { RES } from "../../../module/RES";
class ListPlant extends Container implements IScrollListItem {
id: number;
data: number;
/**
* 数据更新
* @param {number} id
* @param data
*/
public initData(id: number, data: any) {
if (!data || data == PLANT.NONE) return;
this.key = data;
this.img.texture = RES.getRes(`种植框_${s_PlantData[data].name}.png`);
this.img.position.set((this.width - this.img.width) / 2 - 5, (this.height - this.img.height) / 2 + 20);
}
private _key: PLANT = PLANT.NONE;
public get key() {
return this._key;
}
public set key(key: PLANT) {
this._key = key;
if (this._key == PLANT.NONE) return;
this.nameLabel.text = s_PlantData[key].name;
this.timeLabel.text = s_PlantData[key].time + 'h';
this.nameLabel.x = (this.width - this.nameLabel.textWidth) / 2;
this.timeLabel.x = 72 + (35 - this.timeLabel.textWidth) / 2;
}
private nameLabel: TextField;
private timeLabel: TextField;
private img: Sprite;
constructor() {
super();
this.width = 108;
this.height = 160;
this.addChild(Tool.getSprite('种植框_袋子.png'))
.position.set(0, 21);
// 名字的label
this.nameLabel = this.addChild(new TextField());
this.nameLabel.position.set(0, 125);
this.nameLabel.size = 22;
this.nameLabel.textAlign = TEXT_ALIGN.CENTER;
// 需要时间的label
this.timeLabel = this.addChild(new TextField());
this.timeLabel.position.set(75, 85);
this.timeLabel.size = 17;
this.timeLabel.textAlign = TEXT_ALIGN.CENTER;
this.timeLabel.verticalAlign = VERTICAL_ALIGN.MIDDLE;
this.img = this.addChild(new Sprite());
this.addEventListener(FYGE.MouseEvent.CLICK, () => {
console.log(`点到了: ${this.key} ${s_PlantData[this.key].name}`);
});
}
}
export default class PlantList extends Container {
private scrollList: ScrollList;
constructor() {
super();
this.width = 609;
this.height = 106;
// bg
this.addChild(Tool.getSprite('种植框_bg.png'));
// tip: left and right
this.addChild(Tool.getSprite('种植框_left.png'))
.position.set(15, (this.height - 34) / 2);
this.addChild(Tool.getSprite('种植框_right.png'))
.position.set(this.width - 33, (this.height - 34) / 2);
// 列表
this.scrollList = this.addChild(new ScrollList(ListPlant, 128, 160, 500, 160, false));
let data = [];
for (let k in PLANT) {
if (k == PLANT.NONE) continue;
data.push(PLANT[k]);
}
this.scrollList.updateData(data);
this.scrollList.x = (this.width - 500) / 2;
this.x = 100;
this.y = 400;
}
}
import { RES } from "../../module/RES";
import { Tool } from "../Tools";
export class GameEle extends FYGE.Sprite {
private _type: number
get type() {
return this._type
}
set type(value: number) {
this._type = value;
this.texture = RES.getRes("ele" + value + ".png")
}
private _tempType: number = null;
get tempType() {
return this._tempType;
}
set tempType(value) {
this._tempType = value;
}
index: number;
get row() {
return Tool.indexToRc(this.index)[0]
}
get col() {
return Tool.indexToRc(this.index)[1]
}
constructor(type: number) {
super();
this.type = type;
this.anchorTexture.set(0.5, 0.5);
}
reset(type) {
this.type = type;
this.scale.set(1, 1)
}
}
\ No newline at end of file
import { RES } from "../../module/RES";
/**
* 旋转光
*/
export class Light extends FYGE.Sprite {
constructor() {
super();
this.texture = RES.getRes("light.png");
this.anchorTexture.set(0.5, 0.5);
this.addEventListener(FYGE.Event.ENTER_FRAME, () => {
this.rotation += 1;
}, this)
}
}
\ No newline at end of file
import { GameEle } from "./GameEle";
import { Tool } from "../Tools";
import { RES } from "../../module/RES";
import { GPool } from "../../module/tools/GPool";
export interface MoveAniInt {
startEle1: GameEle,
startEle2?: GameEle,
endIndex: number,
}
/**
* 偷懒先用fun的试下,不然就动画独立
* @param callback 回调里计数完成用
* @param startEle1
* @param endIndex
* @param startEle2
*/
export function moveAni(
callback: () => void,
startEle1: GameEle,
endIndex: number,
startEle2?: GameEle,
) {
var endType: number = startEle1.type * 2;
var endP = Tool.getPositionByIndex(endIndex);
//移动动画
FYGE.Tween.get(startEle1)
.to({ x: endP[0], y: endP[1] }, 200)
.call(() => {
callback();
if (!startEle2) return;
//添加动画
// startEle1.parent.addChild(playDisAni(endType, startEle1.x, startEle1.y))
//第一个缩小
FYGE.Tween.get(startEle1)
.to({ scaleX: 0.1, scaleY: 0.1 }, 100)
.call(() => {
startEle1.type = endType;
startEle1.tempType = null;
})
.to({ scaleX: 1, scaleY: 1 }, 100, FYGE.Ease.backOut)
// .call(() => { callback() })
})
if (startEle2) {
FYGE.Tween.get(startEle2)
.to({ x: endP[0], y: endP[1] }, 200)
.call(() => {
//移除第二个
startEle2.parent.removeChild(startEle2);
GPool.recover("gameEle", startEle2)
})
}
}
// const disAniName = "disAniName"
// function playDisAni(type: number, x, y) {
// let mv: FYGE.MovieClip = GPool.takeOut(disAniName + type)
// if (!mv) {
// mv = new FYGE.MovieClip(RES.getRes("create" + type + ".svga"))
// }
// mv.position.set(x - 125, y - 125);
// mv.startAniRange(1, mv.totalFrames, 1, () => {
// if (mv.parent) {
// mv.parent.removeChild(mv);
// GPool.recover(disAniName + type, mv);
// }
// })
// return mv
// }
import Container = FYGE.Container;
import { Tool } from "../../Tools";
import Sprite = FYGE.Sprite;
import TextField = FYGE.TextField;
import Graphics = FYGE.Graphics;
import Texture = FYGE.Texture;
export class UserInfoGroup extends Container {
private avatar: Sprite;
private nickName: TextField;
private numLabel: TextField;
constructor(userInfo?) {
super();
// 背景
this.addChild(Tool.getSprite('用户_bg.png'));
// 头像
// this.avatar = this.addChild(new Sprite());
this.avatar = this.addChild(Tool.getSprite('用户_头像.png'));
this.avatar.position.set(35, 13);
this.avatar.width = this.avatar.height = 93;
// 头像mask
// let mask = new Graphics();
// mask.position.set(35, 13);
let r = 93 / 2;
// mask.drawCircle(35 + r, 13 + r, r);
// this.avatar.mask = this.addChild(mask);
this.avatar.mask = this.addChild(new Graphics().drawCircle(35 + r, 13 + r, r));
// 昵称
this.nickName = this.addChild(new TextField());
this.nickName.position.set(150, 20);
this.nickName.size = 28;
this.nickName.fillColor = '#a65310';
// 数量
this.numLabel = this.addChild(new TextField());
this.numLabel.position.set(200, 68);
this.numLabel.size = 28;
this.numLabel.fillColor = '#a65310';
// 更新信息
userInfo && this.updateInfo(userInfo);
}
/**
* 更新用户信息
* @param userInfo
*/
public updateInfo(userInfo) {
this.avatar.texture = Texture.fromUrl(userInfo.avatar);
if (userInfo.nickName.length >= 3) {
userInfo.nickName = userInfo.nickName.slice(0, 3) + '...';
}
this.nickName.text = userInfo.nickName + '的坚果庄园';
this.numLabel.text = ${userInfo.waterNum}`;
}
}
import { Scene } from "../../module/views/Scene";
import { Tool } from "../Tools";
import PlantList from "../parts/Game/PlantList";
import Container = FYGE.Container;
import { getAdjustBottomHeight, getAdjustTopHeight } from "../const/myLab";
import { UserInfoGroup } from "../parts/UI/UserInfoGroup";
import Sprite = FYGE.Sprite;
import MouseEvent = FYGE.MouseEvent;
export class GameScene extends Scene {
get groupNames() {
return ['gameScene']
}
private plantList: PlantList; // 种植列表
// 顶部
private userInfoGroup: UserInfoGroup; // 用户信息
private ruleBtn: Sprite; // 规则按钮
// 底部
private taskBtn: Sprite; // 任务按钮
private wareHouseBtn: Sprite; // 仓库按钮
private storeBtn: Sprite; // 商店按钮
// 广告
private adBtn: Sprite;// 广告
initUi() {
this.addChild(Tool.getSprite('game_bg.jpg'));
// 底部
let bottomGroup = this.addChild(new Container());
this.taskBtn = bottomGroup.addChild(Tool.getSprite('btn_领水滴.png'))
this.taskBtn.x = 750 / 6 - this.taskBtn.width / 2;
this.taskBtn.name = '任务';
this.wareHouseBtn = bottomGroup.addChild(Tool.getSprite('btn_仓库.png'))
this.wareHouseBtn.x = 750 / 2 - this.wareHouseBtn.width / 2;
this.wareHouseBtn.name = '仓库';
this.storeBtn = bottomGroup.addChild(Tool.getSprite('btn_商店.png'))
this.storeBtn.x = 750 / 6 * 5 - this.storeBtn.width / 2;
this.storeBtn.name = '商店';
bottomGroup.y = getAdjustBottomHeight(bottomGroup, (1624 - 1382 - 133) / 1624);
// 顶部
let topGroup = this.addChild(new Container());
this.userInfoGroup = topGroup.addChild(new UserInfoGroup({
avatar: 'https://source.unsplash.com/collection/collectionid/100x100',
nickName: '哈哈哈哈',
waterNum: '666'
}));
this.ruleBtn = topGroup.addChild(Tool.getSprite('btn_规则.png'));
this.ruleBtn.position.set(622, 0);
this.ruleBtn.name = '规则';
topGroup.y = getAdjustTopHeight(topGroup, 117 / 1624);
this.adBtn = this.addChild(Tool.getSprite('广告.png'));
this.adBtn.position.set(30, (this.height - this.adBtn.height) / 2);
this.adBtn.name = '广告';
// 种植列表
this.plantList = this.addChild(new PlantList());
// this.plantList.visible = false;
}
start() {
super.start();
}
/**
* 按钮的点击事件
* @param e
*/
private touchBtn(e) {
console.log(e.target.name);
switch (e.target) {
case this.taskBtn:
console.log('点击了任务');
break;
case this.wareHouseBtn:
console.log('点击了仓库');
break;
case this.storeBtn:
console.log('点击了商店');
break;
case this.ruleBtn:
console.log('点击了规则');
break;
case this.adBtn:
console.log('点击了广告');
break;
}
}
initEvents() {
super.initEvents();
[this.ruleBtn, this.taskBtn, this.wareHouseBtn, this.storeBtn, this.adBtn].forEach((v) => {
v.addEventListener(MouseEvent.CLICK, this.touchBtn, this);
});
}
removeEvents() {
super.removeEvents();
[this.ruleBtn, this.taskBtn, this.wareHouseBtn, this.storeBtn, this.adBtn].forEach((v) => {
v.removeEventListener(MouseEvent.CLICK, this.touchBtn, this);
});
}
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"sourceMap": true,
"removeComments": true,
"noEmitOnError":true,
"outDir":"dist",
/*"outFile": "./index.js",*/
"lib": [
"es5",
"dom",
"es2015.promise"
]
},
"exclude": [
"node_modules"
]
}
\ No newline at end of file
const path = require('path');
module.exports = {
entry: './src/Main.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
filename: 'output.js',
path: __dirname,
libraryTarget: 'umd',
}
};
\ No newline at end of file
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const webpack = require('webpack');
const MockWebpackPlugin = require('mock-webpack-plugin');
const mockConfig = require('./mock/config.js');
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
contentBase: '.',
proxy: {
'/plugin/*':'http://localhost:3000',
'/ngapi/*': 'http://localhost:3000',
'/ngame/*': 'http://localhost:3000',
}
},
plugins: [
new MockWebpackPlugin({
config: mockConfig,
port: 3000
})
]
});
\ No newline at end of file
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
module.exports = merge(common, {
mode: "production",
devtool: 'source-map',
plugins: [
new UglifyJSPlugin(
{ sourceMap: false }
), new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
});
\ 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