Skip to content

Commit

Permalink
Merge branch 'main' of github.com:arkatsy/moths-cheats
Browse files Browse the repository at this point in the history
  • Loading branch information
arkatsy committed Nov 22, 2024
2 parents ba61897 + b7ee4b1 commit 001d942
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 8 deletions.
87 changes: 84 additions & 3 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export const IPC = {
SET_ESSENCE: "set/essence",
SET_RENOWN: "set/renown",
SET_CALENDAR_TIME: "set/calendar-time",
SET_PRONOUNS: "set/pronouns"
SET_PRONOUNS: "set/pronouns",
SET_HEALTH: "set/health",
SET_STAMINA: "set/stamina",
SET_MANA: "set/mana"
}

export const channels = {
Expand All @@ -30,6 +33,9 @@ export const channels = {
[IPC.SET_ESSENCE]: handleSetEssence,
[IPC.SET_RENOWN]: handleSetRenown,
[IPC.SET_CALENDAR_TIME]: handleSetCalendarTime,
[IPC.SET_HEALTH]: handleSetHealth,
[IPC.SET_STAMINA]: handleSetStamina,
[IPC.SET_MANA]: handleSetMana,
[IPC.SET_PRONOUNS]: handleSetPronouns
}

Expand Down Expand Up @@ -93,7 +99,10 @@ function handleGetSaveData(e, saveId) {
calendarTime: headerData.calendar_time,
year: translateCalendarTime(headerData.calendar_time)[0],
season: translateCalendarTime(headerData.calendar_time)[1],
day: translateCalendarTime(headerData.calendar_time)[2]
day: translateCalendarTime(headerData.calendar_time)[2],
health: headerData.stats.base_health,
stamina: headerData.stats.base_stamina,
mana: headerData.stats.mana_max
}
}

Expand Down Expand Up @@ -142,7 +151,7 @@ function handleSetEssence(e, saveId, essence) {
}

function handleSetRenown(e, saveId, renown) {
console.log(`[handleSetRenown:${saveId}]: Updating essence to ${renown}`)
console.log(`[handleSetRenown:${saveId}]: Updating renown to ${renown}`)

if (!isNumber(renown)) {
console.log(`[handleSetRenown:${saveId}]: Renown is not a number ${renown}, won't update`)
Expand Down Expand Up @@ -195,6 +204,78 @@ function handleSetCalendarTime(e, saveId, calendarTime) {
return true
}

function handleSetHealth(e, saveId, health) {
console.log(`[handleSetHealth:${saveId}]: Updating health to ${health}`)

if (!isNumber(health)) {
console.log(`[handleSetHealth:${saveId}]: Health is not a number ${health}, 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

updateJsonValue(jsonPaths.header, "stats.base_health", health)
updateJsonValue(jsonPaths.header, "stats.health_current", health)
updateJsonValue(jsonPaths.player, "stats.base_health", health)
updateJsonValue(jsonPaths.player, "stats.health_current", health)

return true
}

function handleSetStamina(e, saveId, stamina) {
console.log(`[handleSetStamina:${saveId}]: Updating stamina to ${stamina}`)

if (!isNumber(stamina)) {
console.log(`[handleSetStamina:${saveId}]: Stamina is not a number ${stamina}, 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

updateJsonValue(jsonPaths.header, "stats.base_stamina", stamina)
updateJsonValue(jsonPaths.header, "stats.stamina_current", stamina)
updateJsonValue(jsonPaths.player, "stats.base_stamina", stamina)
updateJsonValue(jsonPaths.player, "stats.stamina_current", stamina)

return true
}

function handleSetMana(e, saveId, mana) {
console.log(`[handleSetMana:${saveId}]: Updating mana to ${mana}`)

if (!isNumber(mana)) {
console.log(`[handleSetMana:${saveId}]: Mana is not a number ${mana}, 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

updateJsonValue(jsonPaths.header, "stats.mana_max", mana)
updateJsonValue(jsonPaths.header, "stats.mana_current", mana)
updateJsonValue(jsonPaths.player, "stats.mana_max", mana)
updateJsonValue(jsonPaths.player, "stats.mana_current", mana)

return true
}

function handleSetPronouns(e, saveId, pronouns) {
console.log(`[handleSetPronouns:${saveId}]: Updating pronouns to ${pronouns}`)

Expand Down
3 changes: 3 additions & 0 deletions src/preload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const api = {
setRenown: async (saveId, renown) => ipcRenderer.invoke(IPC.SET_RENOWN, saveId, renown),
setCalendarTime: async (saveId, calendarTime) =>
ipcRenderer.invoke(IPC.SET_CALENDAR_TIME, saveId, calendarTime),
setHealth: async (saveId, health) => ipcRenderer.invoke(IPC.SET_HEALTH, saveId, health),
setStamina: async (saveId, stamina) => ipcRenderer.invoke(IPC.SET_STAMINA, saveId, stamina),
setMana: async (saveId, mana) => ipcRenderer.invoke(IPC.SET_MANA, saveId, mana),
setPronouns: async (saveId, pronouns) => ipcRenderer.invoke(IPC.SET_PRONOUNS, saveId, pronouns)
}

Expand Down
35 changes: 30 additions & 5 deletions src/renderer/src/components/save-editing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ import {
import tesseraeIcon from "@assets/tessarae.webp"
import essenceIcon from "@assets/essence.png"
import renownIcon from "@assets/renown.png"
import pronounsIcon from "@assets/pronouns.png"
import editIcon from "@assets/edit.png"
import { saves, seasonsList, getCalendarTime, PronounsList, formatPronouns } from "@utils"

const TesseraeIcon = () => <Image src={tesseraeIcon} w="20px" h="20px" />
const EssenceIcon = () => <Image src={essenceIcon} w="20px" h="20px" />
const RenownIcon = () => <Image src={renownIcon} w="20px" h="20px" />
const EditIcon = () => <Image src={editIcon} w="20px" h="20px" />
const PronounsIcon = () => <Image src={pronounsIcon} w="20px" h="20px" />

export default function SaveEditing({ saveId, onBack }) {
const save = saves.find((save) => save.id === saveId)
Expand All @@ -62,6 +60,9 @@ export default function SaveEditing({ saveId, onBack }) {
await window.api.setRenown(saveId, edits.renown)
await window.api.setCalendarTime(saveId, getCalendarTime(edits.year, edits.season, edits.day))
await window.api.setPronouns(saveId, edits.pronouns)
await window.api.setHealth(saveId, edits.health)
await window.api.setStamina(saveId, edits.stamina)
await window.api.setMana(saveId, edits.mana)

const success = await window.api.updateSave(saveId)
setIsApplyingEdits(false)
Expand All @@ -88,8 +89,9 @@ export default function SaveEditing({ saveId, onBack }) {
const setSeason = (newSeason) => setEdits((edits) => ({ ...edits, season: newSeason }))
const setDay = (newDay) => setEdits((edits) => ({ ...edits, day: newDay }))
const setPronouns = (pronouns) => setEdits((edits) => ({ ...edits, pronouns: pronouns }))
// const setCalendarTime = (newCalendarTime) =>
// setEdits((edits) => ({ ...edits, calendarTime: newCalendarTime }))
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 shouldPreventUserInteraction = isLoadingSaveData || isApplyingEdits
const loadingMessage = isLoadingSaveData
Expand Down Expand Up @@ -176,6 +178,30 @@ export default function SaveEditing({ saveId, onBack }) {
collection={pronouns}
/>
</GridItem>
<GridItem>
<NumberInput
value={edits.health}
onValueChange={setHealth}
label="Health"
step={10}
/>
</GridItem>
<GridItem>
<NumberInput
value={edits.stamina}
onValueChange={setStamina}
label="Stamina"
step={10}
/>
</GridItem>
<GridItem>
<NumberInput
value={edits.mana}
onValueChange={setMana}
label="Mana"
step={4}
/>
</GridItem>
</Grid>
</Stack>
{/* ===== Calendar ===== */}
Expand Down Expand Up @@ -240,7 +266,6 @@ function SelectInput({ collection, textLabel, currentValue, onValueChange }) {
<SelectRoot
collection={collection}
size="md"
positioning={{ placement: "bottom", flip: false }}
onValueChange={(e) => onValueChange(e.value[0])}
>
<SelectLabel>{textLabel}</SelectLabel>
Expand Down

0 comments on commit 001d942

Please sign in to comment.