Skip to content

Commit

Permalink
Return calculations & hunting sets (#6)
Browse files Browse the repository at this point in the history
* feat: first version of return calculations and hunting sets

* fix: issues

* fix: minor issues  and some styles

* fix: show correct result

* fix: disable set tracking in current session if removing all sets

* chore: update cli

* feat: count mindforce evades and real player misses

* fix: name tab Returns
  • Loading branch information
slazor authored Dec 24, 2021
1 parent f9bdd80 commit 50a7340
Show file tree
Hide file tree
Showing 17 changed files with 574 additions and 34 deletions.
Binary file modified bin/cli.exe
Binary file not shown.
Binary file modified bin/cli.unix
Binary file not shown.
26 changes: 26 additions & 0 deletions public/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ span.sum {
margin-bottom: -0.75rem;
}

.flex {
display: flex;
align-items: center;
}
.flex-1 {
flex: 1;
}
.inline-label {
margin: 0 1rem 0 0 !important;
}


/* Tables */
.fullwidth {
Expand All @@ -273,9 +284,24 @@ span.sum {
.small-locked-size {
width: 175px;
}
.vert-align-middle {
vertical-align: middle !important;
}
.vert-align-icon {
vertical-align: bottom !important;
}
.calc-col-width {
width: 300px;
}

/* Graphs */
.recharts-cartesian-axis-tick-value,
.x-axis-ticks {
font-size: 0.75rem;
}


/* Settings */
.column-250 {
max-width: 250px;
}
12 changes: 12 additions & 0 deletions src/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ const configStorage = new Store({
sidebarStyle: {
type: 'string',
},
huntingSets: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'string', format: 'uuid' },
default: { type: 'boolean' },
name: { type: 'string' },
decay: { type: 'number' },
},
},
},
});

module.exports = configStorage;
6 changes: 5 additions & 1 deletion src/main/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const { is } = require('electron-util');
const sqlite3 = require('sqlite3');

const dbVersion = 1;
const dbVersion = 2;
const storagePath = is.development ? app.getAppPath() : app.getPath('userData');

const SQL_CREATE_SESSIONS = `
Expand All @@ -23,6 +23,7 @@ const SQL_CREATE_SESSION_INSTANCES = `
created_at VARCHAR NOT NULL DEFAULT CURRENT_TIMESTAMP,
events TEXT NOT NULL,
aggregated TEXT NOT NULL,
config TEXT NOT NULL DEFAULT "{}",
FOREIGN KEY(session_id) REFERENCES sessions(id)
)
`;
Expand Down Expand Up @@ -56,6 +57,9 @@ class Database {
'INSERT INTO db_config(id, version) VALUES(?, ?)',
['version', dbVersion],
);
} else if (row?.version === 1) {
await this.run('UPDATE db_config SET version = ?', [dbVersion]);
await this.run('ALTER TABLE session_instances ADD config TEXT NOT NULL DEFAULT "{}"');
}
}

Expand Down
89 changes: 88 additions & 1 deletion src/main/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const { app, BrowserWindow, Menu, ipcMain, dialog } = require('electron');
const { app, BrowserWindow, Menu, ipcMain, dialog, shell } = require('electron');
const path = require('path');
const { v4: uuidv4 } = require('uuid');
const { is } = require('electron-util');
const unhandled = require('electron-unhandled');
const debug = require('electron-debug');
Expand Down Expand Up @@ -31,6 +32,12 @@ if (!is.development) {
const logReader = new LogReader(config.get('log'), config.get('avatarName'));
const assetPath = is.development ? app.getAppPath() : process.resourcesPath;

const initialHuntingSets = config.get('huntingSets', []);
let activeHuntingSet = initialHuntingSets.find(set => set.default);
if (!activeHuntingSet) {
activeHuntingSet = initialHuntingSets[0];
}

const createMainWindow = async () => {
const win = new BrowserWindow({
icon: path.join(assetPath, 'assets/icon.png'),
Expand Down Expand Up @@ -121,6 +128,7 @@ app.on('activate', async () => {
(async () => {
await app.whenReady();
session = await Session.Create();
session.setHuntingSet(activeHuntingSet);
Menu.setApplicationMenu(menu);
mainWindow = await createMainWindow();
})();
Expand All @@ -132,9 +140,26 @@ function getSettings() {
log: config.get('log', null),
avatarName: config.get('avatarName', null),
sidebarStyle: config.get('sidebarStyle', 'full'),
huntingSets: config.get('huntingSets', []),
activeHuntingSet: activeHuntingSet?.id,
};
}

function setDefaultHuntingSet() {
activeHuntingSet = config.get('huntingSets', []).find(set => set.default);

if (!activeHuntingSet) {
activeHuntingSet = config.get('huntingSets', [])[0];
}

const updatedSettings = getSettings();
mainWindow.webContents.send('settings-updated', updatedSettings);

if (streamWindow && streamWindow.isVisible()) {
streamWindow.webContents.send('settings-updated', updatedSettings);
}
}

function receivedLoggerEvent({ data, lastLine }) {
session.newEvent(data, lastLine).then(() => {
// Only send the complete package
Expand Down Expand Up @@ -164,18 +189,23 @@ function stopLogReader() {

async function startNewSession(emit = true) {
stopLogReader();
setDefaultHuntingSet();

session = await Session.Create();
session.setHuntingSet(activeHuntingSet);
if (emit) {
mainWindow.webContents.send('session-new', session.getData());
}
}

function startNewInstance(emit = true) {
stopLogReader();
setDefaultHuntingSet();

if (session) {
session.createNewInstance();
session.setHuntingSet(activeHuntingSet);

if (emit) {
mainWindow.webContents.send('instance-new', session.getData());
}
Expand All @@ -196,6 +226,10 @@ ipcMain.on('show-settings', () => {
}
});

ipcMain.on('goto-wiki-weapontool', () => {
shell.openExternal('http://www.entropiawiki.com/WeaponCompareV2.aspx');
});

ipcMain.on('logging-status-toggle', () => {
if (logReader) {
if (!logReader.active) {
Expand Down Expand Up @@ -232,6 +266,8 @@ ipcMain.on('load-instance', async (_event, { sessionId, instanceId }) => {
if (session) {
const selectedInstanceId = (instanceId === 'new') ? null : instanceId;
session = await Session.Load(sessionId, selectedInstanceId);
session.setHuntingSet(activeHuntingSet);

if (instanceId === 'new') {
session.createNewInstance();
mainWindow.webContents.send('instance-new', session.getData());
Expand All @@ -241,6 +277,16 @@ ipcMain.on('load-instance', async (_event, { sessionId, instanceId }) => {
}
});

ipcMain.on('change-hunting-set', (_event, selectedHuntingSet) => {
if (session) {
activeHuntingSet = selectedHuntingSet;
session.setHuntingSet(selectedHuntingSet);

const updatedSettings = getSettings();
mainWindow.webContents.send('settings-updated', updatedSettings);
}
});

// Ipc Events with response

ipcMain.handle('select-logfile', async () => {
Expand Down Expand Up @@ -318,6 +364,47 @@ ipcMain.handle('set-data', async (_event, data) => {
return response;
});

ipcMain.handle('set-hunting-sets', (_event, sets) => {
let response = false;
const currentSavedSets = config.get('huntingSets', []);

try {
const updatedSets = sets.map(set => {
set.id = set.id ? set.id : uuidv4();
if (set.default === undefined) {
const wasDefault = currentSavedSets.find(originalSet => originalSet.id === set.id)?.default;
if (wasDefault !== null) {
set.default = wasDefault;
}
}

set.default = (set.default !== undefined) ? set.default : false;
return set;
});

const confirmActiveHuntingSet = updatedSets.find(set => set.id === activeHuntingSet?.id);

config.set('huntingSets', updatedSets);

// Active set has been removed, set default
if (!confirmActiveHuntingSet) {
setDefaultHuntingSet();
if (session) {
session.setHuntingSet(activeHuntingSet);
}
}

response = true;
} catch (error) {
console.error(error);
}

const updatedSettings = getSettings();
mainWindow.webContents.send('settings-updated', updatedSettings);

return response;
});

ipcMain.handle('delete', async (_event, { type, id }) => {
let status = false;
const currentSessionData = session ? session.getData(false) : null;
Expand Down
6 changes: 5 additions & 1 deletion src/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { contextBridge, ipcRenderer } = require('electron');

const getters = new Set(['active-session', 'session', 'sessions', 'instances', 'settings', 'logreader-status', 'development-mode']);
const setters = new Set(['active-session', 'settings']);
const actions = new Set(['new-session', 'new-instance', 'load-instance', 'stream-window-toggle', 'logging-status-toggle']);
const actions = new Set(['new-session', 'new-instance', 'load-instance', 'stream-window-toggle', 'logging-status-toggle', 'goto-wiki-weapontool', 'change-hunting-set']);
const deletes = new Set(['session', 'instance']);

contextBridge.exposeInMainWorld(
Expand All @@ -26,6 +26,10 @@ contextBridge.exposeInMainWorld(
if (setters.has(dataType)) {
return ipcRenderer.invoke('set-data', { type: dataType, values });
}

if (dataType === 'hunting-sets') {
return ipcRenderer.invoke('set-hunting-sets', values);
}
},
delete(type, id) {
if (deletes.has(type)) {
Expand Down
Loading

0 comments on commit 50a7340

Please sign in to comment.