Commit 0c3760e6 authored by rockyl's avatar rockyl

更新模板

parent c1a22af1
......@@ -14,7 +14,7 @@
<style>
html, body {
-ms-touch-action: none;
background: #0a0047;
background: white;
padding: 0;
border: 0;
margin: 0;
......@@ -72,11 +72,11 @@
loadScript(list, function () {
/**
* {
* "renderMode":, //Engine rendering mode, "canvas" or "webgl"
* "audioType": 0 //Use the audio type, 0: default, 2: web audio, 3: audio
* "antialias": //Whether the anti-aliasing is enabled in WebGL mode, true: on, false: off, defaults to false
* "calculateCanvasScaleFactor": //a function return canvas scale factor
* }
* "renderMode":, //Engine rendering mode, "canvas" or "webgl"
* "audioType": 0 //Use the audio type, 0: default, 2: web audio, 3: audio
* "antialias": //Whether the anti-aliasing is enabled in WebGL mode, true: on, false: off, defaults to false
* "calculateCanvasScaleFactor": //a function return canvas scale factor
* }
**/
egret.runEgret({
renderMode: "webgl", audioType: 0, calculateCanvasScaleFactor: function (context) {
......@@ -93,33 +93,57 @@
});
xhr.send(null);
var gameId = 1;
var revivePluginId = 1;
var CFG = {
appInfo: {
"appId": 1,
"earnCreditsUrl": "https://www.baidu.com/",
"loginProgram": "",
"open": false,
"openLogin": false
},
gameInfo: {
"id": 1317,
"oaId": 19951,
"offDate": "2018-04-17 11:00",
"openTotalScoreSwitch": false,
"rankPrize": true,
"skincontent": ""
},
extra: {
"embedDomain": "//embedlog.duibatest.com.cn"
},
defenseStrategy: {
"scoreUnit": 500
}
}
actId: '3213171',
oaId: '3213171',
unitName: '积分',
btnUnitName: '积分',
doJoin: '/hdtool/doJoin?dpm=1.3.1.0&activityId=3213171',
quireOrder: '/hdtool/getOrderStatus',
styleConfig: '/hdtool/getHdtoolConfig',
getElement: '/hdtool/ajaxElement',
getPrizeDetail: '/hdtool/prizeDetail',
ajaxThroughInfo: '/hdtool/ajaxThroughInfo',
throughSubmit: '/hdtool/throughSubmit',
gameGetOrder: '/hdtool/getOrderInfo',//游戏获取订单信息接口
gameSubmit: '/hdtool/gameSubmit',//游戏结果提交接口
doSubmit: '/hdtool/submit',
adslotId:'',
consumerId:'1',
isNotLoginUser:false,
uid:'1',
hdType: 'duiba',
hdToolId: '41832',
appType: 'credits',
subType: 'cutRope',
directSendCoupon: 'false',
ajaxAction: '',
recommendQueue: '/recommend/getRecommend',
recommendSkin: '/recommend/getRecommendSkin',
isShowDetail: true,
preview: false,
from: '',
login: '//activity.m.duiba.com.cn/hdtool/login?dpm=1.3.3.0',
flowRedirectUrl: '',
flowRedirectTuiaUrl: '',
isOpenRecommend: true,
appId: '1',
recordUrl: '//activity.m.duiba.com.cn/crecord/record?dbnewopen&dpm=1.3.2.0',
shareDesc: '分享分享文案文案',
entranceDesc:'测试领奖,也可到我的奖品领奖,24小时内有效哦',
isSHowMeat: true,
needCouponModal: true, // 给前端用,判断是否需要使用配置的优惠券弹窗
needRecommendModal: true, // 给前端用,判断是否需要公用推荐位弹窗
asyncFiles: [], // 给前端用,异步加载的文件
shareAndroidLinkActivity: 'http://www.duiba.com.cn',
shareIosLinkActivity: 'http://www.iqiyi.com'
};
var recordUrl = 'record/';
var activityId = 111;
var activityType = '';
function devil(a) {
return eval(a);
}
......
import MainBase from './core/MainBase'
import GameConfig from "./game/model/GameConfig";
import {init as initLocalStorage} from "@alienlib/support/LocalStorage";
import webService from "@core/WebService";
class Main extends MainBase {
protected onAddedToStage(): void {
super.onAddedToStage();
super.onAddedToStage()
webService.setMockUrlForDebug('http://localhost:3000');
initLocalStorage(GameConfig.gameName);
}
}
......@@ -6,9 +6,13 @@
import {Ajax, EgretUtils} from "@alienlib/tools";
const WEB_SERVICE_URL: string = DEBUG ? 'https://172.31.51.89:3000' : '';
class WebService {
webServiceUrl: string;
setMockUrlForDebug(webServiceUrl){
this.webServiceUrl = DEBUG ? webServiceUrl : '';
}
/**
* 调用API
* @param uri
......@@ -21,7 +25,10 @@ class WebService {
params = {};
}
let url: string = WEB_SERVICE_URL + uri;
if(!this){
console.log();
}
let url: string = this.webServiceUrl + uri;
let m: Function = method == 'post' ? Ajax.POST : Ajax.GET;
......@@ -65,7 +72,7 @@ class WebService {
})
}
const callApi = this.callApi;
const that = this;
let lastData;
return p.then(
......@@ -82,7 +89,7 @@ class WebService {
);
function func() {
return callApi(uri, params, method, responseType).then(
return that.callApi(uri, params, method, responseType).then(
(data) => {
if (successFunc(data)) {
lastData = data;
......
......@@ -113,16 +113,25 @@ function transData(data){
}
}
function bindComponent(host, component, injection) {
export function bindComponent(host, component, injection) {
let components = getComponents(host, true);
components.push(component);
transData(injection);
injectProp(component, injection);
component['host'] = host;
//inject view parts
if(host.skin){
host.skin.skinParts.forEach(part=>{
if(component.hasOwnProperty(part)){
component[part] = host[part];
}
});
}
}
function unbindComponents(host, ...componentArr) {
export function unbindComponents(host, ...componentArr) {
let components = getComponents(host);
if (!components) {
return;
......@@ -228,19 +237,25 @@ export function sleepView(view, name) {
});
}
export function broadcast(method, ...params){
export function broadcast(method, targetComponent = null, ...params){
let group = bindingsMap[currentGroup];
if(!group){
return;
}
const result = [];
for(let key in group){
const bindings = group[key];
for(let binding of bindings){
const m: any = binding[method];
if(m){
m.apply(binding, params);
if(m && !(targetComponent && typeof targetComponent === 'function' && binding instanceof targetComponent)){
result.push({
component: binding,
result: m.apply(binding, params),
});
}
}
}
return result;
}
/**
* Created by rockyl on 2018/11/9.
*/
export function exportField(comment) {
return function (target, key, description) {
}
}
......@@ -11,12 +11,11 @@ import {BADGE_CHANGED} from "../model/events";
export default class Badge extends CurseComponent {
public name:string = '';
private lab: eui.Label;
private lab: eui.Label = null;
protected reset() {
super.reset();
protected onCreate() {
super.onCreate();
this.lab = this.host.lab;
this.registerEvent(badgeService, BADGE_CHANGED, this.onBadgeChange, this);
this.registerEvent(this.host, egret.Event.ADDED_TO_STAGE, this.onAddedToStage, this);
}
......
......@@ -12,8 +12,8 @@ export default class Breath extends CurseComponent{
wave: Wave;
protected reset() {
super.reset();
protected onCreate() {
super.onCreate();
anchorCenter(this.host);
this.wave = new Wave(this.host, this.duration, breath.bind(null, this.scaleOffset), 0, false);
......
......@@ -11,8 +11,8 @@ export default class BuriedPointButton extends CurseComponent {
private buriedPointName: string;
protected reset() {
super.reset();
protected onCreate() {
super.onCreate();
this.buriedPointName = 'buried-point-' + Date.now();
buriedPointService.addBuriedPointConfig(
......
......@@ -8,8 +8,8 @@ import SceneController from "@core/view/SceneController";
export default class ButtonBack extends CurseComponent{
type: number;
protected reset() {
super.reset();
protected onCreate() {
super.onCreate();
this.registerEvent(this.host, egret.TouchEvent.TOUCH_TAP, this.onHostTap, this);
}
......
......@@ -9,8 +9,8 @@ import {PANEL_RULE} from "../model/constants";
export default class ButtonRule extends CurseComponent{
type: number;
protected reset() {
super.reset();
protected onCreate() {
super.onCreate();
this.registerEvent(this.host, egret.TouchEvent.TOUCH_TAP, this.onHostTap, this);
}
......
/**
* Created by rockyl on 2018/10/10.
*/
import CurseComponent from "@core/curse/CurseComponent";
import SceneController from "@core/view/SceneController";
import {SCENE_PLAY} from "../model/constants";
export default class ButtonStart extends CurseComponent{
type: number;
protected reset() {
super.reset();
this.registerEvent(this.host, egret.TouchEvent.TOUCH_TAP, this.onHostTap, this);
}
private onHostTap(event){
SceneController.goto(SCENE_PLAY);
}
}
/**
* Created by rockyl on 2018/11/2.
*
* 防作弊组件
*/
import CurseComponent from "@core/curse/CurseComponent";
import GameConfig from "../model/GameConfig";
import * as api from "../net/api";
export default class Defense extends CurseComponent {
collection: any[] = [];
strategyCollection: any[] = [];
pashCount;
protected onCreate() {
super.onCreate();
this.registerEvent(this.host, egret.TouchEvent.TOUCH_BEGIN, this.onTouch.bind(this, 'md'), this);
}
protected awake() {
super.awake();
}
protected sleep() {
super.sleep();
}
protected destroy() {
super.destroy();
}
private onTouch(type, e:egret.TouchEvent){
const data = { a: type, t: Date.now(), x: e.stageX, y: e.stageY };
/*let str = JSON.stringify(data);
str = md5(str);
let result = '';
for(let i = 0, li = str.length; i < li; i++){
result += Math.random() < 0.3 ? str.charAt(i) : '';
}*/
this.strategyCollection.push(data)
}
start() {
this.collection.splice(0);
this.strategyCollection.splice(0);
this.pashCount = 0;
}
scoreChanged(score){
const {interfaceLimit, scoreUnit} = GameConfig;
const nextDatapashScore = score - this.pashCount * scoreUnit;
if (scoreUnit == 0 || nextDatapashScore < scoreUnit || this.pashCount > interfaceLimit) {
return;
}
this.collection.push(this.strategyCollection.concat());
api.datapash(this.strategyCollection);
this.strategyCollection.splice(0);
this.pashCount++;
}
close(){
this.collection.push(this.strategyCollection.concat());
return {
strategyCollection: this.strategyCollection,
collection: this.collection,
}
}
}
\ No newline at end of file
/**
* Created by rockyl on 2018/10/19.
*
* Created by rockyl on 2018/10/23.
*
* 游戏视图
*/
import CurseComponent from "@core/curse/CurseComponent";
import {broadcast} from "@core/curse/Manager";
export default class GameView extends CurseComponent {
container: eui.Group = null;
labCD: eui.Label = null;
labScore: eui.Label = null;
export default class GameViewLabel extends CurseComponent {
protected reset() {
super.reset();
protected onCreate() {
super.onCreate();
}
protected awake() {
super.awake();
this.host.text = 'hello';
}
protected sleep() {
......@@ -27,4 +31,16 @@ export default class GameViewLabel extends CurseComponent {
super.destroy();
}
}
\ No newline at end of file
readyGo() {
}
startGame() {
broadcast('start');
}
stopGame() {
}
}
/**
* Created by rockyl on 2018/10/11.
*
* 提示弹窗
*/
import CurseComponent from "@core/curse/CurseComponent";
import PanelController from "@core/view/PanelController";
import {PANEL_ALERT} from "../model/constants";
export default class PanelAlert extends CurseComponent {
protected onCreate() {
super.onCreate();
const {btnConfirm} = this.host;
this.registerEvent(btnConfirm, egret.TouchEvent.TOUCH_TAP, this.onBtnConfirmTap, this);
}
protected awake(): void {
super.awake();
const {labContent, btnConfirm} = this.host;
const {content, button = 'Confirm'} = this.host.data;
labContent.text = content;
btnConfirm.label = button;
}
private onBtnConfirmTap(event) {
PanelController.instance.dealAction(PANEL_ALERT);
}
}
/**
* Created by rockyl on 2018/10/11.
*
* 结果弹窗
*/
import CurseComponent from "@core/curse/CurseComponent";
import PanelController from "@core/view/PanelController";
import {PANEL_RESULT, } from "../model/constants";
import lang from "@core/lang";
export default class PanelResult extends CurseComponent {
btnRetry: eui.Button = null;
btnClose: eui.Button = null;
protected onCreate() {
super.onCreate();
this.host.addExcludeForClose(['retry']);
this.registerEvent(this.btnRetry, egret.TouchEvent.TOUCH_TAP, this.onBtnRetryTap, this);
this.registerEvent(this.btnClose, egret.TouchEvent.TOUCH_TAP, this.onBtnCloseTap, this);
}
private onBtnRetryTap(event) {
PanelController.instance.dealAction(PANEL_RESULT, 'retry');
}
private onBtnCloseTap(event) {
PanelController.instance.dealAction(PANEL_RESULT);
}
protected awake(): void {
super.awake();
const {labContent} = this.host;
const {score} = this.host.data;
labContent.text= lang.format(lang.result_text, score);
}
}
......@@ -7,22 +7,32 @@
import CurseComponent from "@core/curse/CurseComponent";
import PanelController from "@core/view/PanelController";
import {PANEL_RULE} from "../model/constants";
import {getRule} from "../net/api";
import {parseHtmlText} from "@alienlib/tools/Utils";
export default class PanelRule extends CurseComponent {
content: string;
button: string;
protected reset() {
super.reset();
protected onCreate() {
super.onCreate();
const {labContent, btnConfirm} = this.host;
labContent.text= this.content;
labContent.text= '';
btnConfirm.label = this.button;
this.readyRule();
this.registerEvent(btnConfirm, egret.TouchEvent.TOUCH_TAP, this.onBtnConfirmTap, this);
}
private async readyRule(){
const {labContent} = this.host;
let content = await getRule();
labContent.textFlow = parseHtmlText(content);
}
private onBtnConfirmTap(event) {
PanelController.instance.close(PANEL_RULE);
PanelController.instance.dealAction(PANEL_RULE);
}
}
\ No newline at end of file
}
/**
* Created by rockyl on 2018/10/23.
*
*
*/
import CurseComponent from "@core/curse/CurseComponent";
import {getWidth} from "@alienlib/support/StageProxy";
export default class ReadyGo extends CurseComponent {
protected onCreate() {
super.onCreate();
}
protected awake() {
super.awake();
}
protected sleep() {
super.sleep();
}
protected destroy() {
super.destroy();
}
reset(){
this.host.visible = false;
}
readyGo(p) {
const sw = getWidth();
const {lab, bg} = this.host;
lab.text = 'Ready';
lab.horizontalCenter = -sw;
this.host.visible = true;
egret.Tween.get(bg, null, null, true)
.set({visible: true})
.to({scaleY: 1}, 200, egret.Ease.cubicOut)
.wait(2000)
.to({scaleY: 0}, 200, egret.Ease.cubicIn);
egret.Tween.get(lab, null, null, true)
.wait(200)
.to({horizontalCenter: 0}, 200, egret.Ease.cubicOut)
.wait(600)
.to({horizontalCenter: sw}, 200, egret.Ease.cubicIn)
.set({
text: 'Go',
horizontalCenter: -sw,
})
.to({horizontalCenter: 0}, 200, egret.Ease.cubicOut)
.wait(600)
.to({horizontalCenter: sw}, 200, egret.Ease.cubicIn)
}
}
\ No newline at end of file
......@@ -7,14 +7,14 @@ import {sin, Wave} from "@alienlib/animation/wave";
import {delayLoad} from "../Utils";
export default class SceneMenu extends CurseComponent{
lab: eui.Label = null;
wave: Wave;
protected reset() {
super.reset();
const {lab} = this.host;
protected onCreate() {
super.onCreate();
this.wave = new Wave(lab, 2000, sin.bind(null, 20), 0, false);
this.wave = new Wave(this.lab, 2000, sin.bind(null, 20), 0, false);
delayLoad();
}
......
......@@ -3,30 +3,90 @@
*/
import CurseComponent from "@core/curse/CurseComponent";
import {delayLoad} from "../Utils";
import {delayLoad,} from "../Utils";
import defenseService from "../services/DefenseService";
import {broadcast,} from "@core/curse/Manager";
import {waitPromise} from "@alienlib/tools/EgretUtils";
import PanelController from "@core/view/PanelController";
import {PANEL_RESULT} from "../model/constants";
import SceneController from "@core/view/SceneController";
import {catchError} from "@core/ErrorUtils";
import mainService from "../services/MainService";
import dataCenterService from "../services/DataCenterService";
import DoJoin from "./api/DoJoin";
import Submit from "./api/Submit";
export default class ScenePlay extends CurseComponent{
protected reset() {
super.reset();
export default class ScenePlay extends CurseComponent {
btnAdjust: eui.Button = null;
grpAdjust: eui.Group = null;
protected onCreate() {
super.onCreate();
defenseService.setView(this.host);
delayLoad();
this.registerEvent(this.btnAdjust, egret.TouchEvent.TOUCH_TAP, this.onBtnAdjustTap, this);
this.registerEvent(dataCenterService, DoJoin.STORE_KEY, this.onDoJoinResponse, this);
this.registerEvent(dataCenterService, Submit.STORE_KEY, this.onSubmitResponse, this);
}
protected awake() {
super.awake();
broadcast('reset');
this.showAdjust();
}
protected sleep() {
super.sleep();
broadcast('stopGame');
}
protected destroy() {
super.destroy();
}
private onBtnAdjustTap(event) {
this.grpAdjust.visible = false;
broadcast('resetOffset');
this._startGame();
}
private async _startGame() {
broadcast('readyGo');
await waitPromise(3000);
broadcast('startGame');
}
private onDoJoinResponse(event){
PanelController.instance.close(PANEL_RESULT);
this._startGame();
}
endGame(score){
broadcast('submit', null, score);
}
private onSubmitResponse(event){
const {score} = dataCenterService.gameInfo;
PanelController.instance.show(PANEL_RESULT, {score}, this.onPanelResult);
}
showAdjust() {
this.grpAdjust.visible = true;
}
private onPanelResult=(action)=>{
if(action == 'retry'){
}else{
SceneController.back();
}
}
}
/**
* Created by rockyl on 2018/10/10.
*
* 点击开始游戏,并跳转到指定场景
*
* @trigger event TOUCH_TAP
* @trigger broadcast doJoin
*/
import CurseComponent from "src/core/curse/CurseComponent";
import SceneController from "src/core/view/SceneController";
import {catchError} from "src/core/ErrorUtils";
import webService from "@core/WebService";
import dataCenterService from "../../services/DataCenterService";
import {exportField} from "@core/decorators";
import GameConfig from "../../model/GameConfig";
export default class DoJoin extends CurseComponent {
@exportField('目标场景名')
nextScene: string;
public static STORE_KEY: string = 'join-info';
protected onCreate() {
super.onCreate();
this.registerEvent(this.host, egret.TouchEvent.TOUCH_TAP, this.onHostTap, this);
}
private onHostTap(event) {
this.doJoin();
}
private doJoin() {
catchError(this.tryStart());
}
private async tryStart() {
if (dataCenterService.get('playing')) {
return;
}
const token = await getToken();
const orderId = await doJoin(token);
const joinInfo = await getStartStatus(orderId);
dataCenterService.put(DoJoin.STORE_KEY, joinInfo);
dataCenterService.put('playing', true);
if (this.nextScene) {
SceneController.goto(this.nextScene);
}
}
}
async function getToken() {
const {consumerId} = GameConfig;
const params: any = {
timestamp: Date.now(),
activityId,
activityType,
consumerId,
};
const {token} = await webService.callApi(
'/hdtool/ctoken/getTokenNew',
params
);
return devil(token);
}
async function doJoin(token) {
const {oaId, actId, consumerId} = GameConfig;
const params: any = {
actId,
oaId,
activityType,
consumerId,
token,
};
const {orderId} = await webService.callApi(
'/hdtool/dojoin',
params
);
return orderId;
}
async function getStartStatus(orderId) {
const params: any = {
orderId,
};
return await webService.polling(
data => {
return data.result === 2
},
'/hdtool/ngame/getStartStatus',
params
);
}
/**
* Created by rockyl on 2018/10/10.
*
* 点击开始游戏,并跳转到指定场景
*
* @trigger broadcast submit
*/
import CurseComponent from "src/core/curse/CurseComponent";
import SceneController from "src/core/view/SceneController";
import {catchError} from "src/core/ErrorUtils";
import dataCenterService from "../../services/DataCenterService";
import {md5} from "@alienlib/tools/md5";
import webService from "@core/WebService";
import DoJoin from "./DoJoin";
import {exportField} from "@core/decorators";
import GameConfig from "../../model/GameConfig";
export default class Submit extends CurseComponent{
@exportField('目标场景名')
nextScene: string;
public static STORE_KEY: string = 'submit-result-lottery';
submit(score, strategyCollection?, collection?){
catchError(this.trySubmit(score, strategyCollection, collection));
}
private async trySubmit(newScore, strategyCollection, collection){
const {orderId, score, maxScore} = await gameSubmit(newScore, strategyCollection, collection);
const {element, lottery} = await getSubmitResult(orderId);
const gameInfo = dataCenterService.gameInfo;
gameInfo.update(element);
gameInfo.score = score;
gameInfo.maxScore = maxScore;
dataCenterService.put(Submit.STORE_KEY, lottery);
dataCenterService.put('playing', false);
if(this.nextScene){
SceneController.goto(this.nextScene);
}
}
}
async function gameSubmit(score, gameData = [], dynamicData = [[]]) {
const gameDataStr = JSON.stringify(gameData);
const dynamicDataStr = JSON.stringify(dynamicData);
const {orderId, submitToken} = dataCenterService.get(DoJoin.STORE_KEY);
let sign = md5(score + gameDataStr + submitToken + '');
return await webService.callApi(
'/hdtool/ngame/submit',
{
orderId,
score,
gameData: gameDataStr,
sign,
dynamicData: dynamicDataStr,
reviveFlag: 0,
}
);
}
async function getSubmitResult(orderId) {
const {adslotId} = GameConfig;
const params: any = {
orderId,
adslotId,
};
return await webService.polling(
data => {
return !data.flag;
},
'/hdtool/getOrderStatus',
params
);
}
......@@ -4,3 +4,8 @@
declare const recordUrl: string;
declare const resPath: string;
declare const activityId: number;
declare const activityType: string;
declare function getDuibaToken(success, fail);
......@@ -3,32 +3,57 @@
*
* 游戏配置
*/
import {injectProp} from "@alienlib/tools/Utils";
export default class GameConfig extends egret.HashObject {
static gameName: string = '{projectName}';
static gameConfig: any = {};
static appConfig: any = {};
static defenseConfig: any = {};
static actId; //: '3213171',
static oaId; //: '3213171',
static unitName; //: '积分',
static btnUnitName; //: '积分',
static doJoin; //: '/hdtool/doJoin?dpm=1.3.1.0&activityId=3213171',
static quireOrder; //: '/hdtool/getOrderStatus',
static styleConfig; //: '/hdtool/getHdtoolConfig',
static getElement; //: '/hdtool/ajaxElement',
static getPrizeDetail; //: '/hdtool/prizeDetail',
static ajaxThroughInfo; //: '/hdtool/ajaxThroughInfo',
static throughSubmit; //: '/hdtool/throughSubmit',
static gameGetOrder; //: '/hdtool/getOrderInfo',//游戏获取订单信息接口
static gameSubmit; //: '/hdtool/gameSubmit',//游戏结果提交接口
static doSubmit; //: '/hdtool/submit',
static adslotId; //:'',
static consumerId; //:'1',
static isNotLoginUser; //:false,
static uid; //:'1',
static hdType; //: 'duiba',
static hdToolId; //: '41832',
static appType; //: 'credits',
static subType; //: 'cutRope',
static directSendCoupon; //: 'false',
static ajaxAction; //: '',
static recommendQueue; //: '/recommend/getRecommend',
static recommendSkin; //: '/recommend/getRecommendSkin',
static isShowDetail; //: true,
static preview; //: false,
static from; //: '',
static login; //: '//activity.m.duiba.com.cn/hdtool/login?dpm=1.3.3.0',
static flowRedirectUrl; //: '',
static flowRedirectTuiaUrl; //: '',
static isOpenRecommend; //: true,
static appId; //: '1',
static recordUrl; //: '//activity.m.duiba.com.cn/crecord/record?dbnewopen&dpm=1.3.2.0',
static shareDesc; //: '分享分享文案文案',
static entranceDesc; //:'测试领奖,也可到我的奖品领奖,24小时内有效哦',
static isSHowMeat; //: true,
static needCouponModal; //: true, // 给前端用,判断是否需要使用配置的优惠券弹窗
static needRecommendModal; //: true, // 给前端用,判断是否需要公用推荐位弹窗
static asyncFiles; //: [], // 给前端用,异步加载的文件
static shareAndroidLinkActivity; //: 'http://www.duiba.com.cn',
static shareIosLinkActivity; //: 'http://www.iqiyi.com'
static parseConfig() {
const {gameInfo, appInfo, defenseStrategy} = window['CFG'];
const {gameConfig, appConfig, defenseConfig} = this;
const {id, oaId, gameId} = gameInfo;
gameConfig.id = id;
gameConfig.oaId = oaId;
gameConfig.gameId = gameId || window['gameId'];
const {appId, earnCreditsUrl, open, openLogin} = appInfo;
appConfig.appId = appId;
appConfig.earnCreditsUrl = earnCreditsUrl;
appConfig.open = open;
appConfig.openLogin = openLogin;
const {interfaceLimit = 50, scoreUnit = 0} = defenseStrategy;
defenseConfig.interfaceLimit = interfaceLimit;
defenseConfig.scoreUnit = scoreUnit;
injectProp(this, window['CFG']);
}
static initData() {
......
/**
* Created by rockyl on 2018/8/21.
*/
export default class GameInfo{
data:any;
creditUnit;
import {injectProp} from "@alienlib/tools/Utils";
update(data){
this.data = data;
this.data.oldMaxScore = this.data ? this.maxScore : 0;
}
export default class GameInfo {
freeLimit;
needCredits;
credits;
get statusCode(){
return this.data.status.code;
}
maxScore;
score;
get maxScore(){
return this.data.maxScore || 0;
}
get percentage(){
return this.data.percentage;
}
get credits(){
return this.data.credits;
}
get status(){
return this.data.status;
}
get gameId(){
return this.data.gameId;
update(data) {
injectProp(this, data, this.onInject);
}
get consumerId(){
return this.data.consumerId;
private onInject = (target, key, value) => {
switch(key){
case 'myCredits':
key = 'credits';
break;
}
target[key] = value;
}
}
......@@ -11,4 +11,6 @@ export const SCENE_MISSION:string = 'scene_mission';
export const SCENE_DRAW_REWARD:string = 'scene_draw-reward';
export const SCENE_FINAL_REWARD:string = 'scene_final_reward';
export const PANEL_RULE:string = 'panel_rule';
\ No newline at end of file
export const PANEL_ALERT:string = 'panel_alert';
export const PANEL_RULE:string = 'panel_rule';
export const PANEL_RESULT:string = 'panel_result';
\ No newline at end of file
/**
* Created by rockyl on 2018/9/12.
*
* 数据中心
*/
import GameInfo from "./GameInfo";
export const gameInfo: GameInfo = new GameInfo();
export const authData: any = {};
export const pluginInfos = {};
......@@ -4,120 +4,57 @@
* api
*/
import {injectProp} from "@alienlib/tools/Utils";
import {md5} from "@alienlib/tools/md5";
import webService from "../../core/WebService";
import {gameInfo} from "../model/data-center";
import GameConfig from "../model/GameConfig";
import dataCenterService from "../services/DataCenterService";
export async function getToken() {
return new Promise((resolve, reject) => {
if (window['getDuibaToken']) {
getDuibaToken(
({token}) => {
resolve(token);
},
(key, msg) => {
reject(msg);
}
)
} else {
resolve();
}
});
}
export async function getGameInfo() {
const {hdType, actId, preview, hdToolId, adslotId} = GameConfig;
export async function getCredits() {
const {unitName, credits} = await webService.callApi(
'/ctool/getCredits',
{},
const response = await webService.callApi(
'/hdtool/ajaxElement',
{
hdType,
hdToolId,
preview,
actId,
adslotId,
},
'get'
);
gameInfo.creditUnit = unitName;
dataCenterService.put('game-info', response.element);
}
export async function getInfo() {
gameInfo.update(
await webService.callApi(
'/ngame/new/getInfo',
{id: GameConfig.gameConfig.gameId},
'get'
)
);
}
export async function getGameConfig() {
const {hdType, actId, hdToolId} = GameConfig;
export async function getRule() {
return await webService.callApi(
'/ngapi/getRule',
{id: GameConfig.gameConfig.gameId},
'post',
'html'
)
const response = await webService.callApi(
'/hdtool/getHdtoolConfig',
{
actId,
hdType,
hdToolId,
},
'get'
);
const gameConfig = {};
for(let {name, children} of response.defaultConfig){
gameConfig[name] = children;
}
dataCenterService.put('game-config', gameConfig);
}
export async function getRealtimeRank(type, count = 50) {
return await webService.callApi(
'/ngapi/realtimerank/' + type,
{
id: GameConfig.gameConfig.gameId,
id: GameConfig.gameId,
count,
},
'get'
)
}
export async function tryStart() {
await doStart();
const {ticketId} = authData;
await getStartStatus(ticketId);
}
export async function doStart(credits = null, customizedType = null) {
let {gameId, oaId} = GameConfig.gameConfig;
const params: any = {
id: gameId,
oaId: oaId
};
if (credits) {
params.credits = credits;
}
if (customizedType) {
params.customizedType = customizedType;
}
params.token = await getToken();
const {token, submitToken, ticketId} = await webService.callApi(
'/ngapi/dostart',
params
);
injectProp(authData, {
token: devil(token),
submitToken: devil(submitToken),
ticketId
})
}
export async function getStartStatus(ticketId, customizedType = null) {
const params: any = {
ticketId: ticketId
};
if (customizedType) {
params.customizedType = customizedType
}
return await webService.polling(
data => {
return data.code === 1
},
'/ngapi/getStartStatus',
params
);
}
export async function getPrizeInfo(activityId) {
pluginInfos[activityId] = await webService.callApi(
'/activityPlugDrawInfo/getPrizeInfo',
......@@ -139,7 +76,7 @@ export async function datapash(collection) {
await webService.callApi(
'/ngame/new/datapash',
{
gameId: GameConfig.gameConfig.id,
gameId: GameConfig.id,
ticketId: authData.ticketId,
dynamicData: JSON.stringify(collection),
}
......@@ -150,7 +87,7 @@ export async function getRankRewardList(showName = false) {
return webService.callApi(
'/ngapi/winranks',
{
id: GameConfig.gameConfig.gameId,
id: GameConfig.gameId,
showName,
}
);
......@@ -178,76 +115,3 @@ export async function getPlugOrderStatus(orderId) {
10,
);
}
export async function submit(score, collection, strategyCollection) {
const {orderId} = await gameSubmit(score, strategyCollection, collection);
return getSubmitResult(orderId);
}
export async function gameSubmit(score, gameData = [], dynamicData = [[]]) {
const {submitToken, ticketId} = authData;
const gameDataStr = JSON.stringify(gameData);
const dynamicDataStr = JSON.stringify(dynamicData);
let sign = md5(ticketId + '' + score + '' + gameDataStr + '' + submitToken);
const data = await webService.callApi(
'/ngame/new/submit',
{
ticketId,
score,
gameData: gameDataStr,
sgin: sign,
dynamicData: dynamicDataStr
}
);
gameInfo.update(data.rsp);
return data;
}
export async function getSubmitResult(orderId) {
const params: any = {
orderId
};
return await webService.polling(
data => {
return !data.flag;
},
'/ngame/new/getSubmitResult',
params
);
}
export async function getBaiduGameInfo() {
updateBaiduGameInfo(await webService.callApi(
'/aaw/baidu/api/getInfo',
{
activityId: GameConfig.gameConfig.gameId,
},
'get'
));
}
export async function addTimes(type) {
return webService.callApi(
'/aaw/baidu/api/addTimes',
{
activityId: GameConfig.gameConfig.gameId,
type,
},
'get'
);
}
export async function doPlay() {
return webService.callApi(
'/aaw/baidu/api/doPlay',
{
activityId: GameConfig.gameConfig.gameId,
}
);
}
......@@ -8,8 +8,8 @@ import Service from "../../core/Service";
import GameConfig from "../model/GameConfig";
import {JSONP} from "@alienlib/tools/Ajax";
import BuriedPoint from "../model/BuriedPoint";
import {gameInfo} from "../model/data-center";
import webService from "../../core/WebService";
import dataCenterService from "./DataCenterService";
class BuriedPointService extends Service {
private _buriedPoints: any = {};
......@@ -24,8 +24,8 @@ class BuriedPointService extends Service {
initEnv(){
this.env = {
app_id: GameConfig.appConfig.appId,
oaid: GameConfig.gameConfig.oaId,
app_id: GameConfig.appId,
oaid: GameConfig.oaId,
}
}
......@@ -57,8 +57,8 @@ class BuriedPointService extends Service {
log(name, type) {
let logPoint = this._buriedPoints[name];
let {consumerId} = gameInfo;
let {appId} = GameConfig.appConfig;
let {consumerId} = dataCenterService.get('game-info');
let {appId} = GameConfig;
let {dpm, dcm} = logPoint;
if (type == 'exposure') {
......
/**
* Created by rockyl on 2018/11/14.
*
* 数据中心服务
*/
import Service from "@core/Service";
import GameInfo from "../model/GameInfo";
class DataCenterService extends Service {
dataPool: any = {};
gameInfo: GameInfo = new GameInfo();
put(key, data){
const oldData = this.dataPool[key];
this.dataPool[key] = data;
this.dispatchEventWith(key, false, {data, oldData});
}
get(key){
return this.dataPool[key];
}
}
const dataCenterService: DataCenterService = new DataCenterService();
export default dataCenterService;
/**
* Created by rockyl on 2018/8/23.
*
* 防作弊服务
*/
import Service from "../../core/Service";
import GameConfig from "../model/GameConfig";
import * as api from "../net/api";
......@@ -32,7 +35,7 @@ class DefenseService extends Service {
}
scoreChanged(score){
const {interfaceLimit, scoreUnit} = GameConfig.defenseConfig;
const {interfaceLimit, scoreUnit} = GameConfig;
const nextDatapashScore = score - this.pashCount * scoreUnit;
if (scoreUnit == 0 || nextDatapashScore < scoreUnit || this.pashCount > interfaceLimit) {
......
......@@ -6,21 +6,20 @@
import GameConfig from "../model/GameConfig";
import Service from "../../core/Service";
import * as api from '../net/api'
import {gameInfo} from "../model/data-center";
import {SCENE_FINAL_REWARD, SCENE_MENU} from "../model/constants";
import {PopUpManager} from "@alienlib/popup";
import SceneController from "../../core/view/SceneController";
import {getGameInfo} from "../net/api";
import dataCenterService from "./DataCenterService";
class MainService extends Service {
async start() {
GameConfig.parseConfig();
await super.start();
await Promise.all([
api.getInfo(),
getGameInfo(),
//api.getCredits(),
//api.getPrizeInfo(drawPluginId),
//api.plugDrawInfo(drawPluginId),
......@@ -28,8 +27,8 @@ class MainService extends Service {
}
afterStart() {
const code = gameInfo.statusCode;
const sceneName = code == 4 || code == 5 ? SCENE_FINAL_REWARD :
const {status} = dataCenterService.get('game-info');
const sceneName = status == 4 || status == 5 ? SCENE_FINAL_REWARD :
SCENE_MENU;
PopUpManager.removeAllPupUp();
......
......@@ -17,9 +17,7 @@ export class LanguagePack{
me:string;
rank_max_score:string;
rank_reward_content:string;
no_more_items:string;
need_install_app:string;
share_result:any;
result_text:string;
}
export class LanguageIds{
need_login:string = 'need_login';
......@@ -40,7 +38,5 @@ export class LanguageIds{
me:string = 'me';
rank_max_score:string = 'rank_max_score';
rank_reward_content:string = 'rank_reward_content';
no_more_items:string = 'no_more_items';
need_install_app:string = 'need_install_app';
share_result:string = 'share_result';
result_text:string = 'result_text';
}
\ No newline at end of file
......@@ -5,18 +5,22 @@
import '../game/services/StorageService'
import '../game/services/MainService'
import '../game/services/DefenseService'
import '../game/services/BuriedPointService'
import '../game/services/BadgeService'
import '../game/components/SceneMenu'
import '../game/components/Badge'
import '../game/components/ButtonStart'
import '../game/components/BuriedPointButton'
import '../game/components/Breath'
import '../game/components/api/DoJoin'
import '../game/components/ButtonRule'
import '../game/components/BuriedPointButton'
import '../game/components/ScenePlay'
import '../game/components/api/Submit'
import '../game/components/ButtonBack'
import '../game/components/GameViewLabel'
import '../game/components/GameView'
import '../game/components/ReadyGo'
import '../game/components/PanelRule'
import '../game/components/PanelResult'
import '../game/components/api/DoJoin'
import '../game/components/PanelAlert'
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