Permalink
Browse files

Event tab

Added the event tab basics. (#43)
Also fixed some log loop issues. (#67)
Made events load from metadata.
  • Loading branch information...
Manuel-777 committed Oct 20, 2018
1 parent f3694e6 commit 57a5f3a31a53fd0c1ae732112ab2e092bd7d0f3c
Showing with 332 additions and 97 deletions.
  1. +32 −4 main.js
  2. +20 −51 shared/util.js
  3. +53 −20 window_background/background.js
  4. +26 −1 window_main/index.css
  5. +4 −3 window_main/index.html
  6. +197 −18 window_main/renderer.js
36 main.js
@@ -28,10 +28,30 @@ var updateProgress = 0;
var updateSpeed = 0;
const ipc = electron.ipcMain;
var mainLoaded = false;
var backLoaded = false;
app.on('ready', () => {
mainWindow = createMainWindow();
overlay = createOverlay();
background = createBackgroundWindow();
mainWindow.webContents.once('dom-ready', () => {
mainLoaded = true;
if (backLoaded == true) {
showWindow();
background.webContents.send("set_renderer_state", 1);
}
});
background.webContents.once('dom-ready', () => {
backLoaded = true;
if (mainLoaded == true) {
showWindow();
background.webContents.send("set_renderer_state", 1);
}
});
autoUpdater.checkForUpdatesAndNotify();
ipc.on('ipc_switch', function (event, method, arg) {
@@ -72,10 +92,6 @@ app.on('ready', () => {
mainWindow.webContents.send("set_remember", arg);
break;
case 'remember':
background.webContents.send("remember", arg);
break;
case 'offline':
mainWindow.webContents.send("offline", arg);
break;
@@ -84,6 +100,10 @@ app.on('ready', () => {
mainWindow.webContents.send("set_status", arg);
break;
case 'set_events':
mainWindow.webContents.send("set_events", arg);
break;
case 'set_db':
mainWindow.webContents.send("set_db", arg);
overlay.webContents.send("set_db", arg);
@@ -162,6 +182,10 @@ app.on('ready', () => {
break;
// to background
case 'remember':
background.webContents.send("remember", arg);
break;
case 'request_draft_link':
background.webContents.send("request_draft_link", arg);
break;
@@ -174,6 +198,10 @@ app.on('ready', () => {
background.webContents.send("request_explore", arg);
break;
case 'request_events':
background.webContents.send("request_events", arg);
break;
case 'renderer_get_economy':
background.webContents.send("set_economy", 1);
break;
@@ -217,57 +217,25 @@ function addCardSeparator(i, element) {
//
function getReadableEvent(arg) {
switch (arg) {
case "CompCons_M_":
return "Competitive Constructed M19"; break;
case "Constructed_BestOf":
return "Constructed Best of 3"; break;
case "Brewers_M_":
return "Brewers Delight"; break;
case "Pauper_":
return "Pauper"; break;
case "TwiceTheLife_":
return "Twice the Life"; break;
case "QuickDraftExploration_M_":
return "Quick Draft Exploration M19"; break;
case "Momir_":
return "Momir Mardness"; break;
case "Sealed_GRN_":
return "Guilds of Ravnica Sealed"; break;
case "CompDraft_DOM_":
return "Competitive Draft DOM"; break;
case "CompDraft_M_":
return "Competitive Draft M19"; break;
case "CompDraft_GRN_":
return "Competitive Draft GRN"; break;
case "QuickDraft_RIX_":
return "Quick Draft RIX"; break;
case "QuickDraft_AKH_":
return "Quick Draft AKH"; break;
case "QuickDraft_DOM_":
return "Quick Draft DOM"; break;
case "QuickDraft_M_":
return "Quick Draft M19"; break;
case "QuickDraft_GRN_":
return "Quick Draft GRN"; break;
case "QuickExploration_":
return "Quick Exploration"; break;
case "Quick_Singleton_":
return "Quick Singleton"; break;
case "Welcome_Weekend_Singleton":
return "Welcome Weekend Singleton"; break;
case "CompCons_Metagame_Challenge_":
return "Metagame Challenge"; break;
case "Quick_constructed_april_":
return "Quick Constructed"; break;
default:
return arg; break;
if (eventsList[arg] != undefined) {
return eventsList[arg];
}
return arg;
}
//
function getEventId(arg) {
var ret = arg;
Object.keys(eventsList).forEach(function (key) {
console.log(arg, key, eventsList[key]);
if (eventsList[key] == arg) {
console.log("match!");
ret = key;
}
});
return ret;
}
//
@@ -397,7 +365,8 @@ function compare_draft_cards(a, b) {
//
var setsList = null;
var setsList = {};
var eventsList = {};
//
function get_set_scryfall(set) {
@@ -64,7 +64,7 @@ const serverAddress = 'mtgatool.com';
const debugLog = false;
const debugNet = false;
const debugLogSpeed = 0.1;
var debugLogSpeed = 0.1;
var timeStart = 0;
var timeEnd = 0;
const fs = require("fs");
@@ -117,6 +117,7 @@ var gameObjs = {};
var hoverCard = undefined;
var history = {};
var drafts = {};
var events = {};
var topDecks = {};
//var coursesToSubmit = {};
var decks = [];
@@ -160,19 +161,15 @@ ipc.on('remember', function (event, arg) {
//
ipc.on('set_renderer_state', function (event, arg) {
ipc_send("ipc_log", "Renderer state: "+arg);
renderer_state = arg;
var settings = store.get("settings");
updateSettings(settings, true);
if (rstore.get("token") !== "" && rstore.get("email") !== "") {
rememberMe = true;
ipc_send("set_remember", rstore.get("email"));
}
if (debugLog) {
ipc_send("show_background", 1);
finishLoading();
}
}
});
//
@@ -229,6 +226,11 @@ ipc.on('update_install', function (event, settings) {
}
});
//
ipc.on('request_events', function (event, arg) {
ipc_send("set_events", JSON.stringify(events));
});
//
ipc.on('request_history', function (event, state) {
requestHistorySend(state);
@@ -305,6 +307,7 @@ ipc.on('set_economy', function (event, arg) {
ipc_send("set_economy", economy);
});
ipc.on('request_explore', function (event, arg) {
if (playerUsername == '') {
ipc_send("offline", 1);
@@ -382,7 +385,21 @@ function loadPlayerConfig(playerId) {
history[id] = item;
history[id].type = "draft";
}
}
}
}
events.courses = store.get('courses_index');
for (let i=0; i<events.courses.length; i++) {
ipc_send("popup", {"text": "Reading events: "+i+" / "+events.courses.length, "time": 0});
var id = events.courses[i];
if (id != null) {
var item = entireConfig[id];
if (item != undefined) {
events[id] = item;
events[id].type = "Event";
}
}
}
deck_changes_index = entireConfig["deck_changes_index"];
@@ -491,7 +508,7 @@ console.log(logUri);
var file;
var logLoopTimer = null;
var logLoopMode = 0;
resetLogLoop(500);
resetLogLoop(100);
//
function resetLogLoop(time) {
@@ -520,7 +537,7 @@ function logLoop() {
//
function readLog() {
//console.log("readLog()");
//ipc_send("ipc_log", "readLog("+logLoopMode+")");
//ipc_send("ipc_log", "readLog logloopmode: "+logLoopMode+", renderer state:"+renderer_state+", logSize: "+logSize+", prevLogSize: "+prevLogSize);
if (!firstPass) {
ipc_send("log_read", 1);
}
@@ -532,7 +549,11 @@ function readLog() {
var logSize = stats.size;
var logDiff = logSize - prevLogSize;
if (logSize > prevLogSize+1) {
if (logSize == undefined) {
fs.close(file);
resetLogLoop(500);
}
else if (logSize > prevLogSize+1) {
if (logLoopMode == 0) {
fs.read(file, new Buffer(logDiff), 0, logDiff, prevLogSize, processLogUser);
}
@@ -541,8 +562,6 @@ function readLog() {
}
}
else {
//console.log("fs.close(file) readLog")
//ipc_send("ipc_log", "fs.close(file) readLog");
fs.close(file);
resetLogLoop(500);
}
@@ -791,8 +810,8 @@ function processLogData(data) {
if (json.CourseDeck != null) {
json.CourseDeck.colors = get_deck_colors(json.CourseDeck);
console.log(json.CourseDeck, json.CourseDeck.colors)
saveCourse(json);
httpSubmitCourse(json._id, json);
saveCourse(json);
}
}
return;
@@ -1071,8 +1090,9 @@ function processLogData(data) {
strCheck = '<== Event.Draft(';
json = checkJsonWithStart(data, strCheck, '', ')');
if (json != false) {
console.log("Draft start")
console.log("Draft start");
draftId = json.Id;
//debugLogSpeed = 200;
return;
}
@@ -1090,7 +1110,8 @@ function processLogData(data) {
}
}
}
if (json.packNumber == 0 && json.pickNumber <= 1) {
console.log("Draft:", json);
if (json.packNumber == 0 && json.pickNumber <= 0) {
httpGetPicks(draftSet);
setDraftCards(json);
createDraft();
@@ -1724,6 +1745,14 @@ function saveCourse(json) {
if (!courses_index.includes(json.id)) {
courses_index.push(json.id);
}
else {
json.date = store.get(json.id).date;
}
// add locally
if (!events.courses.includes(json.id)) {
events.courses.push(json.id);
}
store.set('courses_index', courses_index);
store.set(json.id, json);
@@ -1850,7 +1879,7 @@ function httpBasic() {
async.forEachOfSeries(httpAsyncNew, function (value, index, callback) {
var _headers = value;
if (store.get("settings").send_data == false && _headers.method != 'delete_data' && _headers.method != 'get_database' && _headers.method != 'get_status' && debugLog == false) {
if (store.get("settings").send_data == false && _headers.method != 'get_picks' && _headers.method != 'delete_data' && _headers.method != 'get_database' && _headers.method != 'get_status' && debugLog == false) {
callback({message: "Settings dont allow sending data! > "+_headers.method});
removeFromHttp(_headers.reqId);
}
@@ -1890,7 +1919,7 @@ function httpBasic() {
res.on('end', function () {
if (debugNet) {
ipc_send("ipc_log", "RECV << "+index+", "+_headers.method+", "+_headers.reqId+", "+_headers.token);
ipc_send("ipc_log", "RECV << "+index+", "+_headers.method+", "+results);
ipc_send("ipc_log", "RECV << "+index+", "+_headers.method+", "+results.slice(0, 100));
console.log("RECV << "+index, _headers.method, results);
}
try {
@@ -1928,13 +1957,17 @@ function httpBasic() {
}
if (_headers.method == 'get_database') {
cardsDb.set(parsedResult);
resetLogLoop(1);
//resetLogLoop(100);
delete parsedResult.ok;
setsList = parsedResult.sets;
eventsList = parsedResult.events;
ipc_send("set_db", parsedResult);
}
}
else if (parsedResult.ok == false) {
else if (parsedResult.ok == false && parsedResult.error != undefined) {
if (_headers.method == 'share_draft') {
ipc_send("popup", {"text": parsedResult.error, "time": 3000});
}
// errors here
}
if (_headers.method == 'auth') {
Oops, something went wrong.

0 comments on commit 57a5f3a

Please sign in to comment.