Skip to content

Commit

Permalink
Modified data saving
Browse files Browse the repository at this point in the history
  • Loading branch information
ManoSegransan committed Jul 11, 2018
1 parent 9a993bb commit d24874e
Show file tree
Hide file tree
Showing 7 changed files with 481 additions and 340 deletions.
Binary file added .DS_Store
Binary file not shown.
20 changes: 16 additions & 4 deletions app/index.html
Expand Up @@ -55,7 +55,11 @@
<div class="indicator" id="rightIndicator"></div>
</div>

<p id="scramble" onclick="scramble.openScramble()" title="Current scramble, click to select scrambler"></p>
<div id="scrambleContainer">
<button id="scramblePrevious" onclick="scramble.previousScramble()" title="Go back to previous scramble"></button>
<p id="scramble" onclick="scramble.openScramble()" title="Current scramble, click to select scrambler or use custom scrambles"></p>
<button id="scrambleNext" onclick="scramble.nextScramble()" title="Go to next scramble"></button>
</div>

<div id="stats">
<select title="Event select" id="eventSelect" onchange="events.setEvent()"></select>
Expand Down Expand Up @@ -192,7 +196,7 @@

<div id="dialogScramble">
<p>Scrambler: <select id="scramblerSelect"></select></p>
<p>Custom scramble<br><textarea rows="3" id="customScramble"></textarea></p>
<p>Custom scrambles (newline separated)<br><textarea rows="3" id="customScramble"></textarea></p>
<p><button onclick="scramble.closeScramble()">Done</button></p>
</div>

Expand Down Expand Up @@ -246,6 +250,7 @@
<p title="Automatically save recorded video to folder">Video auto-save location: <input name="autosaveLocation" type="text" style="width:150px"/> <button onclick="prefs.selectLocation(); return false;">Select</button></p>
<p title="Show scrambles next to times in exported sessions and average details"><input type="checkbox" name="scramblesInList" class="checkbox">Display scrambles in lists</p>
<p title="Only show list of times with no other information"><input type="checkbox" name="onlyList" class="checkbox">Remove all formatting in lists</p>
<p title="#">Data auto-save location: <input name="dataPath" type="text" style="width:150px"/> <button onclick="prefs.setDataPath(); return false;">Select</button></p>
</form>
</div>
<div id="tabs-2">
Expand Down Expand Up @@ -332,8 +337,7 @@
</form>
</div>
<div id="tabs-4">
<p title="Manage Block Keeper sessions">Block Keeper: <button onclick="prefs.importBK()">Import</button> <button onclick="prefs.exportBK()">Export</button></p>
<p title="Manage Block Keeper sessions"><button onclick="prefs.setStorageLocation()">Change saving location</button></p>
<p title="Import and export Block Keeper sessions">Block Keeper: <button onclick="prefs.importBK()">Import</button> <button onclick="prefs.exportBK()">Export</button></p>
<p title="Import csTimer Sessions">csTimer: <button onclick="prefs.importCS()">Import</button></p>
<p title="Export all times as flat CSV file">CSV: <button onclick="prefs.exportCSV()">Export</button></p>
</div>
Expand All @@ -343,6 +347,14 @@
<button title="Save preferences and close" id="savePreferences" onclick="prefs.savePreferences()">Save</button>
</div>

<div id="dialogUpdate">
<button class="cross" id="closeUpdate"onclick="update.closeUpdate()"></button>
<h2 id="updateHeading"></h2>
<p id="updateInfo"></p>
<pre id="updateNotes"></pre>
</div>

<script src="scripts/update.js"></script>
<script src="scripts/scrambles.js"></script>
<script src="scripts/style.js"></script>
<script src="scripts/preferences.js"></script>
Expand Down
Binary file added app/scripts/.DS_Store
Binary file not shown.
16 changes: 10 additions & 6 deletions app/scripts/events.js
Expand Up @@ -71,11 +71,12 @@ var events = function() {
// Save events to a file
// Note: Events are stored as puzzles as to not interfere with pre-existing records which were saved before the name was changed
function saveSessions() {
storage.set("puzzles", {puzzles:internalEvents, puzzle:currentEvent, session:currentSession, tools:tools.toolTypes(),currentScrambler:scramble.getCurrentScrambler()}, function(error) {
storage.setDataPath(preferences.dataPath);
storage.set("puzzles", {puzzles:internalEvents, puzzle:currentEvent, session:currentSession, tools:tools.toolTypes(),currentScrambler:scramble.getCurrentScrambler()}, preferences.dataPath.dataPath, function(error) {
if (error) {
throw error;
}
})
});
}

// Merges current events with other events
Expand All @@ -100,6 +101,7 @@ var events = function() {
var letClose = false;
var reloading = false;
function closeApp() {
storage.setDataPath(preferences.dataPath);
storage.set("puzzlesBackup", {puzzles:events, puzzle:currentEvent, session:currentSession, tools:tools.toolTypes()}, function(error) {
if (error) {
throw error;
Expand Down Expand Up @@ -214,6 +216,7 @@ var events = function() {

// Load events
var load = function() {
storage.setDataPath(preferences.dataPath);
storage.get("puzzles", function(error, object) {
if (error) {
storage.get("puzzlesBackup", function(error, object) {
Expand All @@ -236,6 +239,7 @@ var events = function() {

// Load backup events
var loadBackup = function() {
storage.setDataPath(preferences.dataPath);
storage.get("puzzlesBackup", function(error, object) {
if (error) {
if (confirm("Sessions couldn't be loaded. They may be damaged. Please contact dallas@dallasmcneil.com for help. You will need to quit Block Keeper to preserve the damaged session data, or you could erase it and continue using Block Keeper. Would you like to quit?")) {
Expand Down Expand Up @@ -349,7 +353,7 @@ var events = function() {

// Create record from the add time menu
function addRecord() {
var t = parseFloat(parseFloat(document.getElementById("addTimeInput").value.split(':').reduce((acc,time) => (60 * acc) + +time)).toFixed(3));
var t = parseFloat(parseFloat(document.getElementById("addTimeInput").value.split(':').reduce((acc,time) => (60 * acc) + +time)).toFixed(3));
if (isNaN(t) || t === undefined || t <= 0) {
$("#addTimeMessage")[0].innerHTML = "Invalid time";
return;
Expand All @@ -364,7 +368,7 @@ var events = function() {
getLastRecord().scramble = scramble.currentScramble();
}
$("#timer")[0].innerHTML = formatTime(t);
scramble.scramble();
scramble.nextScramble();
closeTimeDialog();
}

Expand All @@ -388,7 +392,7 @@ var events = function() {
currentSession = getCurrentEvent().sessions.length - 1;
sessionSelect.value = currentSession;
updateRecords(true);
scramble.scramble();
scramble.resetList();
}

// Set the session based on the dropdown
Expand Down Expand Up @@ -834,9 +838,9 @@ var events = function() {
var sess = getCurrentEvent().sessions.splice(currentSession, 1);
currentEvent = $("#eventSelectTransfer")[0].value;
getCurrentEvent().sessions.push(sess[0]);
enableAllElements();
eventSelect.value = currentEvent;
setEvent();
enableAllElements();
}

// Hide the session stats
Expand Down
44 changes: 25 additions & 19 deletions app/scripts/preferences.js
Expand Up @@ -2,6 +2,7 @@
// Manages preferences and preferences menu including functionality
// Block Keeper
// Created by Dallas McNeil

const storage = require('electron-json-storage');
var remote = require('electron').remote;
const {remote:{dialog}} = require('electron');
Expand Down Expand Up @@ -47,19 +48,21 @@ var preferences = {
videoResolution:720,
timeSplits:false,
timerSize:25,
timerSecondSize:15
timerSecondSize:15,
dataPath:storage.getDefaultDataPath()
}

// Preference management functions
var prefs = function() {
storage.setDataPath(data);

// Preference forms
var preferencesInterface = document.forms[2];
var preferencesTimer = document.forms[1];
var preferencesGeneral = document.forms[0];

// Saves preferences to file
function savePreferences() {
storage.setDataPath(storage.getDefaultDataPath());
storage.set("preferences", preferences, function(error) {
if (error) {
throw error;
Expand All @@ -68,8 +71,8 @@ var prefs = function() {
setStylesheet();
$("#centreBackground").css("background-image", 'url("' + preferences.backgroundImage + '")');
$("#scramble").css("text-align", preferences.scrambleAlign);
$("#scramble").css("font-size", preferences.scrambleSize + "vh");
$("#scramble").css("line-height", preferences.scrambleSize + "vh");
$("#scramble").css("font-size", (preferences.scrambleSize * 10) + "px");
$("#scramble").css("line-height", (preferences.scrambleSize * 10) + "px");

if (preferences.voice != "none") {
timer.s7voice(new Audio("sounds/" + preferences.voice + "8s.mp3"));
Expand Down Expand Up @@ -109,6 +112,7 @@ var prefs = function() {
preferencesTimer.timeSplits.checked = preferences.timeSplits;
preferencesInterface.timerSecondSize.value = preferences.timerSecondSize;
preferencesInterface.timerSize.value = preferences.timerSize;
preferencesGeneral.dataPath.value = preferences.dataPath;
}

// Loads preferences from file and fills in preferences forms
Expand All @@ -133,7 +137,7 @@ var prefs = function() {
record.setupRecorder();
}
}

storage.setDataPath(storage.getDefaultDataPath());
storage.get("preferences", function(error, object) {
if (error) {
savePreferences();
Expand Down Expand Up @@ -228,6 +232,7 @@ var prefs = function() {
preferences.timeSplits = preferencesTimer.timeSplits.checked;
preferences.timerSecondSize = preferencesInterface.timerSecondSize.value;
preferences.timerSize = preferencesInterface.timerSize.value;
preferences.dataPath = preferencesGeneral.dataPath.value;

if (preferencesTimer.leftKey.value != "") {
preferences.leftKey = preferencesTimer.leftKey.value;
Expand Down Expand Up @@ -284,18 +289,6 @@ var prefs = function() {
}

$("#tabs").tabs();
//Change storage location
function setStorageLocation(data) {
closePreferences();
dialog.showOpenDialog({
properties: ["openDirectory"],
}, function(filesPaths) {
var data = ''+filesPaths+''.substr(1).slice(0, -1);
storage.setDataPath(data);
})
}

var data;

// Import Block Keeper session data from a file
function importBK() {
Expand Down Expand Up @@ -520,6 +513,19 @@ var data;
})
}

function setDataPath() {
dialog.showOpenDialog({
filters:[],
properties: ['openDirectory']
}, function(fileNames) {
if (fileNames === undefined) {
return;
} else
preferencesGeneral.dataPath.value = fileNames[0].replace(new RegExp("\\\\", "g"), "/");
})
}


loadPreferences();

return {
Expand All @@ -535,8 +541,8 @@ var data;
importCSTime:importCSTime,
cancelCSTime:cancelCSTime,
importBK:importBK,
setStorageLocation:setStorageLocation,
exportBK:exportBK,
exportCSV:exportCSV
exportCSV:exportCSV,
setDataPath:setDataPath
}
}()

0 comments on commit d24874e

Please sign in to comment.