Made one of the Extra's Features work.

Added the color system. It updates without hitting a button. I'm certain
there's a better way to go about doing it.

I'd like to implement it to where you can click on the colors in the
dweller's menu, and it converts from hexadecimal internally, similar in
system to how lunchboxes are handled.
This commit is contained in:
TheCreatorJames
2016-07-22 16:09:56 -05:00
parent c73f024f7e
commit 2d71e132bf
2 changed files with 65 additions and 51 deletions
+16 -4
View File
@@ -143,12 +143,24 @@
<form>
<div class="form-group row">
<div class="col-sm-6">
<div class="col-sm-12">
<label>Hex Color</label><br />
<input name="color1" class="jscolor" value="0000FF">
<!---Copy this to the Dweller color:-->
<!---<span class='value1' ng-bind="colortofos()"></span>-->
<input name="color1" class="jscolor" value="0000FF"> : <span class='value1' ng-bind="colortofos()"></span>
<!---Copy this to the Dweller color:--><br />
<!--<input type="submit" value="Update Color">-->
<script>
{
function jscolorFunction()
{
colortofos();
setTimeout(jscolorFunction, 250);
}
setTimeout(jscolorFunction, 1000);
}
</script>
</div>
+49 -47
View File
@@ -3,22 +3,30 @@ var iv = sjcl.codec.hex.toBits("7475383967656A693334307438397532");
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
var isLoaded=false;
var colortofos = function () {
var colorhex = document.getElementsByClassName("jscolor")[0].value;
var colorfos;
var x = colorhex.substring(0, 0) + "FF" + colorhex.substring(0);
colorfos = parseInt(x, 16);
$(".value1").html(colorfos);
};
$(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();
@@ -54,11 +62,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);
@@ -68,11 +76,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);
@@ -85,17 +93,17 @@ function encrypt(fileName, save) {
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) {
@@ -113,7 +121,7 @@ $('body .container .box')
$('.instructions').show();
})
.on('drop', function (e) {
$('.box').removeClass('hover').addClass('ready');
$('.instructions').hide();
@@ -134,14 +142,14 @@ $('body .container .box')
e.preventDefault();
return false;
});
// Modifications
function edit(fileName, save) {
isLoaded=true;
var scope = angular.element($('body').get(0)).scope();
@@ -150,7 +158,7 @@ function edit(fileName, save) {
scope.fileName = fileName;
});
}
var app = angular.module('shelter', []);
@@ -166,7 +174,7 @@ app.controller('dwellerController', function ($scope) {
var _save = {},
_lunchboxCount = 0,
_handyCount = 0;
_petCarrierCount = 0;
_petCarrierCount = 0;
_starterPackCount = 0;
Object.defineProperty($scope, 'save', {
get: function () {
@@ -200,7 +208,7 @@ app.controller('dwellerController', function ($scope) {
updateCount();
}
});
Object.defineProperty($scope, 'petCarrierCount', {
get: function () {
return _petCarrierCount
@@ -211,7 +219,7 @@ app.controller('dwellerController', function ($scope) {
updateCount();
}
});
Object.defineProperty($scope, 'starterPackCount', {
get: function () {
return _starterPackCount
@@ -222,19 +230,19 @@ app.controller('dwellerController', function ($scope) {
updateCount();
}
});
$scope.editDweller = function (dweller) {
$scope.dweller = dweller;
};
$scope.maxhappinessAll = function () {
var sum2 = Object.keys($scope.save.dwellers.dwellers).length;
for(i=0; i<sum2; i++)
$scope.save.dwellers.dwellers[i].happiness.happinessValue = 100;
};
$scope.maxSpecialAll = function () {
var sum2 = Object.keys($scope.save.dwellers.dwellers).length;
for(i=0; i<sum2; i++)
@@ -251,7 +259,7 @@ app.controller('dwellerController', function ($scope) {
$scope.dweller.stats.stats[6].value = 10;
$scope.dweller.stats.stats[7].value = 10;
};
$scope.removeRocks = function () {
$scope.save.vault.rocks = [];
};
@@ -263,15 +271,9 @@ app.controller('dwellerController', function ($scope) {
$scope.download = function () {
encrypt($scope.fileName, $scope.save);
};
$scope.colortofos = function () {
var colorhex = document.getElementsByClassName("jscolor")[0].value;
var colorfos;
var x = colorhex.substring(0, 0) + "FF" + colorhex.substring(0);
colorfos = parseInt(x, 16);
$(".value1").html(colorfos);
};
$scope.colortofos = colortofos;
$scope.unlockrooms = function () {
$scope.save.unlockableMgr.objectivesInProgress = [];
$scope.save.unlockableMgr.completed = [];
@@ -295,7 +297,7 @@ app.controller('dwellerController', function ($scope) {
"HydroponicUnlock",
"NukacolaUnlock"];
};
$scope.unlockrecipes = function () {
$scope.save.survivalW.recipes =[
"Shotgun_Rusty",
@@ -603,7 +605,7 @@ app.controller('dwellerController', function ($scope) {
function extractCount() {
if ($scope.save.vault.LunchBoxesByType.toString().indexOf("0") > -1){
_lunchboxCount = $scope.save.vault.LunchBoxesByType.toString().match(/0/g).length;
} else {
@@ -621,7 +623,7 @@ app.controller('dwellerController', function ($scope) {
} else {
_petCarrierCount = 0;
}
if ($scope.save.vault.LunchBoxesByType.toString().indexOf("3") > -1){
_starterPackCount = $scope.save.vault.LunchBoxesByType.toString().match(/3/g).length;
} else {
@@ -634,11 +636,11 @@ app.controller('dwellerController', function ($scope) {
$scope.petCarrierCount = _petCarrierCount;
$scope.starterPackCount = _starterPackCount;
}
function updateCount() {
var types = $scope.save.vault.LunchBoxesByType = [],
count = $scope.save.vault.LunchBoxesCount = _lunchboxCount + _handyCount + _petCarrierCount + _starterPackCount;
@@ -653,7 +655,7 @@ app.controller('dwellerController', function ($scope) {
for (var i = 0; i < _petCarrierCount; i++){
types.push(2);
}
for (var i = 0; i < _starterPackCount; i++){
types.push(3);
}
@@ -665,7 +667,7 @@ app.controller('dwellerController', function ($scope) {
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;
@@ -680,23 +682,23 @@ function preset(preset, saveFileName){
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);
}
};
}