-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
feat: corruption loadout import/export #114
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,10 +201,15 @@ export const corruptionLoadoutTableCreate = () => { | |
} | ||
if (i === 0) { | ||
let cell = row.insertCell(); | ||
//empty | ||
let btn = document.createElement("button"); | ||
btn.className = "corrSave" | ||
btn.textContent = "Import" | ||
btn.onclick = () => corruptionLoadoutImportPrompt(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addEventListener |
||
cell.appendChild(btn); | ||
cell.title = "Import a loadout configuration string to be used on your next ascension" | ||
|
||
cell = row.insertCell(); | ||
let btn = document.createElement("button"); | ||
btn = document.createElement("button"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename |
||
btn.className = "corrLoad" | ||
btn.textContent = "Zero" | ||
btn.onclick = () => corruptionLoadoutSaveLoad(false, i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please addEventListener here too |
||
|
@@ -253,6 +258,27 @@ const corruptionLoadoutSaveLoad = (save = true, loadout = 1) => { | |
} | ||
} | ||
|
||
const corruptionLoadoutImportPrompt = async () => { | ||
const importPrompt = await Prompt( | ||
[ | ||
'Please enter comma-separated corruption values. Current loadout:', | ||
player.prototypeCorruptions.join(','), | ||
].join('\n') | ||
Comment on lines
+263
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just concat the strings |
||
); | ||
|
||
if (!importPrompt) { | ||
return Alert('Okay, maybe next time.'); | ||
} | ||
const importLoadout = importPrompt.split(',').map(Number); | ||
if (importLoadout.length !== 13) { | ||
return Alert('Invalid format! Corruption loadouts should be 13 comma-separated numbers.'); | ||
} | ||
|
||
player.prototypeCorruptions = importLoadout; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if one of these is NaN, negative, infinite, etc? |
||
corruptionLoadoutTableUpdate(); | ||
corruptionStatsUpdate(); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove semicolon |
||
|
||
async function corruptionLoadoutGetNewName(loadout = 0) { | ||
const maxChars = 9 | ||
// eslint-disable-next-line | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,27 @@ export const btoa = (s: string) => { | |
return null; | ||
} | ||
} | ||
|
||
export const copyToClipboard = async (text: string) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. : Promise |
||
if ('clipboard' in navigator) { | ||
await navigator.clipboard.writeText(text) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return void navigator.clipboard... |
||
.catch(e => console.error(e)); | ||
|
||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. axe this return |
||
} | ||
// Old browsers (legacy Edge, Safari 13.0) | ||
const textArea = document.createElement('textarea'); | ||
textArea.value = text; | ||
textArea.setAttribute('style', 'top: 0; left: 0; position: fixed;'); | ||
|
||
document.body.appendChild(textArea); | ||
textArea.focus(); | ||
textArea.select(); | ||
try { | ||
document.execCommand('copy'); | ||
} catch (_) { | ||
console.error("Failed to copy savegame to clipboard."); | ||
} | ||
|
||
document.body.removeChild(textArea); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const