Commit 1f711c06 authored by rockyl's avatar rockyl

调整目录

parent 629230a5
......@@ -7,7 +7,7 @@
import Service from "../../core/Service";
import GameConfig from "../model/GameConfig";
import {JSONP} from "@alienlib/tools/Ajax";
import BuriedPoint from "../net/BuriedPoint";
import BuriedPoint from "../model/BuriedPoint";
import {gameInfo} from "../model/data-center";
import webService from "../../core/WebService";
......
/**
* Created by rockyl on 2018/8/21.
*/
export default class GameInfo{
data:any;
creditUnit;
update(data){
this.data = data;
this.data.oldMaxScore = this.data ? this.maxScore : 0;
}
get statusCode(){
return this.data.status.code;
}
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;
}
get consumerId(){
return this.data.consumerId;
}
}
export class LanguagePack{
need_login:string;
net_error:string;
current_score:string;
max_score:string;
score_unit:string;
free:string;
my_credit:string;
no_more_credits:string;
revive_cost:string;
revive_failed:string;
rank_first:string;
rank_second:string;
rank_third:string;
rank_num:string;
rank_out:string;
me:string;
rank_max_score:string;
rank_reward_content:string;
no_more_items:string;
need_install_app:string;
share_result:any;
}
export class LanguageIds{
need_login:string = 'need_login';
net_error:string = 'net_error';
current_score:string = 'current_score';
max_score:string = 'max_score';
score_unit:string = 'score_unit';
free:string = 'free';
my_credit:string = 'my_credit';
no_more_credits:string = 'no_more_credits';
revive_cost:string = 'revive_cost';
revive_failed:string = 'revive_failed';
rank_first:string = 'rank_first';
rank_second:string = 'rank_second';
rank_third:string = 'rank_third';
rank_num:string = 'rank_num';
rank_out:string = 'rank_out';
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';
}
\ 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 = {};
/**
* Created by rockyl on 2018/8/23.
*
* 任务服务
*/
import Service from "./Service";
import {BADGE_CHANGED} from "../model/events";
class BadgeService extends Service {
items: any;
async start(): Promise<void> {
await super.start();
this.items = {};
}
private getItem(name){
let item = this.items[name];
if(!item){
item = this.items[name] = {
number: 0,
};
}
return item;
}
private updateItem(name, item, number){
item.number = number;
this.dispatchEventWith(BADGE_CHANGED, false, {name, number})
}
update(name, number){
const item = this.getItem(name);
this.updateItem(name, item, number);
}
change(name, number){
const item = this.getItem(name);
this.updateItem(name, item, item.number + number);
}
getNumber(name){
const item = this.getItem(name);
return item.number;
}
}
const badgeService: BadgeService = new BadgeService();
export default badgeService;
/**
* Created by rockyl on 2018/9/29.
*
* 埋点服务
*/
import Service from "./Service";
import GameConfig from "../model/GameConfig";
import {JSONP} from "@alienlib/tools/Ajax";
import webService from "../net/WebService";
import BuriedPoint from "../net/BuriedPoint";
import {gameInfo} from "../model/data-center";
class BuriedPointService extends Service {
private _buriedPoints: any = {};
env: any;
async start(): Promise<void> {
await super.start();
this.initEnv();
}
initEnv(){
this.env = {
app_id: GameConfig.appConfig.appId,
oaid: GameConfig.gameConfig.oaId,
}
}
addBuriedPoints(buriedPoints) {
for (let name in buriedPoints) {
this._buriedPoints[name] = buriedPoints[name];
}
}
addBuriedPointConfig(name, config) {
const {dpm, dcm} = config;
this._buriedPoints[name] = new BuriedPoint(dpm, dcm, this.env);
}
addBuriedPointConfigs(configs) {
for (let name in configs) {
this.addBuriedPointConfig(name, configs[name]);
}
}
logExposure(name) {
return this.log(name, 'exposure');
}
logClick(name) {
return this.log(name, 'click');
}
log(name, type) {
let logPoint = this._buriedPoints[name];
let {consumerId} = gameInfo;
let {appId} = GameConfig.appConfig;
let {dpm, dcm} = logPoint;
if (type == 'exposure') {
return JSONP('//embedlog.duiba.com.cn/exposure/standard', {
dpm, dcm, consumerId, appId,
}, 'get').catch(e => {
//console.log(e);
});
} else {
return webService.callApi(
'/log/click',
{
dpm, dcm, consumerId, appId
},
'get'
).catch(e => {
//console.log(e);
});
}
}
}
const buriedPointService: BuriedPointService = new BuriedPointService();
export default buriedPointService;
/**
* Created by rockyl on 2018/8/23.
*/
import Service from "./Service";
import GameConfig from "../model/GameConfig";
import * as api from "../net/proxy";
class DefenseService extends Service {
collection: any[] = [];
strategyCollection: any[] = [];
pashCount;
setView(view){
this.registerEvent(view, egret.TouchEvent.TOUCH_BEGIN, this.onTouch.bind(this, 'md'), this);
}
reset() {
this.collection.splice(0);
this.strategyCollection.splice(0);
this.pashCount = 0;
}
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)
}
scoreChanged(score){
const {interfaceLimit, scoreUnit} = GameConfig.defenseConfig;
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,
}
}
}
const defenseService: DefenseService = new DefenseService();
export default defenseService;
\ No newline at end of file
/**
* Created by admin on 2017/6/26.
*
* 主服务
*/
import GameConfig from "../model/GameConfig";
import Service from "./Service";
import * as api from '../net/proxy'
class MainService extends Service {
async start() {
GameConfig.parseConfig();
await super.start();
await Promise.all([
api.getInfo(),
//api.getCredits(),
//api.getPrizeInfo(drawPluginId),
//api.plugDrawInfo(drawPluginId),
])
}
}
const mainService: MainService = new MainService();
export default mainService
/**
* Created by admin on 2017/6/16.
*
* 存储数据服务
*/
import Service from "./Service";
import {LocalStorage} from "@alienlib/support";
import {SETTING_CHANGED} from "../model/events";
class StorageService extends Service{
protected store:any;
protected _initialized;
start(): Promise<any> {
this.load();
this.store.launch_count = this.store.launch_count ? this.store.launch_count + 1 : 1;
this.save();
return super.start();
}
private load(){
this.store = LocalStorage.getItemObj('store', {});
}
save(){
LocalStorage.setItemObj('store', this.store);
}
clean(keeps = null){
if(keeps){
for(let k in this.store){
if(keeps.indexOf(k) < 0 && this.store.hasOwnProperty(k)){
delete this.store[k];
}
}
}else{
this.store = {};
}
this.save();
this._initialized = false;
}
get launchCount(){
return this.store.launch_count;
}
getSettingItem(field){
return this.store.setting ? (this.store.setting[field] === undefined ? true : this.store.setting[field]) : true;
}
setSettingItem(field, value, dispatch = true){
let setting = this.store.setting;
if(!setting){
setting = this.store.setting = {};
}
setting[field] = value;
this.save();
if(dispatch){
this.dispatchEventWith(SETTING_CHANGED, false, {field, value});
}
}
switchSettingItem(field, dispatch = true){
this.setSettingItem(field, !this.getSettingItem(field), dispatch);
}
}
const storageService:StorageService = new StorageService();
export default storageService;
\ 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