Skip to content

Commit c37f3d1

Browse files
committed
fix jp race mechanic selections
1 parent 2f1fb59 commit c37f3d1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/module/api/characterImporter.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const _jsonToActorData = async (json) => {
110110
inteligencia: json.inteligencia,
111111
sabedoria: json.sabedoria,
112112
carisma: json.carisma,
113-
jp_race_bonus: json.race_jp,
113+
jp_race_bonus: _extractJpRaceBonus(json),
114114
current_xp: json.experience_points,
115115
economy: {
116116
cp: json.money_cp,
@@ -203,6 +203,26 @@ const _getItemsFromUUIDs = async (uuids) => {
203203
return items;
204204
};
205205

206+
/**
207+
* Extracts the JP race bonus from the new race_mechanic_selections structure.
208+
* @param {Object} json - Character JSON from Old Dragon Online
209+
* @returns {string} The selection_key value ('jpd', 'jpc', 'jps') or empty string
210+
*/
211+
const _extractJpRaceBonus = (json) => {
212+
// Return empty string if array doesn't exist or is empty
213+
if (!json.race_mechanic_selections || json.race_mechanic_selections.length === 0) {
214+
return '';
215+
}
216+
217+
// Find the first selection with a JP-related selection_key
218+
// Only jpd, jpc, and jps are valid for race JP bonuses
219+
const jpSelection = json.race_mechanic_selections.find((selection) =>
220+
['jpd', 'jpc', 'jps'].includes(selection.selection_key),
221+
);
222+
223+
return jpSelection ? jpSelection.selection_key : '';
224+
};
225+
206226
const _convertCost = (costInPC) => {
207227
if (costInPC >= 100) {
208228
return `${Math.floor(costInPC / 100)} PO`;
@@ -303,7 +323,7 @@ export const updateActor = async (actor) => {
303323
'system.inteligencia': json.inteligencia,
304324
'system.sabedoria': json.sabedoria,
305325
'system.carisma': json.carisma,
306-
'system.jp_race_bonus': json.race_jp,
326+
'system.jp_race_bonus': _extractJpRaceBonus(json),
307327
'system.current_xp': json.experience_points,
308328
'system.economy.cp': json.money_cp,
309329
'system.economy.sp': json.money_sp,

0 commit comments

Comments
 (0)