Slash-The-Hordes/assets/Scripts/Game/TestGameRunner.ts

62 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-12-19 11:00:55 +00:00
import { CCInteger, Component, _decorator } from "cc";
2022-12-16 11:01:25 +00:00
import { AppRoot } from "../AppRoot/AppRoot";
2022-12-12 08:15:27 +00:00
import { GameRunner } from "../Menu/GameRunner";
import { delay } from "../Services/Utils/AsyncUtils";
2022-12-19 11:00:55 +00:00
import { GameSettings, ISpawner } from "./Data/GameSettings";
2022-12-13 10:58:40 +00:00
import { UserData } from "./Data/UserData";
2022-12-12 08:15:27 +00:00
import { Game } from "./Game";
2022-12-13 10:58:40 +00:00
const { ccclass, property } = _decorator;
2022-12-12 08:15:27 +00:00
@ccclass("TestGameRunner")
export class TestGameRunner extends Component {
2022-12-19 11:00:55 +00:00
@property(CCInteger) private startTime = 0;
@property(CCInteger) private startXP = 0;
2022-12-13 10:58:40 +00:00
@property(CCInteger) private maxHpLevel = 0;
@property(CCInteger) private bonusDamageLevel = 0;
@property(CCInteger) private projectilePiercingLevel = 0;
@property(CCInteger) private movementSpeedLevel = 0;
@property(CCInteger) private xpGathererLevel = 0;
@property(CCInteger) private goldGathererLevel = 0;
2022-12-12 08:15:27 +00:00
public start(): void {
if (GameRunner.Instance.IsRunning) return;
this.playTestGameAsync();
}
public async playTestGameAsync(): Promise<void> {
2022-12-16 11:01:25 +00:00
while (Game.Instance == null || AppRoot.Instance == null) await delay(100);
2022-12-13 10:58:40 +00:00
const testUserData = new UserData();
2022-12-16 12:52:54 +00:00
testUserData.game.metaUpgrades.healthLevel = this.maxHpLevel;
testUserData.game.metaUpgrades.overallDamageLevel = this.bonusDamageLevel;
2022-12-13 10:58:40 +00:00
testUserData.game.metaUpgrades.projectilePiercingLevel = this.projectilePiercingLevel;
testUserData.game.metaUpgrades.movementSpeedLevel = this.movementSpeedLevel;
testUserData.game.metaUpgrades.xpGathererLevel = this.xpGathererLevel;
testUserData.game.metaUpgrades.goldGathererLevel = this.goldGathererLevel;
2022-12-19 11:00:55 +00:00
const settings = this.getTimeModifiedSettings(AppRoot.Instance.Settings);
Game.Instance.playGame(testUserData, settings, AppRoot.Instance.TranslationData, { startTime: this.startTime, startXP: this.startXP });
}
private getTimeModifiedSettings(settings: GameSettings): GameSettings {
const spawners: ISpawner[] = [
...settings.enemyManager.circularEnemySpawners,
...settings.enemyManager.individualEnemySpawners,
...settings.enemyManager.waveEnemySpawners
];
for (const spawner of spawners) {
spawner.common.startDelay -= this.startTime;
spawner.common.stopDelay -= this.startTime;
}
return settings;
2022-12-12 08:15:27 +00:00
}
}
2022-12-19 11:00:55 +00:00
export class TestValues {
public startTime = 0;
public startXP = 0;
}