12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- class PlayerProgress {
- constructor() {
- this.progress = {};
- this.progressChains = {};
- this.unlocks = [];
- }
- async init() {
- this.progressChains = await system.jsonGet(`/api/progress`, {});
- this.progress["starting"] = this.progressChains["starting"][0];
- }
- getProgress(chainName) {
- return this.progress[chainName];
- }
- getNextStep(chainName) {
- let currentStep = this.getProgress(chainName);
- let index = this.progressChains[chainName].indexOf(currentStep);
- if (index == this.progressChains[chainName].length - 1) {
- return currentStep;
- }
- let nextStep = this.progressChains[chainName][index + 1];
- return nextStep;
- }
- isUnlocked(key) {
- return this.unlocks.indexOf(key) != -1;
- }
- advanceProgress(chainName) {
- this.progress[chainName] = this.getNextStep(chainName);
- for (let index in this.progress[chainName].unlocks) {
- this.unlock(this.progress[chainName].unlocks[index]);
- }
- let nextStep = this.progress[chainName];
- return nextStep;
- }
- unlock(key) {
- if (!this.isUnlocked(key)) {
- this.unlocks.push(key);
- }
- }
- }
|