diff --git a/package.json b/package.json index fead248..79ac1a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hacks-of-mistria", - "version": "0.5.0", + "version": "0.5.1", "description": "A tool to edit your save files in Fields of Mistria", "main": "./out/main/index.js", "author": "arkatsy, dwlim12", diff --git a/src/main/ipc.js b/src/main/ipc.js index 9d27bd2..5175363 100644 --- a/src/main/ipc.js +++ b/src/main/ipc.js @@ -32,7 +32,8 @@ export const IPC = { SET_CALENDAR_TIME: "set/calendar-time", SET_HEALTH: "set/health", SET_STAMINA: "set/stamina", - SET_MANA: "set/mana" + SET_MANA: "set/mana", + SET_BIRTHDAY: "set/birthday" } export const channels = { @@ -50,7 +51,8 @@ export const channels = { [IPC.SET_CALENDAR_TIME]: handleSetCalendarTime, [IPC.SET_HEALTH]: handleSetHealth, [IPC.SET_STAMINA]: handleSetStamina, - [IPC.SET_MANA]: handleSetMana + [IPC.SET_MANA]: handleSetMana, + [IPC.SET_BIRTHDAY]: handleSetBirthday } async function handleMeasureUnpacking(e, amount) { @@ -164,7 +166,9 @@ async function handleGetSaveData(e, saveId) { day: translateCalendarTime(headerData.calendar_time)[2], health: headerData.stats.base_health, stamina: headerData.stats.base_stamina, - mana: headerData.stats.mana_max + mana: headerData.stats.mana_max, + birthdaySeason: translateCalendarTime(playerData.birthday)[1], + birthdayDay: translateCalendarTime(playerData.birthday)[2] } } @@ -403,3 +407,33 @@ async function handleSetMana(e, saveId, mana) { return true } + +async function handleSetBirthday(e, saveId, birthday) { + console.log(`[handleSetBirthday:${saveId}]: Updating birthday to ${birthday}`) + + if (!isNumber(birthday)) { + console.log( + `[handleSetBirthday:${saveId}]: birthday is not a number ${birthday}, won't update` + ) + return false + } + + if (birthday % 86400 != 0) { + console.log( + `[handleSetBirthday:${saveId}]: Birthday ${birthday} is not a multiple of 86400, won't update` + ) + return false + } + + const saveInfo = unpackedSavesPathsCache.get(saveId) + if (!saveInfo) { + console.log(`couldn't find save with id ${saveId} in cache`) + return false + } + + const { jsonPaths } = saveInfo + + await updateJsonValue(jsonPaths.player, "birthday", birthday) + + return true +} \ No newline at end of file diff --git a/src/preload/index.js b/src/preload/index.js index 75a7a57..bfcbdca 100644 --- a/src/preload/index.js +++ b/src/preload/index.js @@ -17,7 +17,8 @@ const api = { ipcRenderer.invoke(IPC.SET_CALENDAR_TIME, saveId, calendarTime), setHealth: (saveId, health) => ipcRenderer.invoke(IPC.SET_HEALTH, saveId, health), setStamina: (saveId, stamina) => ipcRenderer.invoke(IPC.SET_STAMINA, saveId, stamina), - setMana: (saveId, mana) => ipcRenderer.invoke(IPC.SET_MANA, saveId, mana) + setMana: (saveId, mana) => ipcRenderer.invoke(IPC.SET_MANA, saveId, mana), + setBirthday: (saveId, birthday) => ipcRenderer.invoke(IPC.SET_BIRTHDAY, saveId, birthday) } contextBridge.exposeInMainWorld("api", api) diff --git a/src/renderer/src/components/save-editing.jsx b/src/renderer/src/components/save-editing.jsx index c8f189f..9f62469 100644 --- a/src/renderer/src/components/save-editing.jsx +++ b/src/renderer/src/components/save-editing.jsx @@ -68,6 +68,7 @@ export default function SaveEditing() { await window.api.setHealth(saveId, edits.health) await window.api.setStamina(saveId, edits.stamina) await window.api.setMana(saveId, edits.mana) + await window.api.setBirthday(saveId, getCalendarTime(0, edits.birthdaySeason, edits.birthdayDay)) updateSave() } @@ -84,6 +85,8 @@ export default function SaveEditing() { const setHealth = (newHealth) => setEdits((edits) => ({ ...edits, health: newHealth })) const setStamina = (newStamina) => setEdits((edits) => ({ ...edits, stamina: newStamina })) const setMana = (newMana) => setEdits((edits) => ({ ...edits, mana: newMana })) + const setBirthdaySeason = (newSeason) => setEdits((edits) => ({ ...edits, birthdaySeason: newSeason })) + const setBirthdayDay = (newDay) => setEdits((edits) => ({ ...edits, birthdayDay: newDay })) if (isUpdateError) { return Error updating save @@ -155,6 +158,22 @@ export default function SaveEditing() { icon={} /> + + + + {/* ===== Stats ===== */} diff --git a/src/renderer/src/utils.js b/src/renderer/src/utils.js index 1243cd6..7bd3111 100644 --- a/src/renderer/src/utils.js +++ b/src/renderer/src/utils.js @@ -39,7 +39,7 @@ export function formatPronouns(pronouns, inverse = false) { /** * @desc Translates the playtime variable in header.json into a more accessible format - * @param time The playtime variable from header.json in seconds + * @param {number} time The playtime variable from header.json in seconds * @returns A tuple containing the playtime where * - playtime[0] = hours * - playtime[1] = minutes @@ -57,7 +57,7 @@ export function translatePlaytime(time) { /** * @desc Displays the playtime in a readable format - * @param time The playtime variable from header.json in seconds + * @param {number} time The playtime variable from header.json in seconds * @returns A string containing the playtime in hh:mm:ss format */ export function displayPlaytime(time) { @@ -68,7 +68,7 @@ export function displayPlaytime(time) { /** * @desc Translates the clock_time variable in header.json into a more accessible format - * @param time The clock_time variable from header.json in seconds + * @param {number} time The clock_time variable from header.json in seconds * @returns A tuple containing the clock time where * - clockTime[0] = hours * - clockTime[1] = minutes @@ -88,7 +88,7 @@ export function translateClockTime(time) { /** * @desc Displays the clock time in a readable format - * @param time The clock_time variable from header.json in seconds + * @param {number} time The clock_time variable from header.json in seconds * @returns A string containing the clock time in hh:mm XM format */ export function displayClockTime(time) { @@ -99,7 +99,7 @@ export function displayClockTime(time) { /** * @desc Translates the calendar_time variable in header.json into a more accessible format - * @param time The calendar_time variable from header.json in seconds + * @param {number} time The calendar_time variable from header.json in seconds * @returns A tuple containing the clock time where * - calendarTime[0] = year * - calendarTime[1] = season @@ -117,7 +117,7 @@ export function translateCalendarTime(time) { /** * @desc Displays the calendar time in a readable format - * @param time The calendar_time variable from header.json in seconds + * @param {number} time The calendar_time variable from header.json in seconds * @returns A string containing the calendar time in Year # Season # Day # format */ export function displayCalendarTime(time) { @@ -127,16 +127,16 @@ export function displayCalendarTime(time) { /** * @desc Translates the year, season, and day variables back into a calendar_time variable - * @param year The year # that we are wanting to translate - * @param season The season # that we are wanting to translate (0-3) - * @param day The day # that we are wanting to translate + * @param {integer} year The year # that we are wanting to translate + * @param {integer} season The season # that we are wanting to translate (0-3) + * @param {integer} day The day # that we are wanting to translate * @returns A calendar_time value that is the sum of all the inputs translated to seconds */ export function getCalendarTime(year, season, day) { // Spring = 0, Summer = 1, Fall = 2, Winter = 3 // 86400 * 28 = 2419200 seconds = 1 month because 28 days per month // 2419200 * 4 = 9676800 seconds = 1 year - year = (year - 1) * 9676800 + if (year > 0) { year = (year - 1) * 9676800 } season = season * 2419200 day = (day - 1) * 86400 return year + season + day @@ -144,8 +144,8 @@ export function getCalendarTime(year, season, day) { /** * @desc Gets the current day's forecast using the current calendar time - * @param time The calendar_time variable from header.json in seconds - * @param forecast Array of all weathers for the entire current season by day + * @param {number} time The calendar_time variable from header.json in seconds + * @param {Array} forecast Array of all weathers for the entire current season by day * @returns The current day's forecast */ export function getWeather(time, forecast) { @@ -156,8 +156,8 @@ export function getWeather(time, forecast) { /** * @desc Gets the properties set up for the app to display the current forecast's icon - * @param time The calendar_time variable from header.json in seconds - * @param forecast Array of all weathers for the entire current season by day + * @param {number} time The calendar_time variable from header.json in seconds + * @param {Array} forecast Array of all weathers for the entire current season by day * @returns A tuple containing weather information where * - weather[0] = the current season * - weather[1] = the forecast for the current day