diff --git a/app/js/dataaccess.js b/app/js/dataaccess.js index 83310a5..b2dcb0c 100644 --- a/app/js/dataaccess.js +++ b/app/js/dataaccess.js @@ -388,7 +388,6 @@ module.exports = (function () { for (var i = 0; i < fileEndings.length; i++) { fileEnding = fileEndings[i]; var path = pathModule.join(defaultTokenPath, creatureId + fileEnding); - console.log(path); if (fs.existsSync(path)) return path; } return null; diff --git a/app/js/database.js b/app/js/database.js index fa5ad7b..b703768 100644 --- a/app/js/database.js +++ b/app/js/database.js @@ -1206,13 +1206,11 @@ function loadAll() { } function listAll() { - console.log("List all"); if (listedData == null) { listedData = loadedData; } var data = listedData; - console.log(data); var tabElementName = tab == "homebrew" ? "monsters" : tab; if (sortFunction != null) { data.sort(sortFunction); diff --git a/app/js/util.js b/app/js/util.js index 3373a08..4800312 100644 --- a/app/js/util.js +++ b/app/js/util.js @@ -347,8 +347,9 @@ module.exports = (function () { } function fadeOut(ele, ms = 2000) { + if (!ele.parentNode) return; ele.classList.add("fade_out"); - ele.style.animationDuration = `${ms/1000}s`; + ele.style.animationDuration = `${ms / 1000}s`; window.setTimeout(function (evt) { if (ele.parentNode) ele.parentNode.removeChild(ele); }, ms); diff --git a/app/mappingTool.html b/app/mappingTool.html index 7f74ed0..d3f9c70 100644 --- a/app/mappingTool.html +++ b/app/mappingTool.html @@ -680,13 +680,13 @@

Sound

- + - + - + diff --git a/app/mappingTool/map.admin.js b/app/mappingTool/map.admin.js index 2b349f7..fee4806 100644 --- a/app/mappingTool/map.admin.js +++ b/app/mappingTool/map.admin.js @@ -681,18 +681,16 @@ async function getDefaultLibraryTokenPaths(pawn) { function killOrRevivePawn() { var btn = document.getElementById("kill_or_revive_button"); var revivePawn = btn.innerHTML == "Revive"; + for (var i = 0; i < selectedPawns.length; i++) { killOrReviveHelper(selectedPawns[i]); } - refreshPawnToolTips(); function killOrReviveHelper(pawnElement) { - var isPlayer = isPlayerPawn(pawnElement); - if (revivePawn) { - if (pawnElement.dead == "false") return; - pawnElement.dead = "false"; - if (!isPlayer) { + if (!pawnManager.isDead(pawnElement)) return; + pawnManager.revive(pawnElement); + if (!isPlayerPawn(pawnElement)) { if (pawnElement.index_in_main_window) { window.api.messageWindow("mainWindow", "monster-revived", { name: pawnElement.dnd_name, @@ -701,9 +699,9 @@ function killOrRevivePawn() { } } } else { - if (pawnElement.dead == "true") return; - pawnElement.dead = "true"; - if (!isPlayer) { + if (pawnManager.isDead(pawnElement)) return; + pawnManager.kill(pawnElement); + if (!isPlayerPawn(pawnElement)) { if (pawnElement.index_in_main_window) { window.api.messageWindow("mainWindow", "monster-killed", [pawnElement.dnd_name, pawnElement.index_in_main_window]); } @@ -711,7 +709,6 @@ function killOrRevivePawn() { } var arg = { dead: !revivePawn, elementId: pawnElement.id }; serverNotifier.notifyServer("monster-health-changed", arg); - pawnElement.setAttribute("data-state_changed", 1); } } @@ -798,7 +795,7 @@ function setScaleIfSaved(pawn, path) { if (!path) return; var scale = localStorage.getItem(`token_scale${path}`); if (scale) { - map.setTokenScale(pawn, scale); + pawnManager.setScale(pawn, scale); } else { //Check if file name contains _ScaleXX_, var found = path.toLowerCase().match(/_scale.+_/g); @@ -807,10 +804,10 @@ function setScaleIfSaved(pawn, path) { number = parseInt(number); var fileScale = number / 100; if (fileScale > 0 && fileScale < 10) { - map.setTokenScale(pawn, fileScale); + pawnManager.setScale(pawn, fileScale); } } else { - map.setTokenScale(pawn, 1); + pawnManager.setScale(pawn, 1); } } } @@ -846,11 +843,11 @@ async function setTokenImageHandler(e) { } function showPopupMenuPawn(x, y) { + if (!selectedPawns[0]) return; document.getElementById("popup_menu_general").classList.add("hidden"); - var popup = document.getElementById("popup_menu_pawn"); var killButton = document.getElementById("kill_or_revive_button"); - if (selectedPawns[0].dead == "true") { + if (pawnManager.isDead(selectedPawns[0])) { killButton.innerHTML = "Revive"; } else { killButton.innerHTML = "Kill"; diff --git a/app/mappingTool/map.css b/app/mappingTool/map.css index 02275d6..6d4f3ef 100644 --- a/app/mappingTool/map.css +++ b/app/mappingTool/map.css @@ -470,7 +470,7 @@ li { height: 100%; } -.pawn_dead { +.pawn[data-token-dead=true] { background-color: rgba(218, 0, 0, 0.632) !important; background-image: url("tokens/dead.png"); } diff --git a/app/mappingTool/mapscript.ipc.js b/app/mappingTool/mapscript.ipc.js index 8735901..fc57fe5 100644 --- a/app/mappingTool/mapscript.ipc.js +++ b/app/mappingTool/mapscript.ipc.js @@ -112,7 +112,7 @@ ipcRenderer.on("client-event", function (evt, arg) { map.moveObject(pawn, tanslatedPixels, false) }else if (arg.event == "talk-bubble"){ - map.talkBubble(arg); + pawnManager.talkBubble(arg); } }) ipcRenderer.on("notify-map-tool-monsters-loaded", function (evt, arg) { diff --git a/app/mappingTool/menu.js b/app/mappingTool/menu.js index a368a1f..ae5feb2 100644 --- a/app/mappingTool/menu.js +++ b/app/mappingTool/menu.js @@ -81,7 +81,7 @@ class Menu { document.getElementById("token_scale_button").onclick = (e) => { var firstPawn = selectedPawns[0]; var initValue = - selectedPawns.length == 1 ? map.getTokenScale(firstPawn) : 1; + selectedPawns.length == 1 ? pawnManager.getScale(firstPawn) : 1; Modals.minifiedPrompt( { clientX: firstPawn.offsetLeft, clientY: firstPawn.offsetTop }, @@ -95,7 +95,7 @@ class Menu { (scale) => { if (!scale) return; selectedPawns.forEach((pawn) => { - map.setTokenScale(pawn, scale); + pawnManager.setScale(pawn, scale); }); } ); diff --git a/app/mappingTool/previewPlacing.js b/app/mappingTool/previewPlacing.js index 37c4864..80164ba 100644 --- a/app/mappingTool/previewPlacing.js +++ b/app/mappingTool/previewPlacing.js @@ -37,7 +37,7 @@ const previewPlacementManager = (function () { if (ts == dragPreviewTimestamp) { return; } - + if (!previewPlacementElement) return; dragPreviewTimestamp = ts; e.preventDefault(); var elementHeight = parseFloat(previewPlacementElement.style.height); diff --git a/app/mappingTool/saveManager.js b/app/mappingTool/saveManager.js index 02c1a93..42a8750 100644 --- a/app/mappingTool/saveManager.js +++ b/app/mappingTool/saveManager.js @@ -261,7 +261,7 @@ class SaveManager { } async exportMobTokens(pawn) { - var allTokens = [...pawn.querySelectorAll(".mob_token")].filter(x=> !x.classList.contains("mob_token_dead")); + var allTokens = [...pawn.querySelectorAll(".mob_token")].filter((x) => !x.classList.contains("mob_token_dead")); var tokenPaths = allTokens.map((ele) => ele.getAttribute("data-token_path")); var distinctTokens = [...new Set(tokenPaths)]; @@ -294,12 +294,13 @@ class SaveManager { var darkVisionRadius = element.sight_mode == "darkvision" ? element.sight_radius_bright_light : null; var currentPath = img ? images[currentIndex] || DEFAULT_TOKEN_PATH_JS_RELATIVE : null; var base64 = currentPath ? await util.toBase64(currentPath) : null; - var scale = map.getTokenScale(pawn[0]); + var scale = pawnManager.getScale(pawn[0]); + console.log(pawnManager.isDead(pawn[0])); return { name: pawn[1], id: element.id, isPlayer: isPlayerPawn(pawn[0]), - dead: element.dead, + dead: pawnManager.isDead(element) + "", isMob: isMob, mobSize: mobSize, mobCountDead: 0, @@ -308,7 +309,6 @@ class SaveManager { hexes: element.dnd_hexes, color: element.style.backgroundColor, health_percentage: element.data_health_percentage || "100", - dead: element.dead, scale: scale, size: element.dnd_size, flying_height: element.flying_height, @@ -319,7 +319,6 @@ class SaveManager { bgPhotoBase64: base64, pos: map.objectGridCoords(element), darkVisionRadius: darkVisionRadius, - //attached_objects : element.attached_objects }; } diff --git a/app/mappingTool/serverNotifier.js b/app/mappingTool/serverNotifier.js index f9a1cd3..83cae56 100644 --- a/app/mappingTool/serverNotifier.js +++ b/app/mappingTool/serverNotifier.js @@ -1,6 +1,4 @@ - - -var serverNotifier = function () { +var serverNotifier = (function () { var timeouts = {}; async function mapToolInit() { @@ -9,18 +7,17 @@ var serverNotifier = function () { notifyServer("segments", []); notifyServer("initiative", initiative.getState()); } - - async function sendState() { + async function sendState() { var bgState = {}; - backgroundLoop.saveSlideState(bgState) + backgroundLoop.saveSlideState(bgState); var overlayState = {}; overlayLoop.saveSlideState(overlayState); - ipcRenderer.send("maptool-server-event", { - event: "maptool-state", data: { - tokens: (await getTokensForExport(false)), + event: "maptool-state", + data: { + tokens: await getTokensForExport(false), backgroundLoop: bgState, overlayLoop: overlayState, foreground: getForegroundState(), @@ -31,21 +28,19 @@ var serverNotifier = function () { fog: fovLighting.getFogStyle(), conditions: await getConditionsForExport(), roundTimer: roundTimer?.getState(), - initiative: initiative.getState() - } + initiative: initiative.getState(), + }, }); - } - function getSegments() { var segments = fovLighting.getSegments(); - return segments.map(seg => { + return segments.map((seg) => { return { a: map.toGridCoords(seg.a.x, seg.a.y), - b: map.toGridCoords(seg.b.x, seg.b.y) - } - }) + b: map.toGridCoords(seg.b.x, seg.b.y), + }; + }); } function isServer() { @@ -54,7 +49,7 @@ var serverNotifier = function () { function getBackgroundState() { var hw = getCanvasState(backgroundCanvas); - return { path: settings.currentBackground, width: hw.width, height: hw.height } + return { path: settings.currentBackground, width: hw.width, height: hw.height }; } function getMapEdgeState() { @@ -63,20 +58,18 @@ var serverNotifier = function () { function getForegroundState() { var hw = getCanvasState(foregroundCanvas); - return { path: settings.currentMap, width: hw.width, height: hw.height, translate: { x: foregroundCanvas.data_transform_x || 0, y: foregroundCanvas.data_transform_y || 0 } } + return { path: settings.currentMap, width: hw.width, height: hw.height, translate: { x: foregroundCanvas.data_transform_x || 0, y: foregroundCanvas.data_transform_y || 0 } }; } - function getOverlayState() { var hw = getCanvasState(overlayCanvas); - return { path: settings.currentOverlay, width: hw.width, height: hw.height } + return { path: settings.currentOverlay, width: hw.width, height: hw.height }; } function getCanvasState(canvas) { return { height: parseFloat(canvas.style.height), width: parseFloat(canvas.style.width) }; } - async function serverTokensChanged() { var tokens = await getTokensForExport(); ipcRenderer.send("maptool-server-event", { event: "tokens", data: tokens }); @@ -90,24 +83,21 @@ var serverNotifier = function () { return effectArr; } - async function getTokensForExport(includeHidden) { var tokens = []; for (var i = 0; i < pawns.monsters.length; i++) { - if (!includeHidden && pawns.monsters[i][0].client_hidden) - continue; - tokens.push(await saveManager.exportPawn(pawns.monsters[i])) + if (!includeHidden && pawns.monsters[i][0].client_hidden) continue; + tokens.push(await saveManager.exportPawn(pawns.monsters[i])); } for (var i = 0; i < pawns.players.length; i++) { - if (!includeHidden && pawns.players[i][0].client_hidden) - continue; - tokens.push(await saveManager.exportPawn(pawns.players[i], includeHidden)) + if (!includeHidden && pawns.players[i][0].client_hidden) continue; + tokens.push(await saveManager.exportPawn(pawns.players[i], includeHidden)); } + console.log(tokens); return tokens; } - function notifyServer(eventName, data) { ipcRenderer.send("maptool-server-event", { event: eventName, data: data }); } @@ -119,12 +109,10 @@ var serverNotifier = function () { delete exportList[i].condition_background_location; } return exportList; - } async function mobTokensChanged(mobElement) { - notifyServer("mob-tokens-set", await saveManager.exportMobTokens(mobElement)) - + notifyServer("mob-tokens-set", await saveManager.exportMobTokens(mobElement)); } function serverIsRunning() { @@ -139,13 +127,14 @@ var serverNotifier = function () { getForegroundState: getForegroundState, getTokensForExport: getTokensForExport, getBackgroundState: getBackgroundState, - getMapEdgeState, getMapEdgeState, + getMapEdgeState, + getMapEdgeState, getOverlayState: getOverlayState, serverTokensChanged: serverTokensChanged, mobTokensChanged: mobTokensChanged, isServer: isServer, getSegments: getSegments, getEffectsForExport: getEffectsForExport, - timeouts: timeouts - } -}(); + timeouts: timeouts, + }; +})(); diff --git a/app/mappingTool/tokenDialog.js b/app/mappingTool/tokenDialog.js index d5ac19b..1e3aaa0 100644 --- a/app/mappingTool/tokenDialog.js +++ b/app/mappingTool/tokenDialog.js @@ -164,6 +164,12 @@ class TokenDialog { var cls = this; this.onPlacementInfoChanged(); sidebarManager.showInSideBar(this.dialog, () => { + this.dialog.classList.add("hidden"); + pauseAlternativeKeyboardMoveMap = false; + resetGridLayer(); + gridLayer.style.cursor = "auto"; + if (this.stopTooltip) this.stopTooltip(); + previewPlacementManager.clear(); document.body.appendChild(cls.dialog); }); @@ -206,13 +212,7 @@ class TokenDialog { } close() { - this.dialog.classList.add("hidden"); sidebarManager.close(); - pauseAlternativeKeyboardMoveMap = false; - resetGridLayer(); - gridLayer.style.cursor = "auto"; - if (this.stopTooltip) this.stopTooltip(); - previewPlacementManager.clear(); } async addPawnHandler(e) { diff --git a/app/server/server.js b/app/server/server.js index 147ff6a..24287df 100644 --- a/app/server/server.js +++ b/app/server/server.js @@ -382,7 +382,7 @@ function sendMaptoolState(maptoolState) { sendBatched(peer.connection, "map_edge", dataObject.mapEdge?.data, { format: dataObject.mapEdge?.format, }); - console.log(dataObject.background); + sendBatched(peer.connection, "background", dataObject.background?.data, { width: maptoolState.background?.width, height: maptoolState.background?.height, diff --git a/docs/client.html b/docs/client.html index 4e66be8..dcd48f1 100644 --- a/docs/client.html +++ b/docs/client.html @@ -1,173 +1,190 @@ Virtual tabletop | Dungeoneer - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - -