Initial commit
This commit is contained in:
47
Backend/dist/Pages/KeyManager.js
vendored
Normal file
47
Backend/dist/Pages/KeyManager.js
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.KeyManager = void 0;
|
||||
var Logger_1 = require("../Logger");
|
||||
var KeyManager = /** @class */ (function () {
|
||||
function KeyManager() {
|
||||
this.ids = [];
|
||||
}
|
||||
KeyManager.prototype.register = function (keyID) {
|
||||
if (!this.ids.includes(keyID))
|
||||
this.ids.push(keyID);
|
||||
else {
|
||||
Logger_1.Log('warn', "Duplicate key IDs '" + keyID + "'");
|
||||
keyID = this.generateNew();
|
||||
}
|
||||
return keyID;
|
||||
};
|
||||
KeyManager.prototype.generateNew = function () {
|
||||
var _this = this;
|
||||
return this.register(Undecked.generateRandom(16, function (checkValid) {
|
||||
return !_this.ids.includes(checkValid);
|
||||
}));
|
||||
};
|
||||
KeyManager.prototype.getLocation = function (keyID) {
|
||||
var pages = Undecked.Pages.getAll();
|
||||
for (var pageID in pages) {
|
||||
var page = pages[pageID];
|
||||
if (page.hasKeyWithID(keyID)) {
|
||||
return __assign({ pageID: pageID }, page.getKeyLocationWithID(keyID));
|
||||
}
|
||||
}
|
||||
return { pageID: null, x: null, y: null };
|
||||
};
|
||||
return KeyManager;
|
||||
}());
|
||||
exports.KeyManager = KeyManager;
|
||||
//# sourceMappingURL=KeyManager.js.map
|
||||
1
Backend/dist/Pages/KeyManager.js.map
vendored
Normal file
1
Backend/dist/Pages/KeyManager.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"KeyManager.js","sourceRoot":"","sources":["../../src/Pages/KeyManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,oCAAgC;AAIhC;IAGC;QACC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IACf,CAAC;IAED,6BAAQ,GAAR,UAAS,KAAa;QACrB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC/C;YACJ,YAAG,CAAC,MAAM,EAAE,wBAAsB,KAAK,MAAG,CAAC,CAAC;YAC5C,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;SAC3B;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,gCAAW,GAAX;QAAA,iBAMC;QALA,OAAO,IAAI,CAAC,QAAQ,CACnB,QAAQ,CAAC,cAAc,CAAC,EAAE,EAAE,UAAC,UAAU;YACtC,OAAO,CAAC,KAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC,CAAC,CACF,CAAC;IACH,CAAC;IAED,gCAAW,GAAX,UAAY,KAAK;QAChB,IAAI,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACpC,KAAK,IAAI,MAAM,IAAI,KAAK,EAAE;YACzB,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YACzB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;gBAC7B,kBAAS,MAAM,QAAA,IAAK,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAG;aACvD;SACD;QACD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC;IAC3C,CAAC;IACF,iBAAC;AAAD,CAAC,AAlCD,IAkCC;AAlCY,gCAAU"}
|
||||
397
Backend/dist/Pages/Page.js
vendored
Normal file
397
Backend/dist/Pages/Page.js
vendored
Normal file
@@ -0,0 +1,397 @@
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
exports.__esModule = true;
|
||||
var fs_extra_1 = require("fs-extra");
|
||||
var path = require("path");
|
||||
var Logger_1 = require("../Logger");
|
||||
module.exports = /** @class */ (function () {
|
||||
function Page(settings) {
|
||||
this.pageFilePath = path.join(Undecked.dataPath, 'pages', settings.pageID + ".json");
|
||||
this.pageID = settings.pageID;
|
||||
this.name = settings.name || "Unnamed page (" + this.pageID + ")";
|
||||
this.keys = settings.keys || {};
|
||||
this.ensureKeys();
|
||||
}
|
||||
Page.prototype.save = function (callback) {
|
||||
var _this = this;
|
||||
clearTimeout(this.saveTimeout);
|
||||
this.saveTimeout = setTimeout(function () {
|
||||
fs_extra_1.writeJson(_this.pageFilePath, _this["export"](), function (err) {
|
||||
if (err)
|
||||
Logger_1.Log('error', "Error whilst saving page " + _this.pageID, err.message);
|
||||
else
|
||||
Logger_1.Log('info', "Page " + _this.pageID + " has been saved");
|
||||
if (callback)
|
||||
callback();
|
||||
});
|
||||
}, 10 * 1000);
|
||||
};
|
||||
Page.prototype["export"] = function () {
|
||||
var keys = JSON.parse(JSON.stringify(this.keys));
|
||||
for (var y in keys) {
|
||||
for (var x in keys[y]) {
|
||||
var key = keys[y][x];
|
||||
if (key.state != undefined && key.state.type == 'ghost' && key.state.masterID != undefined) {
|
||||
var location = Undecked.Pages.KeyManager.getLocation(key.state.masterID);
|
||||
var page = Undecked.Pages.get(location.pageID);
|
||||
if (page) {
|
||||
var ghostMaster = page.getKey(location.x, location.y);
|
||||
key.appearence = ghostMaster.appearence;
|
||||
key.actions = ghostMaster.actions;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
pageID: this.pageID,
|
||||
name: this.name,
|
||||
keys: keys
|
||||
};
|
||||
};
|
||||
Page.prototype.getID = function () {
|
||||
return this.pageID;
|
||||
};
|
||||
Page.prototype.ensureKeys = function () {
|
||||
for (var y = 0; y < 4; y++) {
|
||||
if (this.keys[y] == undefined)
|
||||
this.keys[y] = {};
|
||||
for (var x = 0; x < 8; x++) {
|
||||
if (this.keys[y][x] == undefined)
|
||||
this.keys[y][x] = __assign(__assign({}, defaultKey), { id: null });
|
||||
if (this.keys[y][x].id == null || this.keys[y][x].id == undefined)
|
||||
this.keys[y][x].id = Undecked.Pages.KeyManager.generateNew();
|
||||
else
|
||||
Undecked.Pages.KeyManager.register(this.keys[y][x].id);
|
||||
if (this.keys[y][x].actions == undefined)
|
||||
this.keys[y][x].actions = {};
|
||||
if (this.keys[y][x].actions.up == undefined)
|
||||
this.keys[y][x].actions.up = {};
|
||||
if (this.keys[y][x].actions.down == undefined)
|
||||
this.keys[y][x].actions.down = {};
|
||||
if (this.keys[y][x].actions.latch == undefined)
|
||||
this.keys[y][x].actions.latch = {};
|
||||
if (this.keys[y][x].actions.unlatch == undefined)
|
||||
this.keys[y][x].actions.unlatch = {};
|
||||
if (this.keys[y][x].state.type == 'ghost') {
|
||||
if (this.keys[y][x].state.masterID != undefined) {
|
||||
var location = Undecked.Pages.KeyManager.getLocation(this.keys[y][x].state.masterID);
|
||||
var page = Undecked.Pages.get(location.pageID);
|
||||
if (page) {
|
||||
var key = page.getKey(location.x, location.y);
|
||||
if (key.state.ghostIDs == undefined)
|
||||
key.state.ghostIDs = [];
|
||||
key.state.ghostIDs.push(this.keys[y][x].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Page.prototype.setName = function (name) {
|
||||
this.name = name;
|
||||
this.save();
|
||||
Undecked.SocketServer.broadcastTo('home', 'page', 'updatename', this.pageID, name);
|
||||
};
|
||||
Page.prototype.broadcastKeyUpdate = function (x, y, responseToken, key) {
|
||||
if (responseToken === void 0) { responseToken = '-1'; }
|
||||
Undecked.SocketServer.broadcastTo('home', 'page', 'updatekey', this.pageID, x, y, key != undefined ? key : this.keys[y][x], responseToken);
|
||||
};
|
||||
Page.prototype.updateKey = function (x, y, key, responseToken, originQuery, force) {
|
||||
if (force === void 0) { force = false; }
|
||||
if (this.keys[y] != undefined && this.keys[y][x] != undefined) {
|
||||
//FIXME:GHOST still not working oging to bed now, I think i should rewrite it tomorrow.....
|
||||
/* When updating key check if key is a ghost, if so recall the function with the master key. Update all properties on master key as usual. If a key has ghostIDs, update the appearence and actions of the key. */
|
||||
//----------------------------------Validating key
|
||||
var masterResponseToken = originQuery == undefined
|
||||
? responseToken
|
||||
: this.pageID + "_" + x + "_" + y == originQuery ? responseToken : '-1';
|
||||
originQuery = this.pageID + "_" + x + "_" + y;
|
||||
var decks = Undecked.Decks.decks;
|
||||
var currentKey = this.keys[y][x];
|
||||
var grabBest = function (object, value, defaultValue, incommingFirst) {
|
||||
if (incommingFirst === void 0) { incommingFirst = true; }
|
||||
if (key.state.type == 'empty')
|
||||
return defaultValue;
|
||||
if ((incommingFirst == true || force == true) && key[object] != undefined)
|
||||
if (value != null && key[object][value] != undefined)
|
||||
return key[object][value];
|
||||
else if (value == null)
|
||||
return key[object];
|
||||
if (currentKey[object] != undefined)
|
||||
if (value != null && currentKey[object][value] != undefined)
|
||||
return currentKey[object][value];
|
||||
else if (value == null)
|
||||
return currentKey[object];
|
||||
if (incommingFirst == false && key[object] != undefined)
|
||||
if (value != null && key[object][value] != undefined)
|
||||
return key[object][value];
|
||||
else if (value == null)
|
||||
return key[object];
|
||||
return defaultValue;
|
||||
};
|
||||
if (currentKey.state.type != 'ghost' && key.state.type == 'ghost') {
|
||||
//Becoming ghost
|
||||
}
|
||||
else if (currentKey.state.type == 'ghost' && (key.state.type == 'ghost' || key.state.type == 'custom')) {
|
||||
//Editing ghost
|
||||
if (key.state.type == 'custom')
|
||||
key.state.type = 'ghost';
|
||||
var masterID = currentKey.state.masterID;
|
||||
var masterLocation = Undecked.Pages.KeyManager.getLocation(masterID);
|
||||
var masterPage = Undecked.Pages.get(masterLocation.pageID);
|
||||
if (masterPage) {
|
||||
var masterKeyClone = JSON.parse(JSON.stringify(masterPage.getKey(masterLocation.x, masterLocation.y)));
|
||||
return masterPage.updateKey(masterLocation.x, masterLocation.y, __assign(__assign({}, masterKeyClone), { state: __assign(__assign({}, masterKeyClone.state), { confirm: key.state.confirm, toggle: key.state.toggle }), appearence: key.appearence }), responseToken, originQuery);
|
||||
}
|
||||
return console.log('Unable to find ghost master key');
|
||||
}
|
||||
else if (currentKey.state.type == 'ghost' && key.state.type != 'ghost') {
|
||||
var masterID = currentKey.state.masterID;
|
||||
var masterLocation = Undecked.Pages.KeyManager.getLocation(masterID);
|
||||
var masterPage = Undecked.Pages.get(masterLocation.pageID);
|
||||
if (masterPage) {
|
||||
var masterKey = masterPage.getKey(masterLocation.x, masterLocation.y);
|
||||
if (masterKey.state != undefined && masterKey.state.ghostIDs != undefined) {
|
||||
if (masterKey.state.ghostIDs.includes(currentKey.id))
|
||||
masterKey.state.ghostIDs.splice(masterKey.state.ghostIDs.indexOf(currentKey.id), 1);
|
||||
}
|
||||
}
|
||||
//Reverting from ghost
|
||||
}
|
||||
else if (currentKey.state.type == 'custom' &&
|
||||
key.state.type != 'custom' &&
|
||||
currentKey.state.ghostIDs != undefined &&
|
||||
currentKey.state.ghostIDs.length > 0) {
|
||||
//Master becoming other key
|
||||
var ghostIDs = currentKey.state.ghostIDs;
|
||||
var removeGhost = function (ghostID) {
|
||||
var ghostLocation = Undecked.Pages.KeyManager.getLocation(ghostID);
|
||||
var ghostPage = Undecked.Pages.get(ghostLocation.pageID);
|
||||
if (ghostPage) {
|
||||
var ghostKey = ghostPage.getKey(ghostLocation.x, ghostLocation.y);
|
||||
if (ghostKey.state != undefined && ghostKey.state.masterID == currentKey.id) {
|
||||
if (ghostPage.keys[ghostLocation.y] != undefined &&
|
||||
ghostPage.keys[ghostLocation.y][ghostLocation.x]) {
|
||||
ghostPage.keys[ghostLocation.y][ghostLocation.x] = {
|
||||
id: ghostKey.id,
|
||||
appearence: {},
|
||||
state: { confirm: false, toggle: false, type: 'empty' }
|
||||
};
|
||||
ghostPage.broadcastKeyUpdate(ghostLocation.x, ghostLocation.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
for (var i = 0; i < ghostIDs.length; i++) {
|
||||
removeGhost(ghostIDs[i]);
|
||||
continue;
|
||||
}
|
||||
currentKey.state.ghostIDs = null;
|
||||
}
|
||||
else {
|
||||
//Normal change
|
||||
}
|
||||
var id = currentKey.id != undefined ? currentKey.id : Undecked.Pages.KeyManager.generateNew();
|
||||
var _internal = currentKey._internal != undefined ? currentKey._internal : {};
|
||||
var state = {
|
||||
confirm: grabBest('state', 'confirm', false),
|
||||
toggle: grabBest('state', 'toggle', false),
|
||||
type: grabBest('state', 'type', 'empty'),
|
||||
masterID: grabBest('state', 'masterID', null, false),
|
||||
ghostIDs: grabBest('state', 'ghostIDs', null, false)
|
||||
};
|
||||
var actions = state.type == 'empty'
|
||||
? { down: {}, up: {}, latch: {}, unlatch: {} }
|
||||
: force == true
|
||||
? key.actions
|
||||
: currentKey.actions != undefined
|
||||
? currentKey.actions
|
||||
: { up: {}, down: {}, latch: {}, unlatch: {} };
|
||||
var appearence = {
|
||||
background: grabBest('appearence', 'background', {}),
|
||||
image: grabBest('appearence', 'image', {}),
|
||||
text: grabBest('appearence', 'text', {})
|
||||
};
|
||||
this.keys[y][x] = {
|
||||
id: id,
|
||||
_internal: _internal,
|
||||
actions: actions,
|
||||
state: state,
|
||||
appearence: appearence
|
||||
};
|
||||
//----------------------------------Updating decks & web ui
|
||||
var deckPages = {};
|
||||
for (var serialNumber in decks) {
|
||||
var deck = decks[serialNumber];
|
||||
if (deckPages[deck.getPageID()] == undefined)
|
||||
deckPages[deck.getPageID()] = [];
|
||||
deckPages[deck.getPageID()].push(deck);
|
||||
if (deck.getPageID() == this.pageID) {
|
||||
deck.updateKey(parseInt(x), parseInt(y));
|
||||
}
|
||||
}
|
||||
if (this.keys[y][x].state.type == 'ghost') {
|
||||
var masterLocation = Undecked.Pages.KeyManager.getLocation(this.keys[y][x].state.masterID);
|
||||
var masterPage = Undecked.Pages.get(masterLocation.pageID);
|
||||
if (masterPage) {
|
||||
var masterClone = JSON.parse(JSON.stringify(masterPage.getKey(masterLocation.x, masterLocation.y)));
|
||||
this.broadcastKeyUpdate(x, y, masterResponseToken, __assign(__assign({}, key), { state: __assign(__assign({}, key.state), { confirm: masterClone.state.confirm, toggle: masterClone.state.toggle }), appearence: masterClone.appearence }));
|
||||
}
|
||||
}
|
||||
else
|
||||
this.broadcastKeyUpdate(x, y, masterResponseToken);
|
||||
if (currentKey.state.type == 'custom' &&
|
||||
currentKey.state.ghostIDs != undefined &&
|
||||
currentKey.state.ghostIDs.length > 0) {
|
||||
//Updating ghost of this key
|
||||
var ghostAppearence = JSON.parse(JSON.stringify(appearence));
|
||||
ghostAppearence.system = { ghost: true };
|
||||
for (var i = 0; i < currentKey.state.ghostIDs.length; i++) {
|
||||
var ghostID = currentKey.state.ghostIDs[i];
|
||||
var ghostLocation = Undecked.Pages.KeyManager.getLocation(ghostID);
|
||||
var ghostPage = Undecked.Pages.get(ghostLocation.pageID);
|
||||
if (ghostPage) {
|
||||
var ghostKeyClone = JSON.parse(JSON.stringify(ghostPage.getKey(ghostLocation.x, ghostLocation.y)));
|
||||
if (ghostKeyClone.state != undefined && ghostKeyClone.state.masterID == id) {
|
||||
var responseTokenGhost = originQuery == undefined
|
||||
? responseToken
|
||||
: ghostLocation.pageID + "_" + ghostLocation.x + "_" + ghostLocation.y == originQuery
|
||||
? responseToken
|
||||
: '-1';
|
||||
var newGhostKey = __assign(__assign({}, ghostKeyClone), { appearence: ghostAppearence });
|
||||
ghostPage.broadcastKeyUpdate(ghostLocation.x, ghostLocation.y, responseTokenGhost, newGhostKey);
|
||||
if (deckPages[ghostPage.getID()] != undefined)
|
||||
for (var i_1 = 0; i_1 < deckPages[ghostPage.getID()].length; i_1++) {
|
||||
var deck = deckPages[ghostPage.getID()][i_1];
|
||||
deck.setKey(ghostLocation.x, ghostLocation.y, newGhostKey);
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentKey.state.ghostIDs.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.save();
|
||||
}
|
||||
};
|
||||
Page.prototype.setKeyInternal = function (x, y, property, value) {
|
||||
if (this.keys[y] != undefined && this.keys[y][x] != undefined) {
|
||||
this.keys[y][x]._internal[property] = value;
|
||||
this.save();
|
||||
}
|
||||
};
|
||||
Page.prototype.getKey = function (x, y) {
|
||||
if (this.keys[y] != undefined && this.keys[y][x] != undefined)
|
||||
return this.keys[y][x];
|
||||
return null;
|
||||
};
|
||||
Page.prototype.requestKey = function (x, y) {
|
||||
if (this.keys[y] != undefined && this.keys[y][x] != undefined) {
|
||||
if (this.keys[y][x].state != undefined &&
|
||||
this.keys[y][x].state.type == 'ghost' &&
|
||||
this.keys[y][x].state.masterID != undefined) {
|
||||
var key = JSON.parse(JSON.stringify(this.keys[y][x]));
|
||||
var location = Undecked.Pages.KeyManager.getLocation(key.state.masterID);
|
||||
var page = Undecked.Pages.get(location.pageID);
|
||||
if (page) {
|
||||
var ghostMasterClone = JSON.parse(JSON.stringify(page.getKey(location.x, location.y)));
|
||||
key.state = __assign(__assign({}, this.keys[y][x].state), { confirm: ghostMasterClone.state.confirm, toggle: ghostMasterClone.state.toggle });
|
||||
key.appearence = ghostMasterClone.appearence;
|
||||
key.actions = ghostMasterClone.actions;
|
||||
return key;
|
||||
}
|
||||
}
|
||||
else
|
||||
return this.keys[y][x];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Page.prototype.hasKey = function (x, y) {
|
||||
return this.keys[y] != undefined && this.keys[y][x] != undefined;
|
||||
};
|
||||
Page.prototype.hasKeyWithID = function (keyID) {
|
||||
for (var y = 0; y < 4; y++)
|
||||
for (var x = 0; x < 8; x++)
|
||||
if (this.keys[y] != undefined && this.keys[y][x] != undefined)
|
||||
if (this.keys[y][x].id == keyID)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
Page.prototype.getKeyLocationWithID = function (keyID) {
|
||||
for (var y = 0; y < 4; y++)
|
||||
for (var x = 0; x < 8; x++)
|
||||
if (this.keys[y] != undefined && this.keys[y][x] != undefined)
|
||||
if (this.keys[y][x].id == keyID)
|
||||
return { x: x, y: y };
|
||||
return null;
|
||||
};
|
||||
Page.prototype.getKeyTextList = function () {
|
||||
var list = [];
|
||||
for (var y = 0; y < 4; y++)
|
||||
for (var x = 0; x < 8; x++) {
|
||||
if (this.keys[y] != undefined && this.keys[y][x] != undefined) {
|
||||
var key = this.keys[y][x];
|
||||
if (key.appearence != undefined && key.appearence.text != undefined) {
|
||||
if (key.appearence.text.value != undefined && key.appearence.text.value.length > 0) {
|
||||
list.push({ x: x, y: y, text: key.appearence.text.value, id: key.id });
|
||||
continue;
|
||||
}
|
||||
}
|
||||
list.push({ x: x, y: y, text: null, id: key.id });
|
||||
}
|
||||
else
|
||||
list.push({ x: x, y: y, text: null, id: null });
|
||||
}
|
||||
return list;
|
||||
};
|
||||
Page.prototype.getActionInstance = function (key, actionInstanceID) {
|
||||
if (key.actions != undefined) {
|
||||
if (key.actions.up != undefined && key.actions.up[actionInstanceID] != undefined)
|
||||
return key.actions.up[actionInstanceID];
|
||||
if (key.actions.down != undefined && key.actions.down[actionInstanceID] != undefined)
|
||||
return key.actions.down[actionInstanceID];
|
||||
if (key.actions.latch != undefined && key.actions.latch[actionInstanceID] != undefined)
|
||||
return key.actions.latch[actionInstanceID];
|
||||
if (key.actions.unlatch != undefined && key.actions.unlatch[actionInstanceID] != undefined)
|
||||
return key.actions.unlatch[actionInstanceID];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return Page;
|
||||
}());
|
||||
var defaultKey = {
|
||||
id: null,
|
||||
state: {
|
||||
type: 'empty',
|
||||
toggle: false,
|
||||
confirm: false
|
||||
},
|
||||
actions: {
|
||||
up: {},
|
||||
down: {},
|
||||
latch: {},
|
||||
unlatch: {}
|
||||
},
|
||||
appearence: {
|
||||
text: {
|
||||
color: '#ffffff',
|
||||
size: 20,
|
||||
value: '',
|
||||
offsetX: 0,
|
||||
offsetY: 0
|
||||
}
|
||||
},
|
||||
_internal: {}
|
||||
};
|
||||
//# sourceMappingURL=Page.js.map
|
||||
1
Backend/dist/Pages/Page.js.map
vendored
Normal file
1
Backend/dist/Pages/Page.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
273
Backend/dist/Pages/PageManager.js
vendored
Normal file
273
Backend/dist/Pages/PageManager.js
vendored
Normal file
@@ -0,0 +1,273 @@
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.PageManager = void 0;
|
||||
var path = require("path");
|
||||
var Logger_1 = require("../Logger");
|
||||
var KeyManager_1 = require("./KeyManager");
|
||||
var fs = require("fs-extra");
|
||||
var ensureDir = fs.ensureDir, pathExists = fs.pathExists, readdir = fs.readdir, readJSON = fs.readJSON, readJson = fs.readJson, writeFile = fs.writeFile;
|
||||
var PageClass = require('./Page');
|
||||
var PageManager = /** @class */ (function () {
|
||||
function PageManager() {
|
||||
}
|
||||
PageManager.prototype.load = function (callback) {
|
||||
var _this = this;
|
||||
this.managerConfigPath = path.join(Undecked.dataPath, 'pagemanager.json');
|
||||
this.managerDataPath = path.join(Undecked.dataPath, 'pages');
|
||||
this.KeyManager = new KeyManager_1.KeyManager();
|
||||
this.pages = {};
|
||||
this.order = [];
|
||||
Logger_1.Log('info', 'Loading pages');
|
||||
ensureDir(this.managerDataPath, function (err) {
|
||||
if (err)
|
||||
throw err;
|
||||
_this.loadConfig(function () {
|
||||
_this.order = _this.managerConfig.order || [];
|
||||
_this.loadPages(callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
PageManager.prototype.loadConfig = function (callback) {
|
||||
var _this = this;
|
||||
pathExists(this.managerConfigPath, function (err, exists) {
|
||||
if (err)
|
||||
throw err;
|
||||
if (exists) {
|
||||
readJson(_this.managerConfigPath, function (err, json) {
|
||||
if (err)
|
||||
throw err;
|
||||
_this.managerConfig = json;
|
||||
callback();
|
||||
});
|
||||
}
|
||||
else {
|
||||
_this.managerConfig = defaultPageConfig;
|
||||
_this.saveConfig(callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
PageManager.prototype.saveConfig = function (callback) {
|
||||
var toSave = {
|
||||
order: this.order
|
||||
};
|
||||
writeFile(this.managerConfigPath, JSON.stringify(toSave, null, 4), function (err) {
|
||||
if (err)
|
||||
Logger_1.Log('error', 'Error whilst saving manager config', err.message);
|
||||
if (callback)
|
||||
callback();
|
||||
});
|
||||
};
|
||||
PageManager.prototype.loadPages = function (callback) {
|
||||
var instance = this;
|
||||
readdir(this.managerDataPath, function (err, files) {
|
||||
if (err)
|
||||
throw err;
|
||||
(function readPage(i) {
|
||||
if (i === void 0) { i = 0; }
|
||||
if (files[i]) {
|
||||
readJSON(path.join(instance.managerDataPath, files[i]), function (err, data) {
|
||||
if (err)
|
||||
Logger_1.Log('error', "Error whilst loading page " + files[i].replace('.json', ''), err.message);
|
||||
else
|
||||
instance.pages[data.pageID] = new PageClass(data);
|
||||
readPage(i + 1);
|
||||
});
|
||||
}
|
||||
else {
|
||||
Logger_1.Log('info', "Loaded " + Object.keys(instance.pages).length + " page(s)");
|
||||
if (Object.keys(instance.pages).length > 0)
|
||||
callback();
|
||||
else {
|
||||
instance.create('First page', callback);
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
};
|
||||
PageManager.prototype.create = function (pageName, callback) {
|
||||
var existingPageIDs = Object.keys(this.pages);
|
||||
var pageID = Undecked.generateRandom(4, function (testrandom) {
|
||||
return !existingPageIDs.includes(testrandom);
|
||||
}, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
this.pages[pageID] = new PageClass({
|
||||
pageID: pageID,
|
||||
name: pageName + " (" + pageID + ")",
|
||||
keys: {
|
||||
'0': { '0': { state: { type: 'pageup' } } },
|
||||
'1': { '0': { state: { type: 'currentpage' } } },
|
||||
'2': { '0': { state: { type: 'pagedown' } } }
|
||||
}
|
||||
});
|
||||
if (!this.order.includes(pageID))
|
||||
this.order.push(pageID);
|
||||
Undecked.SocketServer.broadcastTo('home', 'pagelist', this.getNames());
|
||||
this.pages[pageID].save(function () {
|
||||
Logger_1.Log('info', "Page " + pageID + " has been created");
|
||||
if (callback)
|
||||
callback();
|
||||
});
|
||||
};
|
||||
PageManager.prototype.exists = function (pageID) {
|
||||
return this.pages[pageID] != undefined;
|
||||
};
|
||||
PageManager.prototype.get = function (pageID) {
|
||||
if (this.exists(pageID))
|
||||
return this.pages[pageID];
|
||||
return null;
|
||||
};
|
||||
PageManager.prototype.getAll = function () {
|
||||
return this.pages;
|
||||
};
|
||||
PageManager.prototype.getIdByIndex = function (index) {
|
||||
var ids = this.order;
|
||||
if (ids[index])
|
||||
return ids[index];
|
||||
return null;
|
||||
};
|
||||
PageManager.prototype.getIndexById = function (id) {
|
||||
var ids = this.order;
|
||||
if (ids.includes(id))
|
||||
return ids.indexOf(id);
|
||||
return null;
|
||||
};
|
||||
PageManager.prototype.getNames = function () {
|
||||
var order = this.getOrder();
|
||||
var names = [];
|
||||
for (var i = 0; i < order.length; i++) {
|
||||
if (this.pages[order[i]] != undefined) {
|
||||
var page = this.pages[order[i]];
|
||||
names.push({ pageID: order[i], name: page.name });
|
||||
}
|
||||
}
|
||||
return names;
|
||||
};
|
||||
PageManager.prototype.getOrder = function () {
|
||||
var hasChanges = false;
|
||||
for (var pageID in this.pages) {
|
||||
if (!this.order.includes(pageID)) {
|
||||
this.order.push(pageID);
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < this.order.length; i++) {
|
||||
if (this.pages[this.order[i]] == undefined) {
|
||||
this.order.splice(i, 1);
|
||||
i--;
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
if (hasChanges)
|
||||
this.saveConfig();
|
||||
return this.order;
|
||||
};
|
||||
PageManager.prototype.setOrder = function (order) {
|
||||
var newOrder = [];
|
||||
for (var i = 0; i < order.length; i++)
|
||||
if (this.exists(order[i]))
|
||||
newOrder.push(order[i]);
|
||||
for (var pageID in this.pages)
|
||||
if (!newOrder.includes(pageID))
|
||||
newOrder.push(pageID);
|
||||
this.order = newOrder;
|
||||
for (var serialNumber in Undecked.Decks.decks)
|
||||
Undecked.Decks.decks[serialNumber].updateAll();
|
||||
Undecked.SocketServer.broadcastTo('home', 'pagelist', this.getNames());
|
||||
this.saveConfig();
|
||||
};
|
||||
PageManager.prototype.handleOperation = function (operation, originPageID, originX, originY, destinationPageID, destinationX, destinationY) {
|
||||
var _this = this;
|
||||
var findKey = function (pageID, x, y) {
|
||||
if (_this.exists(pageID)) {
|
||||
return _this.get(pageID).getKey(x, y);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
var setKey = function (pageID, x, y, key, force) {
|
||||
if (force === void 0) { force = false; }
|
||||
if (_this.exists(pageID)) {
|
||||
return _this.get(pageID).updateKey(x, y, key, '-1', null, force);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
var newKey = function () {
|
||||
return {
|
||||
state: { type: 'empty', confirm: false, toggle: false },
|
||||
appearence: {},
|
||||
actions: { down: {}, up: {}, latch: {}, unlatch: {} },
|
||||
id: Undecked.Pages.KeyManager.generateNew()
|
||||
};
|
||||
};
|
||||
var originKey = findKey(originPageID, originX, originY);
|
||||
var destinationKey = findKey(destinationPageID, destinationX, destinationY);
|
||||
var originKeyClone = JSON.parse(JSON.stringify(originKey));
|
||||
if (originKey && originKey.state.type == 'custom') {
|
||||
switch (operation) {
|
||||
case 'copy':
|
||||
//FIXME: For some reason it doesnt copy the actions
|
||||
if (destinationKey) {
|
||||
var destinationKeyID = destinationKey.id;
|
||||
var actions = originKeyClone.actions;
|
||||
for (var actionsCategory in actions) {
|
||||
for (var actionID in actions[actionsCategory]) {
|
||||
actions[actionsCategory][actionID].id = Undecked.generateRandom(8, function (checkValid) {
|
||||
return actions[actionsCategory][actionID] == undefined;
|
||||
});
|
||||
}
|
||||
}
|
||||
setKey(destinationPageID, destinationX, destinationY, __assign(__assign({}, originKey), { actions: actions, id: destinationKeyID }), true);
|
||||
}
|
||||
break;
|
||||
case 'cut':
|
||||
if (destinationKey) {
|
||||
setKey(originPageID, originX, originY, newKey(), true);
|
||||
setKey(destinationPageID, destinationX, destinationY, originKeyClone, true);
|
||||
}
|
||||
break;
|
||||
case 'ghost':
|
||||
if (destinationKey) {
|
||||
var originKeyID = originKey.id;
|
||||
var destinationKeyID = destinationKey.id;
|
||||
setKey(destinationPageID, destinationX, destinationY, {
|
||||
id: destinationKeyID,
|
||||
appearence: {},
|
||||
state: {
|
||||
type: 'ghost',
|
||||
toggle: false,
|
||||
confirm: false,
|
||||
masterID: originKeyID
|
||||
},
|
||||
actions: {
|
||||
up: {},
|
||||
down: {},
|
||||
latch: {},
|
||||
unlatch: {}
|
||||
}
|
||||
}, true);
|
||||
if (originKey.state.ghostIDs == undefined)
|
||||
originKey.state.ghostIDs = [];
|
||||
originKey.state.ghostIDs.push(destinationKeyID);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
setKey(originPageID, originX, originY, newKey(), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
return PageManager;
|
||||
}());
|
||||
exports.PageManager = PageManager;
|
||||
var defaultPageConfig = {
|
||||
order: []
|
||||
};
|
||||
//# sourceMappingURL=PageManager.js.map
|
||||
1
Backend/dist/Pages/PageManager.js.map
vendored
Normal file
1
Backend/dist/Pages/PageManager.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user