1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/**
* @typedef {Object} DB_Evolution
* @property {string} path
* @property {string} monster_slug
* @property {string} at_level
* @property {string} item
*/
//
const DB = {
/**
* @type {string[]}
*/
allMonsters: [],
/**
* @typedef {Object.<string, string[]>} DB_Animation
*
* @type {DB_Animation}
*/
allAnimations: {},
/**
* @type {string[]}
*/
allItems: [],
/**
* @typedef {Object} DB_Monster
*
* @type {Object.<MonsterSlug, DB_Monster>}
*/
monsters: {},
/**
* @typedef {Object} DB_Shape
*
* @type {Object.<string, DB_Shape>}
*/
shapes: {},
/**
* @typedef {Object} DB_Element
*
* @type {Object.<ElementType, DB_Element>}
*/
elements: {},
/**
* @typedef {Object} DB_Technique
*
* @type {Object.<TechniqueSlug, DB_Technique>}
*/
techniques: {},
/**
* @typedef {Object} DB_StatusEffect
*
* @type {Object.<string, DB_StatusEffect>}
*/
statusEffects: {},
/**
* @typedef {Object} DB_Item
*
* @type {Object.<string, DB_Item>}
*/
items: {},
areas: {},
translations: {},
currencies : {},
};
async function initializeDB () {
DB.allMonsters = await fetch('/db/_generated/all-monsters.json').then((response) => response.json());
DB.allAnimations = await fetch('/db/_generated/animations.json').then((response) => response.json());
DB.allItems = await fetch('/db/_generated/all-items.json').then((response) => response.json());
DB.shapes = await fetch('/modules/tuxemon/mods/tuxemon/db/shape/shapes.json').then((response) => response.json());
for (const element of Object.keys(ElementType)) {
DB.elements[element] = await fetch(`/modules/tuxemon/mods/tuxemon/db/element/${element}.json`).then((response) => response.json());
}
await fetchTranslation(Memory.state.Settings.language);
applyTranslation();
DB.currencies = await fetch('/db/_generated/currencies.json').then((response) => response.json());
}
/**
* @param {MonsterSlug} slug
*
* @returns {Promise<Monster>}
*/
async function fetchMonster (slug) {
if (! DB.monsters[slug]) {
DB.monsters[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/monster/${slug}.json`).then((response) => response.json());
}
const monster = new Monster(slug);
await monster.initialize();
return monster;
}
/**
* @param {TechniqueSlug} slug
*
* @returns {Promise<Technique>}
*/
async function fetchTechnique (slug) {
if (! DB.techniques[slug]) {
DB.techniques[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/technique/${slug}.json`).then((response) => response.json());
}
return new Technique(slug);
}
/**
* @param {string} slug
*
* @returns {Promise<StatusEffect>}
*/
async function fetchStatusEffect (slug) {
if (! DB.statusEffects[slug]) {
DB.statusEffects[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/technique/status_${slug}.json`).then((response) => response.json());
}
return new StatusEffect(slug);
}
/**
* @param {string} slug
*
* @returns {Promise<Item>}
*/
async function fetchItem (slug) {
if (! DB.items[slug]) {
DB.items[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/item/${slug}.json`).then((response) => response.json());
}
return new Item(slug);
}
/**
* @param {string} locale
*
* @returns {Promise<Object>}
*/
async function fetchTranslation (locale) {
if (! DB.translations[locale]) {
DB.translations[locale] = await fetch(`/db/_generated/i18n/${locale}.json`).then((response) => response.json());
}
return DB.translations[locale];
}
/**
* @param {string} slug
*
* @returns {Promise<Area>}
*/
async function fetchArea (slug) {
if (Memory.state.areaProgress[slug]) {
return Memory.state.areaProgress[slug];
}
if (! DB.areas[slug]) {
DB.areas[slug] = await fetch(`/db/_generated/areas/${slug}.json`).then((response) => response.json());
}
const area = new Area(slug);
return area;
}
|