Skip to content

Commit

Permalink
add filter to client
Browse files Browse the repository at this point in the history
  • Loading branch information
Durtur committed Jul 30, 2023
1 parent 6b40a7e commit 53ba76d
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 61 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build release

on: push

jobs:
release:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 14
- name: install dependencies
run: npm install
- name: publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run publish
1 change: 0 additions & 1 deletion app/js/combatLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,6 @@ var combatLoader = (function () {
var nameB = b.getAttribute("monster_original_name") || b.getElementsByClassName("name_field")[0].value;
if (nameA == nameB) return 0;
if (currentInitiativeActorName == nameA) return -1;

if (currentInitiativeActorName == nameB) return 1;
return 0;
};
Expand Down
2 changes: 1 addition & 1 deletion app/mappingTool.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
/>
</li>
<li>
<select title="Filter" id="filter_tool" onchange="setBackgroundFilter">
<select title="Filter" id="filter_tool">
<option value="none" selected>No filter</option>
<option value="url(#night-mode)">Night</option>
<option value="url(#winter-mode)">Winter</option>
Expand Down
32 changes: 23 additions & 9 deletions app/mappingTool/map.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,11 @@ function loadSettings() {
effectFilePath = defaultEffectPath;

if (!settings.enableGrid) settings.snapToGrid = false;
if (!settings.applyDarkvisionFilter) {
setBackgroundFilter();
} else {
if (fovLighting.viewerHasDarkvision()) {
setBackgroundFilter();
}
}

var filterValue = settings.currentFilter ? settings.currentFilter : 0;
var filterDd = document.getElementById("filter_tool");
filterDd.selectedIndex = parseInt(filterValue);
setBackgroundFilter();
onBackgroundFilterSelected();
if (settings.currentMap && !RUN_ARGS_MAP) {
setMapForeground(settings.currentMap, settings.gridSettings.mapSize);
}
Expand All @@ -80,6 +74,26 @@ function loadSettings() {
});
}

function onBackgroundFilterSelected() {
var filterDd = document.getElementById("filter_tool");
if (!filterDd) return;
filterValue = filterDd.options[filterDd.selectedIndex].value;
if (filterValue == "none") {
filtered = false;
filterDd.classList.remove("toggle_button_toggled");
} else {
filtered = true;
filterDd.classList.add("toggle_button_toggled");
}

if (fovLighting.viewerHasDarkvision() && settings.applyDarkvisionFilter && fovLighting.isDark()) {
filterValue = "grayscale(80%)";
}
serverNotifier.notifyServer("filter-set", { filter: filterValue });
settings.currentFilter = filterDd.selectedIndex;
map.setFilter(filterValue);
}

function saveSettings() {
console.log("Saving settings");
console.log(settings);
Expand Down Expand Up @@ -114,7 +128,7 @@ document.addEventListener("DOMContentLoaded", function () {
loadSettings();
updateHowlerListenerLocation();
window.api.messageWindow("mainWindow", "maptool-initialized");
serverNotifier.notifyServer("initialized", {})
serverNotifier.notifyServer("initialized", {});
serverNotifier.notifyServer("request-state", null);
serverNotifier.mapToolInit();
var bgSize = parseInt($("#foreground").css("background-size"));
Expand Down
2 changes: 1 addition & 1 deletion app/mappingTool/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Menu {

document.querySelector("#vision_button").onclick = showLightSourceTooltip;
document.querySelector("#conditions_button").onclick = showConditionsMenu;
document.getElementById("filter_tool").onchange = setBackgroundFilter;
document.getElementById("filter_tool").onchange = onBackgroundFilterSelected;
document.getElementById("foreground_size_slider").oninput = function (
event
) {
Expand Down
1 change: 1 addition & 0 deletions app/mappingTool/serverNotifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var serverNotifier = (function () {
conditions: await getConditionsForExport(),
roundTimer: roundTimer?.getState(),
initiative: initiative.getState(),
filter: map.getFilter(),
},
});
}
Expand Down
56 changes: 32 additions & 24 deletions app/server/server.api.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
// preload with contextIsolation enabled
const { contextBridge, ipcRenderer } = require('electron');
const { contextBridge, ipcRenderer } = require("electron");
const dataAccess = require("../js/dataaccess");
const AdminSoundManager = require("../js/soundManager");
const pathModule = require("path");
var soundManager;
dataAccess.getSettings(settings => {
dataAccess.getSettings((settings) => {
soundManager = new AdminSoundManager(pathModule);
soundManager.setSoundLibraryPath(settings.maptool.soundLibraryPath)
})
soundManager.setSoundLibraryPath(settings.maptool.soundLibraryPath);
});

const util = require("./server.util");
const ElementCreator = require("../js/lib/elementCreator");
const diceRoller = require("../js/diceroller")
const diceRoller = require("../js/diceroller");

const constants = dataAccess.getConstantsSync();


contextBridge.exposeInMainWorld('api', {
contextBridge.exposeInMainWorld("api", {
util,
constants,
diceRoller,
extname: (path) => pathModule.extname(path),
messageWindow: (windowName, eventName, args) => { return ipcRenderer.send('notify-window', { name: windowName, event: eventName, args: args }) },
})

messageWindow: (windowName, eventName, args) => {
return ipcRenderer.send("notify-window", { name: windowName, event: eventName, args: args });
},
});

contextBridge.exposeInMainWorld('subscribe', {
contextBridge.exposeInMainWorld("subscribe", {
on: (event, handler) => ipcRenderer.on(event, handler),
requestMapToolState: () => ipcRenderer.send('request-maptool-state'),
notifyServerState: (args) => { console.log(args); ipcRenderer.send('maptool-server-state', args) }
})

contextBridge.exposeInMainWorld('dataAccess', {
getSettings: (callback) => { dataAccess.getSettings(callback) },
getParty: (callback) => { dataAccess.getParty(callback) },
base64: async (path) => await dataAccess.base64(path)
})

contextBridge.exposeInMainWorld('soundManager', {
getAvailableSounds: async () => { return await soundManager.getAvailableSounds() }
})
requestMapToolState: () => ipcRenderer.send("request-maptool-state"),
notifyServerState: (args) => {
ipcRenderer.send("maptool-server-state", args);
},
});

contextBridge.exposeInMainWorld("dataAccess", {
getSettings: (callback) => {
dataAccess.getSettings(callback);
},
getParty: (callback) => {
dataAccess.getParty(callback);
},
base64: async (path) => await dataAccess.base64(path),
});

contextBridge.exposeInMainWorld("soundManager", {
getAvailableSounds: async () => {
return await soundManager.getAvailableSounds();
},
});
9 changes: 6 additions & 3 deletions app/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ function onConnected(conn) {
}
}

console.log(conn);

var peer = peers.find((x) => x.connectonId == conn.connectionId);
if (!peer) {
peers.add({
Expand All @@ -326,7 +324,6 @@ function onConnected(conn) {
return conn.send({ event: "ack" });
} else if (data.event == "ack") {
var peer = peers.find((x) => x.connectionId == conn.connectionId);
console.log(peers);
peer.timeout.ack();
return;
}
Expand Down Expand Up @@ -456,6 +453,12 @@ function sendMaptoolState(maptoolState) {
data: maptoolState.initiative,
});
setClientFog(clientFogUserSet ? clientFog : maptoolState.fog);
console.log(maptoolState.filter);
if (maptoolState.filter)
peer.connection.send({
event: "filter-set",
data: { filter: maptoolState.filter },
});
}
});
}
Expand Down
46 changes: 46 additions & 0 deletions docs/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,53 @@
</main>

<div id="chat-container" class="hidden"></div>
<svg>
<filter id="effect_fill_filter" x="0%" y="0%" width="100%" height="100%">
<feImage id="effect_fill_filter_img" />
</filter>
<filter id="night-mode">
<feColorMatrix
type="matrix"
values="
0.2 0 0 0 0
0 0.2 0 0 0
0 0 0.3 0 0.01
0 0 0 0 1"
/>
</filter>
<filter id="winter-mode">
<feColorMatrix
type="matrix"
values="
0.6 0 0 0 0
0 0.6 0 0 0
0.3 0.2 2.5 0 0
0 0 0 1.8 0"
/>
</filter>
<filter id="red_hue_filter">
<feColorMatrix
type="matrix"
values="0.78 0 0 0 0
0 0.04 0 0 0
0 0 0.04 0 0
0 0 0 1 0 "
/>
</filter>
<filter id="daylight">
<!--Blur effect-->

<!--Lighting effect-->
<feSpecularLighting result="spec2" specularConstant="1.4" specularExponent="13" lighting-color="rgba(255,255,0,0.01)">
<!--Light source effect-->
<feDistantLight azimuth="25" elevation="5" />
</feSpecularLighting>
<!--Composition of inputs-->
<feComposite in="SourceGraphic" in2="spec2" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" />
</filter>
</svg>
</body>

<script src="client/connectionConfig.js"></script>
<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>
<script src="client/hammer.min.js"></script>
Expand Down
3 changes: 3 additions & 0 deletions docs/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ function setState(message) {
chat.messageReceived(message.data);
pawnManager.talkBubble({ text: message.data.text, elementId: message.data.elementId });
break;
case "filter-set":
map.setFilter(message.data.filter);
break;
}
}

Expand Down
34 changes: 12 additions & 22 deletions docs/client/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,6 @@ function newPawnId() {
return `pawn${pawnId++}`;
}

function setBackgroundFilter() {
var filterDd = document.getElementById("filter_tool");
if (!filterDd) return;
filterValue = filterDd.options[filterDd.selectedIndex].value;
if (filterValue == "none") {
filtered = false;
filterDd.classList.remove("toggle_button_toggled");
} else {
filtered = true;
filterDd.classList.add("toggle_button_toggled");
}

if (fovLighting.viewerHasDarkvision() && settings.applyDarkvisionFilter && fovLighting.isDark()) {
filterValue = "grayscale(80%)";
}
document.querySelector("#map_layer_container").style.filter = filterValue;

settings.currentFilter = filterDd.selectedIndex;
saveSettings();
}

//Overriden in map.admin
function saveSettings() {}
function toggleSaveTimer() {}
Expand Down Expand Up @@ -1807,7 +1786,7 @@ function refreshFogOfWar(timestamp) {
function switchActiveViewer() {
fovLighting.toggleDarkvision();
refreshFogOfWar();
setBackgroundFilter();
if (serverNotifier.isServer()) onBackgroundFilterSelected();
}

/* #endregion */
Expand Down Expand Up @@ -2132,6 +2111,15 @@ const map = (function () {
});
}

function setFilter(filterValue) {
document.querySelector("#map_layer_container").style.filter = filterValue;
saveSettings();
}

function getFilter() {
return document.querySelector("#map_layer_container").style.filter;
}

return {
init: init,
moveMap,
Expand All @@ -2146,6 +2134,8 @@ const map = (function () {
updateObjectSize: updateObjectSize,
centerObjectOn: centerObjectOn,
moveObject: moveObject,
setFilter: setFilter,
getFilter: getFilter,
removeAllPawns: removeAllPawns,
removeAllEffects: removeAllEffects,
onkeydown: onkeydown,
Expand Down

0 comments on commit 53ba76d

Please sign in to comment.