[add] first

This commit is contained in:
2023-02-22 09:50:51 +08:00
commit 6260e95bc8
9053 changed files with 4492644 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
import { game, math, PhysicsSystem } from "cc";
import { Save } from "./save";
import { Local } from "../../core/localization/local";
import { Msg } from "../../core/msg/msg";
import { Singleton } from "../../core/pattern/singleton";
import { ResCache } from "../../core/res/res-cache";
export class GameQuality extends Singleton {
index: number = 0;
max: number = 2;
_data = Object.create(null);
_map = Object.create(null);
cur = {
"name": "game_quality_high",
"level": -1,
"fps": 59.9,
"maxSubSteps": 1,
"open_ik": true
};
_default = 0;
public init (): void {
this._data = ResCache.Instance.getJson('data-quality').json;
this.index = 0;
if (this.index < 0) this.index = 0;
if (this.index >= this._data.set.length) this.index = this.index = this._data.set.length - 1;
this._default = this.index;
this.cur = this._data.set[this.index];
PhysicsSystem.instance.maxSubSteps = 10;
// game.frameRate = this.cur.fps;
Msg.on('next_quality', () => {
this.index++;
if (this.index >= this._data.set.length) this.index = 0;
this.cur = this._data.set[this.index];
Save.Instance._cur.game_quality = this.index;
Local.Instance.refresh();
});
Msg.on('pre_quality', () => {
this.index--;
if (this.index < 0) this.index = this._data.set.length - 1;
this.cur = this._data.set[this.index];
Save.Instance._cur.game_quality = this.index;
Local.Instance.refresh();
});
Msg.on('msg_check_change', this.checkChange.bind(this));
}
public checkChange () {
if (this._default !== this.index) {
// Restart game.
globalThis.window.location.reload();
}
}
public getShowName () {
return Local.Instance.get(this._data.set[this.index].name);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5d6ea56e-2116-44d5-888d-443ef432a621",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,104 @@
import { _decorator, Component, Node } from 'cc';
import { UtilTime } from '../../core/util/util';
import { Save } from './save';
import { Singleton } from '../../core/pattern/singleton';
import { DataGameInst } from './data-core';
const { ccclass, property } = _decorator;
@ccclass('Achievement')
export class Achievement extends Singleton {
public percent:number = 0;
public unlockAllAchi = false;
public init() {
var achievement = DataGameInst._data['achievement'];
var achi_save = Save.Instance.get('achievement');
//if (achi_save === undefined) {
Save.Instance._cur['achievement'] = {};
achi_save = Save.Instance.get('achievement');
//}
for(let i = 0; i < achievement.length; i++) {
var arch = achievement[i];
var arch_save = achi_save[arch.name];
if (arch_save === undefined) achi_save[arch.name] = { "name":arch.name,"condition":arch.condition,"value":arch.value,"percent":0,"stat_value":0 };
}
Save.Instance._cur['achievement'] = achi_save;
this.updateData();
}
public totalTime():string {
var time = Save.Instance.statisticsValue('level_playTime');
if (time === undefined) time = 0;
time = UtilTime.toHours(time);
return `${time}`;
}
public totalPercent():number {
return this.percent;
}
public getAchi(key:string) {
var achievement = Save.Instance.get('achievement');
return achievement[key];
}
public updateData() {
var achi_save = Save.Instance.get('achievement');
var statistics = Save.Instance.get('statistics');
if (Save.Instance.get('achi_percent') === 1) return;
var count = 1;
//achi_save.forEach(arch => {
for(const key in achi_save) {
var achi = achi_save[key];
if (achi['percent'] !== 1) {
var stat_value = statistics[achi.value];
if (stat_value === undefined) continue;
if (stat_value > achi.condition) stat_value = achi.condition;
achi['stat_value'] = stat_value;
var arch_percent = stat_value / achi.condition;
achi['percent'] = arch_percent;
achi['unlock_time'] = UtilTime.yearMonth();
}
this.percent += achi['percent'];
count++;
};
this.percent /= count;
this.unlockAllAchi = this.percent === 1;
Save.Instance._cur['achi_percent'] = this.percent;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "40889af1-7210-4174-a66d-a052fa15bc5b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,193 @@
/*
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { Msg } from "../../core/msg/msg";
import { Singleton } from "../../core/pattern/singleton";
import { Local } from "../../core/localization/local";
import { GameQuality } from "./GameQuality";
import { Sound } from "../../core/audio/sound";
import { ResCache } from "../../core/res/res-cache";
import { Level } from "../level/level";
import { Save } from "./save";
export class Bind extends Singleton {
// Event dictionary, used to construct the mapping of keys to events.
_map: { [name: string]: Function } = {}
// Total number of events.
totalEvents = 0;
public init (): void {
// Registered events are used to count the total number of events.
Msg.on('msg_count_events', this.countEvents.bind(this));
// Bind the skill detail 0.
this._map['txt_upgrade_life_detail'] = () => Level.Instance.getUpgradeCardInfo(0);
// Bind the skill detail 1.
this._map['txt_upgrade_attack_detail'] = () => Level.Instance.getUpgradeCardInfo(1);
// Bind the skill detail 2.
this._map['txt_upgrade_defense_detail'] = () => Level.Instance.getUpgradeCardInfo(2);
// Bind the button event of skill upgrade tab 0.
this._map['btn_select_upgrade_0'] = () => {
Level.Instance.upgradePlayerAttributes(0);
Msg.emit('back');
}
// Bind the button event of skill upgrade tab 1.
this._map['btn_select_upgrade_1'] = () => {
Level.Instance.upgradePlayerAttributes(1);
Msg.emit('back');
}
// Bind the button event of skill upgrade tab 2.
this._map['btn_select_upgrade_2'] = () => {
Level.Instance.upgradePlayerAttributes(2);
Msg.emit('back');
}
// Bind the current language name.
this._map['txt_language'] = () => Local.Instance.getShowName();
// Bind the current game quality name.
this._map['txt_game_quality'] = () => GameQuality.Instance.getShowName();
// Bind the current volume value.
this._map['sli_sound'] = () => Sound.volumeSound;
// Bind the current music volume value.
this._map['sli_music'] = () => Sound.volumeMusic;
// Bind game result score.
this._map['spr_score'] = () => {
const imgSrc = `txt_score_${Level.Instance.getLevelScore()}`;
return ResCache.Instance.getSprite(imgSrc);
}
// Bind level over killed value.
this._map['txt_killed'] = () => Save.Instance.getStatistics('killedTimes');
// Bind level over hit value.
this._map['txt_hit_head'] = () => Save.Instance.getStatistics('hit_headTimes');
// Bind level over Hit Rate.
this._map['txt_hsp'] = () => `${(Save.Instance.getStatistics('hit_rate') * 100).toFixed(2)} %`;
// Bind level over hit value.
this._map['txt_be_hit'] = () => Save.Instance.getStatistics('be_hit_times');
// Bind dodge rate.
this._map['txt_dodge'] = () => `${(Save.Instance.getStatistics('dodge_rate') * 100).toFixed(2)} %`;
// Bind level score.
this._map['txt_level_score'] = () => `${Save.Instance.getStatistics('level_score')}`;
// Bind day value.
this._map['txt_day_num'] = () => `${Save.Instance.get('day')}`;
}
/**
* The method is used to initialize the event binder.
* @param data The data is game events mapping.
*/
public initData (data: [{ name: string, event: string, data: string | undefined }]) {
this.init();
data.forEach(events => {
let name = events.name;
let event = events.event;
let data = events.data;
if (!events.data) data = undefined;
this._map[name] = () => {
Msg.emit(event, data);
}
});
}
/**
* This method is used to execute specific events by key.
* @param key The name of the event to execute.
*/
public on (key: string) {
var event = this._map[key];
if (event) {
event();
this.countEvents();
} else {
console.warn('Can not find key:' + key);
}
}
/**
* This method is to get this event and return the result of executing the method.
* @param key The key is event to execute.
* @returns
*/
public get (key: string) {
return this._map[key]();
}
/**
* This method is used to determine if the event is mapped or not.
* @param key The key of the event to be judged.
* @returns
*/
public hasBind (key: string): boolean {
return this._map[key] !== undefined;
}
/**
* Current frame event execution statistics.
*/
public countEvents () {
this.totalEvents++;
}
/**
* Check if the count needs to be refreshed according to the current frame.
*/
public checkRefresh () {
if (this.totalEvents > 0) {
Msg.emit("refresh_ui");
this.totalEvents = 0;
}
}
/**
* This method is an update function for each frame.
* @param deltaTime This value is the execution time per frame.
*/
public update (deltaTime: number): void {
// Check if a refresh is needed.
this.checkRefresh();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "87dbc93c-9846-4ce2-a73f-4b6be63cf1bc",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,23 @@
import { Singleton } from "../../core/pattern/singleton";
import { ResCache } from "../../core/res/res-cache";
export class Buff extends Singleton {
_data = {};
public init(): void {
this._data = ResCache.Instance.getJson('data-buff').json;
}
public get(key) {
if (this._data[key]) {
return this._data[key];
}else{
console.error('can not find buff:', key);
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "05297ed3-085e-460f-b215-7f5c343b805f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,6 @@
import { Camera, director, game, Scene } from "cc";
import { DataBase } from "../../core/data/data-base";
import { Msg } from "../../core/msg/msg";
export class DataCamera extends DataBase {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "45947891-ce2d-4990-9a83-778ecff05af7",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,26 @@
import { DataEquip } from "../../logic/data/data-equip";
import { DataSound } from "../../logic/data/data-sound";
import { DataCamera } from "./data-camera";
import { DataGame } from "./data-game";
import { DataLevel } from "./data-level";
import { DataNavigation } from "./data-navigation";
import { DataUpgradeCard } from "./data-upgrade-card";
export const DataEquipInst = new DataEquip();
export const DataSoundInst = new DataSound();
export const DataCameraInst = new DataCamera();
export const DataNavigationInst = new DataNavigation();
export const DataUpgradeCardInst = new DataUpgradeCard();
export const DataGameInst = new DataGame();
export const DataLevelInst = new DataLevel();
export function Init() {
//Init data.
DataEquipInst.init('data-equips');
DataSoundInst.init('data-sound');
DataCameraInst.init('data-camera');
DataNavigationInst.init('data-navigation');
DataUpgradeCardInst.init('data-upgrade-card');
DataGameInst.init('data-game');
DataLevelInst.init('data-level');
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "d7e0859d-9634-4966-8b84-7dd48cca642e",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,4 @@
import { DataBase } from "../../core/data/data-base";
export class DataEquip extends DataBase {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a9ecb15d-668f-4572-ac55-2f93b3f20e0c",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,4 @@
import { DataBase } from "../../core/data/data-base";
export class DataGame extends DataBase {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bf414ed5-1494-4f52-89cc-6f5d895c2c43",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,4 @@
import { DataBase } from "../../core/data/data-base";
export class DataLevel extends DataBase {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "da03d9ac-6916-43be-b683-71aaaeb06621",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,4 @@
import { DataBase } from "../../core/data/data-base";
export class DataNavigation extends DataBase {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a28cf226-f524-4cf0-9edc-9a5921cee53e",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,4 @@
import { DataBase } from "../../core/data/data-base";
export class DataSound extends DataBase {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f8b5552c-1913-40c9-9ce4-dda2dbb69247",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,4 @@
import { DataBase } from "../../core/data/data-base";
export class DataUpgradeCard extends DataBase {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "02b9a859-4540-40ed-b8cd-323078b417ab",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,12 @@
import { _decorator, Component, Node, Label, Sprite, Button, EditBox, Toggle, Slider } from 'cc';
import { FilSmooth } from '../../core/ui/fil-smooth';
const { ccclass, property } = _decorator;
export type type_x_y = {
x: number,
y: number,
}
export type KeyAnyType = {
[key:string]:any;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "569cd6b1-546c-4159-82d3-e43bf087995d",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,209 @@
/*
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { Node, find, game } from "cc";
import { Action } from "../../core/action/action";
import { Singleton } from "../../core/pattern/singleton";
import { UI } from '../../core/ui/ui';
import { Bind } from './bind'
import { Local } from "../../core/localization/local";
import { Save } from "./save";
import { Msg } from "../../core/msg/msg";
import { Stack } from "../../core/util/data-structure";
import { Level } from "../level/level";
import { Sound } from "../../core/audio/sound";
import { Notify } from "../../core/io/notify";
import { GameQuality as GameQuality } from "./GameQuality";
import * as dataCore from "./data-core";
import { BindUI } from "../../core/ui/ui-base";
export class Game extends Singleton {
// Action objects are used to execute the current set of actions.
_action: Action | undefined;
// The stack collection is used to manage the current node order.
_stack: Stack<string> = new Stack(5);
// The key-value collection is used to store all the game node data.
_nodes: { [key: string]: any } = {};
// Game data object to store static game data.
_data: { [key: string]: any } = {};
// If or not the game is initialized, true is initialized, false is not initialized.
_isInit = false;
// Total game time, used to store the total time the game has been running.
_totalGameTime = 0;
// The next storage time point is used to control the event interval control for automatic storage.
_nextSaveTime = 0;
// Current game node name, used to record the current game node name.
_currentGameNodeName = '';
// The root node of all pool objects game runtime.
_poolNode: Node | null | undefined;
// Safe time for back
backSafeTime = 0;
public init (): void {
// Find the root node of all pool objects.
this._poolNode = find('init')?.getChildByName('objects-pool');
// Initialize the data core.
dataCore.Init();
// Initialize local storage.
Save.Instance.init();
// Initialize the game data.
this._data = dataCore.DataGameInst._data;
// Initialize game action data.
this._action = new Action(this._data.action_data);
// Get the game node data.
this._nodes = this._data['nodes'];
// Initialize the game quality.
GameQuality.Instance.init();
// Initialize the sound manager.
Sound.init();
// Initialize localization.
Local.Instance.init();
// Initialize the level object.
Level.Instance.init();
// Initialize the UI binding.
BindUI.init();
// Initialize the binder.
Bind.Instance.initData(this._data['events']);
// Initialize the UI management object.
UI.Instance.init();
// Register game node stack operation method.
Msg.on('push', (key: string) => { Game.Instance.push(key); });
Msg.on('root', (key: string) => { Game.Instance.root(key); });
Msg.on('next', this.next.bind(this));
Msg.on('back', this.back.bind(this));
// Push the game initial node into the stack data.
this.push(this._data['start_node']);
//Set game initialization to true.
this._isInit = true;
// Check if a message currently exists.
// Why it is detected after initialization: because messages may not be displayed properly during initialization.
Notify.Instance.check_notify();
}
/**
* Jump to the next game node.
*/
public next (): void {
var cur = this._stack.cur();
const nextAction = this._nodes[cur].next;
if (nextAction) this.push(nextAction);
}
/**
* Return to the previous game node.
*/
public back (): void {
if (game.totalTime - this.backSafeTime < 50) return;
this.backSafeTime = game.totalTime;
const preNode = this._stack.pop();
this._action!.off(preNode);
}
/**
* Returns to the game root node corresponding to the name.
* @param name
*/
public root (name: string): void {
var size = this._stack.size() - 1;
for (let i = 0; i < size - 1; i++) {
let pre = this._stack.pop();
this._action!.off(pre);
}
}
/**
* Pushes a new game node.
* @param name node name.
*/
public push (name: string) {
this._currentGameNodeName = name;
if (!this._nodes[name].is_pop && this._stack.size() > 0) {
var pre = this._stack.pop();
this._action!.off(pre);
}
this._stack.push(name);
this._action!.on(name);
}
public update (deltaTime: number): void {
// If initialization false returns, initialization success continues.
if (!this._isInit) return;
//Increase the game time, The accumulated time is the length of each frame.
this._totalGameTime += deltaTime;
// Update the game action logic every frame.
Game.Instance._action.update(deltaTime);
// Update the level logic every frame.
Level.Instance.update(deltaTime);
// Update the binder logic every frame.
Bind.Instance.update(deltaTime);
// Automatic save judgment: true is on, false is off
if (this._data.auto_save) {
// When the current total time of the game is greater than the next time node.
// true is to update the game storage logic.
// false is to wait.
if (this._totalGameTime > this._nextSaveTime) {
// Updates the current game time stats.
Save.Instance.statisticsTime('game', Math.floor(this._data.next_save_time));
this._nextSaveTime += this._data.next_save_time
}
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f1830bc9-1d25-4331-91fc-c0c7007064e5",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,253 @@
/*
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { Singleton } from "../../core/pattern/singleton"
import { GMath } from '../../core/util/g-math';
import { IO } from "../../core/io/io";
import { UtilArray } from "../../core/util/util";
import { JsonTool } from "../../core/io/json-tool";
import { Msg } from "../../core/msg/msg";
import { ResCache } from "../../core/res/res-cache";
const max_history_statistics = 30;
interface key_any {
[key: string]: any
}
export class Save extends Singleton {
_uuid = '';
_cur: key_any = {};
_uuidKey = 'uuid';
_archiveKey = 'archive_list';
_archiveList: string[] | undefined;
_saveJson:any;
_backup_counter = 0;
_currentStatistics:key_any = {};
get PlayerID() {
if (this._cur.player_id === undefined) this._cur.player_id = 27;
return this._cur.player_id;
}
public init (): void {
this._saveJson = ResCache.Instance.getJson('data-save').json;
if (!IO.exist(this._archiveKey + '.json')) {
this._archiveList = [];
this.newArchive();
} else {
this._archiveList = JsonTool.toIOObject(this._archiveKey);
this._uuid = this._archiveList![0];
this.loadArchive(this._uuid);
this._uuid = IO.read(this._uuidKey + '.json');
}
Msg.on('msg_save_set', (data:{key:string, value:number})=>{
this.set(data.key, data.value);
});
Msg.on('msg_stat_times', this.statisticsTimes.bind(this));
Msg.on('msg_stat_time', this.statisticsTime.bind(this));
Msg.on('msg_stat_distance', this.statisticsDistance.bind(this));
Msg.on('msg_save_archive', this.saveArchive.bind(this));
}
public backup() {
this._backup_counter--;
if (this._backup_counter > 0) return;
this._backup_counter = 5;
}
public saveArchiveList () {
IO.write(this._archiveKey + '.json', JsonTool.toJson(this._archiveList));
}
public saveArchive () {
try {
//Achievement.Instance.updateData();
var data = JsonTool.toJson(this._cur);
IO.write(this._uuid + '.json', data);
this.backup();
}catch(error){
console.error('save archive error.');
}
}
public hasArchive (): boolean {
return this._archiveList!.length > 0;
}
public newArchive () {
this._cur = this._saveJson;
this._uuid = GMath.uuid();
this._archiveList!.push(this._uuid);
IO.write(this._uuidKey + '.json', this._uuid);
this.saveArchive();
this.saveArchiveList();
}
public loadArchive (name: string) {
this._uuid = name;
IO.write(this._uuidKey + '.json', this._uuid);
let read_data = IO.read(name + '.json');
//console.log(name, read_data);
if (read_data === undefined) {
console.error('can not read data uuid key:', this._uuid);
this._cur = Object.assign(this._saveJson);
}else{
this._cur = JsonTool.toObject(read_data) as IArchive;
}
// Add new data input index.
if (this._cur.input_index === undefined) this._cur.input_index = 0;
}
public loadBackup (name: string) {
this._uuid = name;
var data = IO.read(name + '_b0.json');
this._cur = JsonTool.toObject(data) as IArchive;
}
public deleteArchive (name: string) {
UtilArray.remove(this._archiveList!, name);
this.saveArchiveList();
IO.delete(name + '.json');
}
public deleteAllArchive () {
if (this._archiveList) {
this._archiveList.forEach(element => {
IO.delete(element + '.json');
});
this._archiveList = undefined;
}
IO.delete(this._archiveKey + '.json');
IO.delete(this._uuid + '.json');
}
public get<T> (name: string): T {
try {
return this._cur[name];
} catch {
throw new Error(`Save not find key's value. The key is : ${name}`);
}
}
public set<T> (name: string, value: T) {
this._cur[name] = value;
this.saveArchive();
}
setValue(name:string, value:any) {
this._cur[name] = value;
}
public setStatistics(name:string, value:number) {
this._currentStatistics[name] = value;
}
public getStatistics(name: string) {
const value = this._currentStatistics[name];
return value === undefined ? 0 : value;
}
public saveGameOver () {
this.statisticsFinalScore();
}
public clearByKey(key:string) {
this._cur[key] = {};
this.saveArchive();
}
public statisticsTimes(key:string) {
var statKey = key + 'Times'
if (this._currentStatistics[statKey] === undefined) this._currentStatistics[statKey] = 0;
this._currentStatistics[statKey] += 1;
}
public statisticsTime(data:{key:string, time:number}) {
var statKey = data.key + 'Time';
if (this._currentStatistics[statKey] === undefined) this._currentStatistics[statKey] = 0;
this._currentStatistics[statKey] += data.time;
}
public statisticsDistance(data:{key:string, distance:number}) {
var statKey = data.key + 'Distance';
if (this._currentStatistics[statKey] === undefined) this._currentStatistics[statKey] = 0;
this._currentStatistics[statKey] += data.distance;
}
public statisticsValue(key:string): number {
return this._currentStatistics[key];
}
public statisticsFinalScore() {
for(let k in this._currentStatistics) {
this._cur.statistics[k] += this._currentStatistics[k];
}
}
public nextStatistics() {
if(this._cur.history_index === undefined) this._cur.history_index = -1;
this._cur.history_index++;
console.log('history index:', this._cur.history_index);
if(this._cur.history_index > max_history_statistics)
this._cur.history_index = 0;
if(this._cur.history === undefined) this._cur.history = [];
if(this._cur.history_index >= this._cur.history.length) {
this._cur.history.push({});
}
this._currentStatistics = this._cur.history[this._cur.history_index];
}
}
export interface IArchive {
totalTime: number;
playTimes: 0;
language: string;
name: string;
nickname: string;
money: number;
guideIndex: 0;
mapAutoIndex: 10;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "370a30db-de4b-4c0b-94f9-bd3779468a51",
"files": [],
"subMetas": {},
"userData": {}
}