Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Birthday edit #69

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
40 changes: 37 additions & 3 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) {
Expand Down Expand Up @@ -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]
}
}

Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion src/preload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 19 additions & 0 deletions src/renderer/src/components/save-editing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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 <Text>Error updating save</Text>
Expand Down Expand Up @@ -155,6 +158,22 @@ export default function SaveEditing() {
icon={<FarmIcon />}
/>
</GridItem>
<GridItem>
<SelectInput
colorPalette="teal"
currentValue={seasonsList[edits.birthdaySeason]}
onValueChange={setBirthdaySeason}
textLabel="Birthday"
collection={seasons}
/>
<SelectInput
colorPalette="teal"
currentValue={edits.birthdayDay}
onValueChange={setBirthdayDay}
// textLabel="Day"
collection={days}
/>
</GridItem>
</Grid>
</Stack>
{/* ===== Stats ===== */}
Expand Down
28 changes: 14 additions & 14 deletions src/renderer/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -127,25 +127,25 @@ 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
}

/**
* @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<string>} forecast Array of all weathers for the entire current season by day
* @returns The current day's forecast
*/
export function getWeather(time, forecast) {
Expand All @@ -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<string>} 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
Expand Down