mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-04 17:07:22 +00:00
Use localStorage for saves
This commit is contained in:
parent
881043f4cb
commit
76ffe39348
3 changed files with 23 additions and 7 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
|
@ -5681,6 +5681,11 @@
|
||||||
"yallist": "^4.0.0"
|
"yallist": "^4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"lz-string": {
|
||||||
|
"version": "1.4.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
|
||||||
|
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY="
|
||||||
|
},
|
||||||
"magic-string": {
|
"magic-string": {
|
||||||
"version": "0.22.5",
|
"version": "0.22.5",
|
||||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz",
|
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz",
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cheap-glkote": "^0.2.4",
|
"cheap-glkote": "^0.2.4",
|
||||||
"emglken": "^0.3.3",
|
"emglken": "^0.3.3",
|
||||||
|
"lz-string": "^1.4.4",
|
||||||
"preact": "^10.5.12",
|
"preact": "^10.5.12",
|
||||||
"wouter-preact": "^2.7.3"
|
"wouter-preact": "^2.7.3"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
import { useState, useEffect } from 'preact/hooks'
|
import { useState, useEffect } from 'preact/hooks'
|
||||||
|
import {
|
||||||
|
compressToUTF16 as encode,
|
||||||
|
decompressFromUTF16 as decode
|
||||||
|
} from 'lz-string'
|
||||||
|
|
||||||
import CheapGlkOte from 'cheap-glkote'
|
import CheapGlkOte from 'cheap-glkote'
|
||||||
|
|
||||||
|
|
@ -48,12 +52,17 @@ const Handlers = ({
|
||||||
},
|
},
|
||||||
onFileRead: ({ filename }) => {
|
onFileRead: ({ filename }) => {
|
||||||
if (filename === 'save') return null
|
if (filename === 'save') return null
|
||||||
const token = prompt('Enter your SAVE_TOKEN here')
|
|
||||||
return token
|
const lsName = prompt('Enter RecordID:')
|
||||||
|
|
||||||
|
const record = localStorage.getItem(`save-${lsName}`)
|
||||||
|
return decode(record)
|
||||||
},
|
},
|
||||||
onFileWrite: ({ filename }, content) => {
|
onFileWrite: ({ filename }, content) => {
|
||||||
const token = content
|
const lsName = prompt('Choose RecordID:')
|
||||||
prompt('Copy your SAVE_TOKEN', token)
|
const record = encode(content)
|
||||||
|
|
||||||
|
localStorage.setItem(`save-${lsName}`, record)
|
||||||
},
|
},
|
||||||
/* */
|
/* */
|
||||||
onExit: _ => setInputType(null)
|
onExit: _ => setInputType(null)
|
||||||
|
|
@ -94,15 +103,16 @@ export default function ({ vmParts: { file, engine } }) {
|
||||||
|
|
||||||
return status.stage !== 'ready'
|
return status.stage !== 'ready'
|
||||||
? (<div>{status.details}</div>)
|
? (<div>{status.details}</div>)
|
||||||
: (<section>
|
: (
|
||||||
|
<section>
|
||||||
<TextBuffer {...{
|
<TextBuffer {...{
|
||||||
inbox,
|
inbox,
|
||||||
currentWindow
|
currentWindow
|
||||||
}}/>
|
}} />
|
||||||
<InputBox {...{
|
<InputBox {...{
|
||||||
currentWindow,
|
currentWindow,
|
||||||
inputType,
|
inputType,
|
||||||
sendMessage
|
sendMessage
|
||||||
}}/>
|
}} />
|
||||||
</section>)
|
</section>)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue