Add local build saving/loading

This commit is contained in:
dr-carlos 2021-09-12 15:48:20 +09:30 committed by hppeng-wynn
parent 348db18c02
commit 890b5252f0
2 changed files with 59 additions and 0 deletions

View file

@ -885,6 +885,37 @@ function shareBuild() {
} }
} }
function saveBuild() {
if (player_build) {
let savedBuilds = window.localStorage.getItem("builds") === null ? {} : JSON.parse(window.localStorage.getItem("builds"));
let saveName = document.getElementById("build-name").value;
if ((!Object.keys(savedBuilds).includes(saveName) || document.getElementById("saved-error").textContent !== "") && location.hash !== "") {
savedBuilds[saveName] = location.hash.replace("#", "");
window.localStorage.setItem("builds", JSON.stringify(savedBuilds));
document.getElementById("saved-error").textContent = "";
document.getElementById("saved-build").textContent = "Build saved";
} else {
if (location.hash === "")
document.getElementById("saved-error").textContent = "Empty build";
else
document.getElementById("saved-error").textContent = "Exists. Overwrite?";
}
}
}
function loadBuild() {
let savedBuilds = window.localStorage.getItem("builds") === null ? {} : JSON.parse(window.localStorage.getItem("builds"));
let saveName = document.getElementById("build-name").value;
document.getElementById("loaded-error").textContent = "";
if (Object.keys(savedBuilds).includes(saveName)) {
decodeBuild(savedBuilds[saveName])
document.getElementById("loaded-build").textContent = "Build loaded";
} else
document.getElementById("loaded-error").textContent = "Build doesn't exist";
}
function resetFields(){ function resetFields(){
for (let i in powderInputs) { for (let i in powderInputs) {
setValue(powderInputs[i], ""); setValue(powderInputs[i], "");

View file

@ -47,6 +47,9 @@
<th class="center smalltitle"> <th class="center smalltitle">
<label>Accessories</label> <label>Accessories</label>
</th> </th>
<th class="center smalltitle">
<label>Build</label>
</th>
</tr> </tr>
<tr> <tr>
<td class="left"> <td class="left">
@ -154,6 +157,31 @@
<p class="error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p> <p class="error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p>
</td> </td>
</tr> </tr>
<tr>
<td class="left">
<label for="build-name">Build Name:</label><br>
<input id="build-name" name="build-name"/>
<!-- Dummy <p> tag for horizontal alignment -->
<p style="top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; white-space: nowrap; word-break:break-word;"></p>
</td>
<td class="left">
<br/>
<button style="font-size: 100%" class="button" id="save-button" onclick="saveBuild()">
Save Build
</button>
<p id="saved-build" style="color: green; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; white-space: nowrap; word-break:break-word;"></p>
<p id="saved-error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p>
</td>
<td class="left">
<br/>
<button style="font-size: 100%" class="button" id="load-button" onclick="loadBuild()">
Load Build
</button>
<p id="loaded-build" style="color: green; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; white-space: nowrap; word-break:break-word;"></p>
<p id="loaded-error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p>
</td>
</tr>
</table> </table>
</div> </div>
<div class="center" style="grid-column:1/span 3;grid-row:2"> <div class="center" style="grid-column:1/span 3;grid-row:2">