summaryrefslogtreecommitdiff
path: root/resources/js
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-23 00:24:50 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-23 00:24:50 +0200
commit4dd1a344c6474087a3f8782dd54f5c7b4acc67ed (patch)
tree7a0229eb721d81c7579a7f5f721a503136c98095 /resources/js
parentdbcd0118863ff3e7c5bee45041ccdb757eb2f366 (diff)
area connections and town maps
Diffstat (limited to 'resources/js')
-rw-r--r--resources/js/classes/Area.js12
-rw-r--r--resources/js/game.js3
-rw-r--r--resources/js/helpers.js8
-rw-r--r--resources/js/ui.js54
4 files changed, 73 insertions, 4 deletions
diff --git a/resources/js/classes/Area.js b/resources/js/classes/Area.js
index b2af3ea..b0bd710 100644
--- a/resources/js/classes/Area.js
+++ b/resources/js/classes/Area.js
@@ -11,6 +11,10 @@ class Area {
async initialize () {}
+ get name () {
+ return DB.areas[this.slug].name;
+ }
+
get encounters () {
return DB.areas[this.slug].encounters;
}
@@ -27,6 +31,14 @@ class Area {
return DB.areas[this.slug].environment;
}
+ get map () {
+ return DB.areas[this.slug].map;
+ }
+
+ get locations () {
+ return DB.areas[this.slug].locations;
+ }
+
get events () {
return DB.areas[this.slug].events;
}
diff --git a/resources/js/game.js b/resources/js/game.js
index 7b40015..9370382 100644
--- a/resources/js/game.js
+++ b/resources/js/game.js
@@ -111,6 +111,7 @@ const Game = {
} else if (Memory.state.opponent.type === 'trainer') {
if (Memory.state.opponent.activeMonster === Memory.state.opponent.monsters[Memory.state.opponent.monsters.length - 1]) {
Memory.state.currentArea.trainerProgress++;
+ Memory.state.currentArea.monsterProgress = 0;
if (Memory.state.currentArea.encounters.length > 0) {
await Game.encounterWildMonster();
} else {
@@ -708,6 +709,8 @@ const Game = {
if (Game.isTown(Memory.state.currentArea)) {
UI.elements.sceneBattle.classList.add('hidden');
UI.elements.sceneTown.classList.remove('hidden');
+
+ UI.drawTown();
} else {
UI.elements.sceneTown.classList.add('hidden');
UI.elements.sceneBattle.classList.remove('hidden');
diff --git a/resources/js/helpers.js b/resources/js/helpers.js
index 2395878..e9cb37d 100644
--- a/resources/js/helpers.js
+++ b/resources/js/helpers.js
@@ -4,7 +4,13 @@
* @returns {(string|MonsterSlug|TechniqueSlug)}
*/
function slugToName (slug) {
- return slug.split('_').map((item) => item.charAt(0).toUpperCase() + item.slice(1)).join(' ');
+ const ucfirst = (str) => {
+ return str.charAt(0).toUpperCase() + str.slice(1);
+ };
+
+ return slug
+ .split('_').map((item) => ucfirst(item)).join(' ')
+ .split('-').map((item) => ucfirst(item)).join(' ');
}
/**
diff --git a/resources/js/ui.js b/resources/js/ui.js
index a40550b..3940574 100644
--- a/resources/js/ui.js
+++ b/resources/js/ui.js
@@ -22,6 +22,9 @@ const Template = {
movesetList: document.querySelector('#tpl___moveset__list'),
movesetItem: document.querySelector('#tpl___moveset__item'),
+ areaSelection: document.querySelector('#tpl___area-selection'),
+ areaSelectionItem: document.querySelector('#tpl___area-selection__item'),
+
inventory: document.querySelector('#tpl___inventory'),
inventoryItem: document.querySelector('#tpl___inventory__item'),
@@ -628,6 +631,49 @@ const UI = {
},
+ /* Town */
+
+ async drawTown () {
+ const currentArea = Memory.state.currentArea;
+
+ UI.elements.sceneTown.innerHTML = Memory.state.currentArea.map;
+
+ for (const locationId of Object.keys(currentArea.locations)) {
+ const location = currentArea.locations[locationId];
+
+ UI.elements.sceneTown.querySelector(`[data-location="${locationId}"]`).addEventListener('click', () => {
+ if (location.type === 'healingCenter') {
+ UI.openHealingCenter(location);
+ }
+
+ else if (location.type === 'shop') {
+ UI.openShop(location);
+ }
+ });
+ }
+ },
+
+ openHealingCenter (healingCenter) {},
+
+ async openShop (shop) {
+ const popup = UI.createPopup();
+ const template = document.createElement('div');
+
+ for (const itemData of shop.items) {
+ const item = await fetchItem(itemData.item_name);
+ const itemNode = document.createElement('div');
+
+ itemNode.innerHTML = `<img src="/modules/tuxemon/mods/tuxemon/${item.sprite}" />`;
+ itemNode.innerHTML += `${item.name}`;
+ itemNode.innerHTML += `${itemData.price} ${DB.currencies.map[Memory.state.Settings.currency].symbol}`;
+
+ template.appendChild(itemNode);
+ }
+
+ popup.querySelector('.popup').appendChild(template);
+ UI.drawPopup(popup);
+ },
+
/* Menu */
@@ -688,6 +734,7 @@ const UI = {
`${Memory.state.money.toFixed(DB.currencies.map[Memory.state.Settings.currency].decimals)}` +
' ' +
`${DB.currencies.map[Memory.state.Settings.currency].symbol}`;
+ UI.elements.status.querySelector('[data-template-slot="area"]').textContent = currentArea.name;
UI.elements.status.querySelector('[data-template-slot="monsterProgress"]').textContent = `${currentArea.monsterProgress} / ${currentArea.requiredEncounters}`;
UI.elements.status.querySelector('[data-template-slot="trainerProgress"]').textContent = `${currentArea.trainerProgress} / ${currentArea.trainers.length}`;
@@ -705,14 +752,14 @@ const UI = {
openAreaSelection () {
const popup = UI.createPopup();
- const template = document.createElement('div');
+ const template = UI.createTemplate(Template.areaSelection);
const currentArea = Memory.state.currentArea;
for (const connectionSlug in currentArea.connections) {
const connection = currentArea.connections[connectionSlug];
- const connectionNode = document.createElement('div');
+ const connectionNode = UI.createTemplate(Template.areaSelectionItem);
- connectionNode.textContent = slugToName(connectionSlug);
+ connectionNode.querySelector('[data-template-slot="text"]').textContent = connection.name;
let canGo = true;
for (const condition of connection.conditions) {
@@ -1020,6 +1067,7 @@ const UI = {
const exchangedMoney = baseRateMoney * newCurrency.rate;
Memory.state.money = Number(exchangedMoney.toFixed(newCurrency.decimals));
+ UI.drawTown();
UI.drawStatus();
});