mirror of
https://github.com/rakion99/shelter-editor.git
synced 2026-07-27 19:56:25 +00:00
Presets
This commit is contained in:
+19
-3
@@ -7,6 +7,7 @@ body {
|
||||
background-image: url(../background.jpg);
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
background-attachment: fixed;
|
||||
}
|
||||
|
||||
body > .container {
|
||||
@@ -14,7 +15,7 @@ body > .container {
|
||||
width: 800px;
|
||||
margin: -225px 0 0 -400px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
top: 240px;
|
||||
left: 50%;
|
||||
padding: 0;
|
||||
}
|
||||
@@ -211,7 +212,7 @@ a.tab:focus {
|
||||
text-align: center;
|
||||
position: absolute;
|
||||
line-height: 25px;
|
||||
top: 50%;
|
||||
top: 40%;
|
||||
left: 50%;
|
||||
margin-top: -50px;
|
||||
margin-left: -175px;
|
||||
@@ -219,7 +220,7 @@ a.tab:focus {
|
||||
|
||||
.instructions input {
|
||||
display: inline-block;
|
||||
max-width: 80px;
|
||||
|
||||
}
|
||||
|
||||
.boy {
|
||||
@@ -324,3 +325,18 @@ a.list-group-item, a.list-group-item, button.list-group-item, button.list-group-
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.presets {
|
||||
margin-top: 30px;
|
||||
margin-bottom: 10px;
|
||||
height: 370px;
|
||||
width: 100%;
|
||||
border: 4px solid #467bb7;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,24 @@
|
||||
var key = [2815074099, 1725469378, 4039046167, 874293617, 3063605751, 3133984764, 4097598161, 3620741625];
|
||||
var iv = sjcl.codec.hex.toBits("7475383967656A693334307438397532");
|
||||
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
|
||||
var isLoaded=false;
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
|
||||
if(window.location.href.indexOf("?preset=") > -1 && window.location.href.indexOf("?savename=") > -1){
|
||||
|
||||
urlPreset = window.location.href.substring(window.location.href.indexOf("?preset=")+8, window.location.href.indexOf("?savename="));
|
||||
urlSaveName = window.location.href.substring(window.location.href.indexOf("?savename=")+10);
|
||||
|
||||
preset(urlPreset,urlSaveName);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function handleFileSelect(evt) {
|
||||
|
||||
try {
|
||||
evt.stopPropagation();
|
||||
evt.preventDefault();
|
||||
@@ -38,9 +54,11 @@ function handleFileSelect(evt) {
|
||||
} finally {
|
||||
evt.target.value = null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function decrypt(evt, fileName, base64Str) {
|
||||
|
||||
var cipherBits = sjcl.codec.base64.toBits(base64Str);
|
||||
var prp = new sjcl.cipher.aes(key);
|
||||
var plainBits = sjcl.mode.cbc.decrypt(prp, cipherBits, iv);
|
||||
@@ -50,9 +68,11 @@ function decrypt(evt, fileName, base64Str) {
|
||||
} catch (e) {
|
||||
throw "Decrypted file does not contain valid JSON: " + e
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function encrypt(fileName, save) {
|
||||
|
||||
var compactJsonStr = JSON.stringify(save);
|
||||
var plainBits = sjcl.codec.utf8String.toBits(compactJsonStr);
|
||||
var prp = new sjcl.cipher.aes(key);
|
||||
@@ -62,14 +82,20 @@ function encrypt(fileName, save) {
|
||||
type: "text/plain"
|
||||
});
|
||||
|
||||
|
||||
saveAs(blob, fileName.replace(".txt", ".sav").replace(".json", ".sav"))
|
||||
|
||||
|
||||
}
|
||||
|
||||
document.getElementById("sav_file").addEventListener("change", function (e) {
|
||||
|
||||
$('.box').removeClass('hover').addClass('ready');
|
||||
$('.instructions').hide();
|
||||
|
||||
|
||||
handleFileSelect(e);
|
||||
|
||||
}, false);
|
||||
|
||||
document.ondragover = document.ondrop = function (e) {
|
||||
@@ -80,11 +106,14 @@ document.ondragover = document.ondrop = function (e) {
|
||||
$('body .container .box')
|
||||
.on('dragover', function (e) {
|
||||
$('.box').addClass('hover');
|
||||
$('.instructions').hide();
|
||||
})
|
||||
.on('dragleave', function (e) {
|
||||
$('.box').removeClass('hover');
|
||||
$('.instructions').show();
|
||||
})
|
||||
.on('drop', function (e) {
|
||||
|
||||
$('.box').removeClass('hover').addClass('ready');
|
||||
$('.instructions').hide();
|
||||
|
||||
@@ -104,22 +133,30 @@ $('body .container .box')
|
||||
|
||||
e.preventDefault();
|
||||
return false;
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Modifications
|
||||
function edit(fileName, save) {
|
||||
|
||||
|
||||
isLoaded=true;
|
||||
var scope = angular.element($('body').get(0)).scope();
|
||||
|
||||
scope.$apply(function () {
|
||||
scope.save = save;
|
||||
scope.fileName = fileName;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
var app = angular.module('shelter', []);
|
||||
|
||||
app.controller('dwellerController', function ($scope) {
|
||||
|
||||
$scope.section = 'vault';
|
||||
|
||||
$scope.fileName = '';
|
||||
@@ -186,6 +223,7 @@ app.controller('dwellerController', function ($scope) {
|
||||
};
|
||||
|
||||
function extractCount() {
|
||||
|
||||
$scope.save.vault.LunchBoxesByType.forEach(function (type) {
|
||||
if (type == 0) {
|
||||
_lunchboxCount++;
|
||||
@@ -196,9 +234,11 @@ app.controller('dwellerController', function ($scope) {
|
||||
$scope.lunchboxCount = _lunchboxCount;
|
||||
$scope.handyCount = _handyCount;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function updateCount() {
|
||||
|
||||
var types = $scope.save.vault.LunchBoxesByType = [],
|
||||
count = $scope.save.vault.LunchBoxesCount = _lunchboxCount + _handyCount;
|
||||
|
||||
@@ -209,5 +249,46 @@ app.controller('dwellerController', function ($scope) {
|
||||
types.push(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
function preset(preset, saveFileName){
|
||||
|
||||
if(isLoaded==true){
|
||||
if(window.location.href.indexOf("?") > -1){
|
||||
window.location.href = window.location.href.substring(0,window.location.href.indexOf("?")) + "?preset=" + preset + "?savename=" + saveFileName;
|
||||
}else{
|
||||
window.location.href = window.location.href + "?preset=" + preset + "?savename=" + saveFileName;
|
||||
|
||||
}
|
||||
throw new Error("There already is a savefile loaded.")
|
||||
|
||||
}
|
||||
file = "presets/" + preset + ".json";
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = readPreset;
|
||||
|
||||
xhr.open("GET", file, true);
|
||||
xhr.send();
|
||||
|
||||
|
||||
function readPreset()
|
||||
{
|
||||
|
||||
if (xhr.readyState == 4) {
|
||||
var resp = JSON.parse(xhr.responseText);
|
||||
$('.instructions').hide();
|
||||
edit(saveFileName, resp);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+22848
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+22920
File diff suppressed because it is too large
Load Diff
+14
-2
@@ -144,11 +144,23 @@
|
||||
<div class="row save">
|
||||
<button class="btn btn-primary pull-right" ng-click="download()" ng-show="fileName">Save</button>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<div class="instructions">
|
||||
Drag a save file here (e.g. Vault1.sav) <br />
|
||||
or select one here <input type="file" id="sav_file" name="sav_file" />
|
||||
or select one here<br><input type="file" id="sav_file" name="sav_file" /><br><br>
|
||||
<small>Loading saves with high Lunch Boxes or high Mr. Handy boxes might take a while</small>
|
||||
</div>
|
||||
|
||||
<div class="presets">
|
||||
<br><label title="Savefile names can only be 'Vault1.sav', 'Vault2.sav' or 'Vault3.sav'">Savefile Name: </label> <input type="text" name="presetSaveName" id="presetSaveName" placeholder="Vault1.sav" value="Vault1.sav" ><hr>
|
||||
<button class="btn" onclick="preset('NewSave', document.getElementById('presetSaveName').value)">New Save</button>
|
||||
<button class="btn" onclick="preset('Stats9999', document.getElementById('presetSaveName').value)">All 9999</button>
|
||||
<button class="btn" onclick="preset('SuperDwellers', document.getElementById('presetSaveName').value)">Super Dwellers</button>
|
||||
<button class="btn" onclick="preset('SuperHack', document.getElementById('presetSaveName').value)">Super Hack</button>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<script src="js/jquery-2.1.4.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user