From 050a141ab48dd43cbcb245bea49313b540b48985 Mon Sep 17 00:00:00 2001
From: mamarguerat <49449909+mamarguerat@users.noreply.github.com>
Date: Mon, 18 Mar 2024 21:11:32 +0100
Subject: [PATCH 01/18] Move Device and Link classes in separate files
---
device.js | 50 +++++++++++++++++++++++++++++
link.js | 40 +++++++++++++++++++++++
preload.js | 93 +++---------------------------------------------------
3 files changed, 95 insertions(+), 88 deletions(-)
create mode 100644 device.js
create mode 100644 link.js
diff --git a/device.js b/device.js
new file mode 100644
index 0000000..a502ef0
--- /dev/null
+++ b/device.js
@@ -0,0 +1,50 @@
+const path = require('path');
+
+const publicPath =
+ process.env.NODE_ENV === 'development'
+ ? './public'
+ : path.join(process.resourcesPath, 'public');
+const imagesPath = path.join(publicPath, "assets", "images");
+
+class Device {
+ constructor(x, y, type, id, name) {
+ this.x = x;
+ this.y = y;
+ this.type = type;
+ this.id = id;
+ this.name = name;
+ }
+
+ show() {
+ return "
" +
+ "
A
" +
+ "
B
" +
+ "
";
+ }
+
+ move(newX, newY) {
+ this.x = newX;
+ this.y = newY;
+ }
+
+ delete() {
+ let finished = false;
+ do {
+ finished = false
+ links.forEach((link, index, fullArray) => {
+ // if link on the device to delete
+ if ((this.id == link.device1) || (this.id == link.device2)) {
+ finished = true;
+ links.splice(index, 1); // changes the array length, act as break in loop
+ }
+ });
+ }
+ while (finished)
+ }
+}
+
+module.exports = Device;
\ No newline at end of file
diff --git a/link.js b/link.js
new file mode 100644
index 0000000..e60679d
--- /dev/null
+++ b/link.js
@@ -0,0 +1,40 @@
+const AES50 = {
+ A: "A",
+ B: "B"
+};
+
+class Link {
+ constructor(dev1, aes50_1, dev2, aes50_2) {
+ this.device1 = dev1;
+ this.device2 = dev2;
+ this.aes50_1 = aes50_1;
+ this.aes50_2 = aes50_2;
+ this.check();
+ }
+
+ /// Check if link is valable
+ check() {
+ links.forEach((link, index, fullArray) => {
+ // if link already on aes50
+ if ((this.device1 == link.device1 && this.aes50_1 == link.aes50_1) ||
+ (this.device1 == link.device2 && this.aes50_1 == link.aes50_2) ||
+ (this.device2 == link.device1 && this.aes50_2 == link.aes50_1) ||
+ (this.device2 == link.device2 && this.aes50_2 == link.aes50_2)) {
+ links.splice(index, 1);
+ }
+ });
+ }
+
+ show() {
+ let x1offset = this.aes50_1 == AES50.A ? 58 : 78;
+ let x2offset = this.aes50_2 == AES50.A ? 58 : 78;
+ //return "";
+ return "";
+ }
+}
+
+module.exports = Link
diff --git a/preload.js b/preload.js
index a81daa9..2d900ec 100644
--- a/preload.js
+++ b/preload.js
@@ -1,6 +1,8 @@
const { contextBridge, ipcRenderer } = require('electron');
const { fs } = require('fs');
-const path = require('path')
+const path = require('path');
+const Device = require('./device.js')
+const Link = require('./link.js')
// Uncomment for npm start command
// process.env.NODE_ENV = 'development'
@@ -16,91 +18,6 @@ const AES50 = {
B: "B"
};
-class Device {
- constructor(x, y, type, id, name) {
- this.x = x;
- this.y = y;
- this.type = type;
- this.id = id;
- this.name = name;
- this.visible = true;
- }
-
- show() {
- if (this.visible)
- {
- return "" +
- "
A
" +
- "
B
" +
- "
";
- }
- else return "";
- }
-
- move(newX, newY) {
- this.x = newX;
- this.y = newY;
- }
-
- delete() {
- this.visible = false;
- links.forEach(link => {
- // if link on the device to delete
- if ((this.id == link.device1) || (this.id == link.device2)) {
- link.delete()
- }
- });
- }
-}
-
-class Link {
- constructor(dev1, aes50_1, dev2, aes50_2) {
- this.valid = true
- this.device1 = dev1;
- this.device2 = dev2;
- this.aes50_1 = aes50_1;
- this.aes50_2 = aes50_2;
- this.check();
- }
-
- /// Check if link is valable
- check() {
- links.forEach((link, index, fullArray) => {
- // if link already on aes50
- if ((this.device1 == link.device1 && this.aes50_1 == link.aes50_1) ||
- (this.device1 == link.device2 && this.aes50_1 == link.aes50_2) ||
- (this.device2 == link.device1 && this.aes50_2 == link.aes50_1) ||
- (this.device2 == link.device2 && this.aes50_2 == link.aes50_2)) {
- links.splice(index, 1);
- }
- });
- }
-
- delete() {
- this.valid = false;
- this.device1 = -1;
- this.aes50_1 = -1;
- this.device2 = -1;
- this.aes50_2 = -2;
- }
-
- show() {
- if (this.valid) {
- let x1offset = this.aes50_1 == AES50.A ? 58 : 78;
- let x2offset = this.aes50_2 == AES50.A ? 58 : 78;
- //return "";
- return "";
- }
- }
-}
/*
contextBridge.exposeInMainWorld('versions', {
node: () => process.versions.node,
@@ -112,6 +29,7 @@ contextBridge.exposeInMainWorld('versions', {
*/
let devices = [];
+// TODO: Share variables with modules
let links = [];
let selectedElement = null;
let originX, originY, mouseX, mouseY;
@@ -178,9 +96,7 @@ function enableClick(ele) {
function enableTextBox(parent, ele) {
ele.addEventListener("keyup", (ev) => {
deviceId = ev.target.parentElement.id;
- console.log(deviceId)
devices[id2index(deviceId, devices)].name = ev.target.value;
- console.log(devices)
});
}
@@ -279,5 +195,6 @@ ipcRenderer.on('file', (event, arg) => {
links.push(new Link(link.device1, link.aes50_1, link.device2, link.aes50_2));
})
draw();
+ idCnt = devices[devices.length - 1].id + 1;
}
})
\ No newline at end of file
From 937e1e0baf303a096e77ffb1ecf4322babf338b6 Mon Sep 17 00:00:00 2001
From: mamarguerat <49449909+mamarguerat@users.noreply.github.com>
Date: Sun, 24 Mar 2024 17:50:46 +0100
Subject: [PATCH 02/18] Move constants in separate file
---
const.js | 35 +++++++++++++++++++++++++++++++++++
device-detail-preload.js | 8 ++------
device-detail.html | 4 ----
device.js | 9 ++-------
link.js | 9 +++------
preload.js | 16 ++--------------
6 files changed, 44 insertions(+), 37 deletions(-)
create mode 100644 const.js
diff --git a/const.js b/const.js
new file mode 100644
index 0000000..5a2780d
--- /dev/null
+++ b/const.js
@@ -0,0 +1,35 @@
+const path = require('path');
+
+const publicPath =
+ process.env.NODE_ENV === 'development'
+ ? './public'
+ : path.join(process.resourcesPath, 'public');
+
+module.exports = {
+ imagesPath : path.join(publicPath, "assets", "images"),
+ iconsPath : path.join(publicPath, "assets", "icons", "svg"),
+ AES50: {
+ A: "A",
+ B: "B"
+ },
+ icons : [
+ "No icon", "Kick Back", "Kick Front", "Snare Top", "Snare Bottom", "High Tom", "Mid Tom", "Floor Tom", "Hi-Hat", "Ride",
+ "Drum Kit", "Cowbell", "Bongos", "Congas", "Tambourine", "Vibraphone", "Electric Bass", "Acoustic Bass", "Contrabass", "Les Paul Guitar",
+ "Ibanez Guitar", "Washburn Guitar", "Acoustic Guitar", "Bass Amp", "Guitar Amp", "Amp Cabinet", "Piano", "Organ", "Harpsichord", "Keyboard",
+ "Synthesizer 1", "Synthesizer 2", "Synthesizer 3", "Keytar", "Trumpet", "Trombone", "Saxophone", "Clarinet", "Violin", "Cello",
+ "Male Vocal", "Female Vocal", "Choir", "Hand Sign", "Talk A", "Talk B", "Large Diaphragm Mic", "Condenser Mic Left", "Condenser Mic Right", "Handheld Mic",
+ "Wireless Mic", "Podium Mic", "Headset Mic", "XLR Jack", "TRS Plug", "TRS Plug Left", "TRS Plug Right", "RCA Plug Left", "RCA Plug Right", "Reel to Reel",
+ "FX", "Computer", "Monitor Wedge", "Left Speaker", "Right Speaker", "Speaker Array", "Speaker on a Pole", "Amp Rack", "Controls", "Fader",
+ "MixBus", "Matrix", "Routing", "Smiley"
+ ],
+ colors : [
+ {"Name": "Off", "Color": "#000000", "ID": "OFF"},
+ {"Name": "Red", "Color": "#E72D2E", "ID": "RD"},
+ {"Name": "Green", "Color": "#35e72d", "ID": "GN"},
+ {"Name": "Yellow", "Color": "#FCF300", "ID": "YE"},
+ {"Name": "Blue", "Color": "#0060FF", "ID": "BL"},
+ {"Name": "Magenta", "Color": "#ED27AC", "ID": "MG"},
+ {"Name": "Cyan", "Color": "#2DE0E7", "ID": "CY"},
+ {"Name": "White", "Color": "#FFFFFF", "ID": "WH"}
+ ]
+}
\ No newline at end of file
diff --git a/device-detail-preload.js b/device-detail-preload.js
index 0fd52f2..0dae2eb 100644
--- a/device-detail-preload.js
+++ b/device-detail-preload.js
@@ -1,11 +1,7 @@
const { contextBridge, ipcRenderer } = require('electron')
const path = require('path')
+const Constants = require('./const.js')
-const publicPath =
- process.env.NODE_ENV === 'development'
- ? './public'
- : path.join(process.resourcesPath, 'public');
-const imagesPath = path.join(publicPath, "assets", "images");
function selectTopDiv(ele) {
while (!ele.classList.contains('device') && ele.tagName != "INPUT") {
@@ -28,5 +24,5 @@ function enableRightClick(ele) {
ipcRenderer.on('type', (event, arg) => {
console.log(arg)
- document.getElementById("canvas").innerHTML += "";
+ document.getElementById("canvas").innerHTML += "";
});
\ No newline at end of file
diff --git a/device-detail.html b/device-detail.html
index cfb885c..dc2cce2 100644
--- a/device-detail.html
+++ b/device-detail.html
@@ -1,9 +1,6 @@
-
Device detail
@@ -16,5 +13,4 @@
-