diff --git a/package-lock.json b/package-lock.json index a52eaf6..cac3bda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@sveltejs/adapter-auto": "^2.0.0", "@sveltejs/kit": "^1.20.5", "@types/node": "^18.15.11", + "@types/wicg-file-system-access": "^2020.9.6", "fast-xml-parser": "^4.2.0", "idb": "^7.1.1", "svelte": "^4.0.0", @@ -633,6 +634,12 @@ "integrity": "sha512-SnHmG9wN1UVmagJOnyo/qkk0Z7gejYxOYYmaAwr5u2yFYfsupN3sg10kyzN8Hep/2zbHxCnsumxOoRIRMBwKCg==", "dev": true }, + "node_modules/@types/wicg-file-system-access": { + "version": "2020.9.6", + "resolved": "https://registry.npmjs.org/@types/wicg-file-system-access/-/wicg-file-system-access-2020.9.6.tgz", + "integrity": "sha512-6hogE75Hl2Ov/jgp8ZhDaGmIF/q3J07GtXf8nCJCwKTHq7971po5+DId7grft09zG7plBwpF6ZU0yx9Du4/e1A==", + "dev": true + }, "node_modules/acorn": { "version": "8.9.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", diff --git a/package.json b/package.json index cde5988..f9fda76 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@sveltejs/adapter-auto": "^2.0.0", "@sveltejs/kit": "^1.20.5", "@types/node": "^18.15.11", + "@types/wicg-file-system-access": "^2020.9.6", "fast-xml-parser": "^4.2.0", "idb": "^7.1.1", "svelte": "^4.0.0", @@ -24,4 +25,4 @@ "vite": "^4.2.0" }, "type": "module" -} \ No newline at end of file +} diff --git a/src/lib/SaveFile.ts b/src/lib/SaveFile.ts index 6dd61cd..f391c25 100644 --- a/src/lib/SaveFile.ts +++ b/src/lib/SaveFile.ts @@ -57,4 +57,52 @@ class CharacterSelector { } } -export const Character = new CharacterSelector(SaveGame); \ No newline at end of file +export const Character = new CharacterSelector(SaveGame); + +export const Download = async (save: SaveFile, filename: string) => { + if (!save || !filename) { + console.error('Save or filename is undefined'); + return; + } + + const res = await fetch('/api/toXML', { + method: 'POST', + body: JSON.stringify(save), + headers: { + 'Content-Type': 'application/json', + }, + }); + + if (!res.ok) { + console.error(res); + return; + } + + const blob = await res.blob(); + + // If supported, use file picker + if ('showSaveFilePicker' in window) { + const handle = await window.showSaveFilePicker({ + types: [ + { + description: 'Stardew Valley Save File', + accept: { 'text/text': [] }, + }, + ], + suggestedName: filename, + }); + const writable = await handle.createWritable(); + await writable.write(blob); + await writable.close(); + return; + } + + // Otherwise just download the file to downloads + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = filename; + a.click(); + URL.revokeObjectURL(url); + a.remove(); +}; \ No newline at end of file diff --git a/src/routes/(edit)/+layout.svelte b/src/routes/(edit)/+layout.svelte index f388f1b..ac13b09 100644 --- a/src/routes/(edit)/+layout.svelte +++ b/src/routes/(edit)/+layout.svelte @@ -1,7 +1,7 @@ diff --git a/src/routes/(edit)/appearance/+page.svelte b/src/routes/(edit)/appearance/+page.svelte index e6cf11d..15fa67c 100644 --- a/src/routes/(edit)/appearance/+page.svelte +++ b/src/routes/(edit)/appearance/+page.svelte @@ -1,11 +1,14 @@ @@ -27,7 +32,7 @@
-
+
+
+ +
+
+ +
+
+ +
{/if} @@ -81,6 +133,7 @@ .wrapper { display: grid; grid-template-columns: 1fr 3fr; + gap: 16px; } .editor1 { @@ -116,18 +169,17 @@ text-align: center; } - .gender { + .selector { display: flex; - gap: 8px; + flex-direction: row; justify-content: center; - width: 100%; } - .gender input { + .selector input { appearance: none; } - .gender label { + .selector label { border-radius: 4px; display: flex; justify-content: center; @@ -136,17 +188,19 @@ padding-bottom: 0.1em; font-size: 1.5em; cursor: pointer; + /* Beef up the text shadow a little bit, some emojis might blend into the bg too much */ + text-shadow: -0.05em 0.05em 0.1em rgba(0, 0, 0, 0.6); } - .gender label:has(input:checked) { + .selector label:has(input:checked) { border: solid 3px #d93703; } - .gender label:has(input:not(:checked)) { + .selector label:has(input:not(:checked)) { border: solid 3px #00000000; } - .gender label input { + .selector label input { position: absolute; } diff --git a/src/routes/(edit)/character/+page.svelte b/src/routes/(edit)/character/+page.svelte index a1f53ea..3e102e8 100644 --- a/src/routes/(edit)/character/+page.svelte +++ b/src/routes/(edit)/character/+page.svelte @@ -97,10 +97,6 @@ Golden Walnuts -

Wallet

@@ -151,9 +147,9 @@ align-items: center; } - .stats > label:last-child { + /* .stats > label:last-child { grid-column: 1 / -1; - } + } */ input[type='number'] { width: 4em; diff --git a/src/routes/(edit)/inventory/+page.svelte b/src/routes/(edit)/inventory/+page.svelte index ee0ee12..8b33145 100644 --- a/src/routes/(edit)/inventory/+page.svelte +++ b/src/routes/(edit)/inventory/+page.svelte @@ -121,6 +121,24 @@ break; } + const newItem: Item = { + name: newItemName, + stack: 1, + parentSheetIndex: 'parentSheetIndex' in newItemData ? newItemData.parentSheetIndex : 0, + category: category, + hasBeenInInventory: true, + hasBeenPickedUpByFarmer: true, + DisplayName: newItemData.name, + SpecialVariable: 0, // TODO ? + indexInColorSheet: 0, // TODO + isLostItem: false, + specialItem: false, + tileLocation: { X: 0, Y: 0 }, + boundingBox: { X: 0, Y: 0, Width: 64, Height: 64, Location: { X: 0, Y: 0 } }, + canBeSetDown: true, + canBeGrabbed: true, + }; + let type: string | undefined; switch (newItemData._type) { case 'ObjectInformation': @@ -159,24 +177,8 @@ break; } - const newItem: Item = { - name: newItemName, - stack: 1, - parentSheetIndex: 'parentSheetIndex' in newItemData ? newItemData.parentSheetIndex : 0, - category: category, - hasBeenInInventory: true, - hasBeenPickedUpByFarmer: true, - DisplayName: newItemData.name, - SpecialVariable: 0, // TODO ? - indexInColorSheet: 0, // TODO - isLostItem: false, - specialItem: false, - tileLocation: { X: 0, Y: 0 }, - canBeSetDown: true, - canBeGrabbed: true, - }; - if (type) { + // This is required for the game to recognize the item as the correct type, but isn't part of the XML structureS // @ts-expect-error newItem['@_xsi:type'] = type; }