Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Durtur committed Dec 30, 2022
1 parent 937f0ed commit ec1ed87
Show file tree
Hide file tree
Showing 19 changed files with 343 additions and 316 deletions.
1 change: 0 additions & 1 deletion app/js/dataaccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions app/js/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion app/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions app/mappingTool.html
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,13 @@ <h2 class="interactive_header">Sound</h2>
<script src="mappingTool/previewPlacing.js"></script>
<!-- <script src="mappingTool/map.js"></script> -->
<script src="../docs/client/map.js"></script>

<script src="mappingTool/mapscript.ipc.js"></script>
<script src="../docs/client/measurements.js"></script>

<script src="../docs/client/pawns.js"></script>
<script src="../docs/client/timer.js"></script>
<script src="../docs/client/lightning.js"></script>
<script src="mappingTool/map.admin.js"></script>
<script src="mappingTool/map.admin.js"></script>
<script src="mappingTool/spectrum.js"></script>
<script src="mappingTool/howler/howler.core.min.js"></script>
<script src="mappingTool/howler/howler.spatial.min.js"></script>
Expand Down
27 changes: 12 additions & 15 deletions app/mappingTool/map.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -701,17 +699,16 @@ 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]);
}
}
}
var arg = { dead: !revivePawn, elementId: pawnElement.id };
serverNotifier.notifyServer("monster-health-changed", arg);
pawnElement.setAttribute("data-state_changed", 1);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion app/mappingTool/map.css
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion app/mappingTool/mapscript.ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions app/mappingTool/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -95,7 +95,7 @@ class Menu {
(scale) => {
if (!scale) return;
selectedPawns.forEach((pawn) => {
map.setTokenScale(pawn, scale);
pawnManager.setScale(pawn, scale);
});
}
);
Expand Down
2 changes: 1 addition & 1 deletion app/mappingTool/previewPlacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const previewPlacementManager = (function () {
if (ts == dragPreviewTimestamp) {
return;
}

if (!previewPlacementElement) return;
dragPreviewTimestamp = ts;
e.preventDefault();
var elementHeight = parseFloat(previewPlacementElement.style.height);
Expand Down
9 changes: 4 additions & 5 deletions app/mappingTool/saveManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -319,7 +319,6 @@ class SaveManager {
bgPhotoBase64: base64,
pos: map.objectGridCoords(element),
darkVisionRadius: darkVisionRadius,
//attached_objects : element.attached_objects
};
}

Expand Down
63 changes: 26 additions & 37 deletions app/mappingTool/serverNotifier.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@


var serverNotifier = function () {
var serverNotifier = (function () {
var timeouts = {};

async function mapToolInit() {
Expand All @@ -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(),
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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 });
Expand All @@ -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 });
}
Expand All @@ -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() {
Expand All @@ -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,
};
})();
12 changes: 6 additions & 6 deletions app/mappingTool/tokenDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit ec1ed87

Please sign in to comment.