mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 16:46:00 +00:00
UpgradesModalWindow
This commit is contained in:
@@ -2,7 +2,7 @@ import { sys } from "cc";
|
||||
import { UserData } from "../Game/Data/UserData";
|
||||
|
||||
export class SaveSystem {
|
||||
private userDataIdentifier = "user-d";
|
||||
private userDataIdentifier = "user-de";
|
||||
public save(userData: UserData): void {
|
||||
sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData));
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
export class UserData {
|
||||
public soundVolume = 0;
|
||||
public musicVolume = 0;
|
||||
public soundVolume = 1;
|
||||
public musicVolume = 1;
|
||||
public game = new GameData();
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { instantiate, Label, Node, Prefab, TiledUserNodeData, _decorator } from "cc";
|
||||
import { AudioClip, instantiate, Label, Node, Prefab, _decorator } from "cc";
|
||||
import { AppRoot } from "../../../AppRoot/AppRoot";
|
||||
import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings";
|
||||
import { UserData, GameData, MetaUpgradesData } from "../../../Game/Data/UserData";
|
||||
import { MetaUpgradeType, UpgradeType } from "../../../Game/Upgrades/UpgradeType";
|
||||
import { MetaUpgradesData, UserData } from "../../../Game/Data/UserData";
|
||||
import { MetaUpgradeType } from "../../../Game/Upgrades/UpgradeType";
|
||||
import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow";
|
||||
import { UpgradeUI } from "./UpgradeUI";
|
||||
|
||||
@@ -13,6 +13,7 @@ export class UpgradesModalWindow extends ModalWindow<Empty, Empty> {
|
||||
@property(Prefab) private upgradeButtonPrefab: Prefab;
|
||||
@property(Node) private upgradeButtonParent: Node;
|
||||
@property(Label) private goldCoinsLabel: Label;
|
||||
@property(AudioClip) private upgradeAudioClip: AudioClip;
|
||||
|
||||
private typeToLevel = new Map<MetaUpgradeType, number>();
|
||||
private typeToCosts = new Map<MetaUpgradeType, number[]>();
|
||||
@@ -62,12 +63,15 @@ export class UpgradesModalWindow extends ModalWindow<Empty, Empty> {
|
||||
if (costs.length <= currentLevel) return; // already max level
|
||||
if (this.userData.game.goldCoins < costs[currentLevel]) return; // not enough gold
|
||||
|
||||
AppRoot.Instance.AudioPlayer.playSound(this.upgradeAudioClip);
|
||||
|
||||
this.userData.game.goldCoins -= costs[currentLevel];
|
||||
const level = ++this.userData.game.metaUpgrades[this.typeToLevelKey.get(upgradeType)];
|
||||
this.typeToUpgradeUI.get(upgradeType).updateLevel(level);
|
||||
this.typeToLevel.set(upgradeType, level);
|
||||
|
||||
this.goldCoinsLabel.string = this.userData.game.goldCoins.toString();
|
||||
AppRoot.Instance.saveUserData;
|
||||
AppRoot.Instance.saveUserData();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user