add ability for admin to enqueue updates to the map; v0.2.6

This commit is contained in:
Iris Lightshard 2023-10-29 00:04:22 -06:00
parent 4435d1e130
commit 140e775d66
Signed by: nilix
GPG key ID: F54E0D40695271D4
5 changed files with 36 additions and 16 deletions

View file

@ -28,6 +28,7 @@ async function loadAdmin(name, pass) {
const table = await tableData.json() const table = await tableData.json()
mgmtHTML = `<a href='#' onclick='getTables();return false;'>&larr; table list</a><br>\n` + mgmtHTML = `<a href='#' onclick='getTables();return false;'>&larr; table list</a><br>\n` +
`<button id='q_toggle' onclick='toggleQ()'>Enqueue Updates</button>` +
`<textarea id='aux_msg_input'>${table.auxMsg}</textarea><br><button onclick='publishAuxMsg()'>Set Status</button>\n` + `<textarea id='aux_msg_input'>${table.auxMsg}</textarea><br><button onclick='publishAuxMsg()'>Set Status</button>\n` +
`<button onclick='destroyTable()'>Destroy Table</button><br/>\n` + `<button onclick='destroyTable()'>Destroy Table</button><br/>\n` +
`<input id='map_img_upload' type='file'/><button onclick='uploadImg("map")'>Upload Map</button><br/>\n` `<input id='map_img_upload' type='file'/><button onclick='uploadImg("map")'>Upload Map</button><br/>\n`
@ -43,6 +44,7 @@ async function loadAdmin(name, pass) {
mgmtHTML += "<label>Maps couldn't be retrieved</label>"; mgmtHTML += "<label>Maps couldn't be retrieved</label>";
} }
$("table_management").innerHTML = mgmtHTML; $("table_management").innerHTML = mgmtHTML;
q = false;
let spriteListHTML = `<input id='token_img_upload' type='file'/><button onclick='uploadImg("token")'>Upload Sprite</button><br/>`; let spriteListHTML = `<input id='token_img_upload' type='file'/><button onclick='uploadImg("token")'>Upload Sprite</button><br/>`;
@ -69,6 +71,18 @@ async function loadAdmin(name, pass) {
} }
} }
function toggleQ() {
const toggleBtn = $('q_toggle');
q = !q;
if (!q) {
emptyMsgQ();
toggleBtn.innerText = "Enqueue Updates"
} else {
toggleBtn.innerText = "Send Updates"
}
}
function fillSpriteDropdown(sprites) { function fillSpriteDropdown(sprites) {
const dropdown = $("sprite_dropdown"); const dropdown = $("sprite_dropdown");
let options = "<option value=''>select</option>"; let options = "<option value=''>select</option>";
@ -90,7 +104,6 @@ function previewSprite(source) {
break; break;
default: default:
scaleSpritePreview(source); scaleSpritePreview(source);
console.log("default case");
} }
} }
} }
@ -310,7 +323,7 @@ function renderTokenMasterList() {
function publishAuxMsg() { function publishAuxMsg() {
const txtArea = $("aux_msg_input"); const txtArea = $("aux_msg_input");
if (txtArea) { if (txtArea) {
publish({auxMsg: txtArea.value, auth: adminToken.access_token}); publish({auxMsg: txtArea.value || " ", auth: adminToken.access_token});
} }
} }

View file

@ -146,14 +146,14 @@
</form> </form>
</details> </details>
<div id="lag" style="display:none;">lag...</div> <div id="lag" style="display:none;">lag...</div>
<div class="ui_win" id="felt_info"><a href="https://hacklab.nilfm.cc/felt">felt v0.2.5</a> (<a href="https://hacklab.nilfm.cc/felt/raw/main/LICENSE">license</a>) | built with <a href="https://leafletjs.com">leaflet</a> (<a href="https://hacklab.nilfm.cc/felt/raw/main/LEAFLET_LICENSE">license</a>) </div> <div class="ui_win" id="felt_info"><a href="https://hacklab.nilfm.cc/felt">felt v0.2.6</a> (<a href="https://hacklab.nilfm.cc/felt/raw/main/LICENSE">license</a>) | built with <a href="https://leafletjs.com">leaflet</a> (<a href="https://hacklab.nilfm.cc/felt/raw/main/LEAFLET_LICENSE">license</a>) </div>
</nav> </nav>
</body> </body>
<script>L_DISABLE_3D = window.location.hash.toLowerCase() === "#no3d";</script> <script>L_DISABLE_3D = window.location.hash.toLowerCase() === "#no3d";</script>
<script src="./leaflet.js?v=1.9.4" type="text/javascript"></script> <script src="./leaflet.js?v=1.9.4" type="text/javascript"></script>
<script src="./util.js?v=0.2.5" type="text/javascript"></script> <script src="./util.js?v=0.2.6" type="text/javascript"></script>
<script src="./map.js?v=0.2.5" type="text/javascript"></script> <script src="./map.js?v=0.2.6" type="text/javascript"></script>
<script src="./socket.js?v=0.2.5" type="text/javascript"></script> <script src="./socket.js?v=0.2.6" type="text/javascript"></script>
<script src="./dice.js?v=0.2.5" type="text/javascript"></script> <script src="./dice.js?v=0.2.6" type="text/javascript"></script>
<script src="./admin.js?v=0.2.5" type="text/javascript"></script> <script src="./admin.js?v=0.2.6" type="text/javascript"></script>
</html> </html>

View file

@ -6,6 +6,7 @@ const tableKey = {
let conn = null; let conn = null;
let offline = false; let offline = false;
const msgQ = []; const msgQ = [];
let q = false;
function dial() { function dial() {
// get tableKey from UI // get tableKey from UI
@ -58,6 +59,8 @@ function dial() {
mapImg.removeFrom(map); mapImg.removeFrom(map);
mapImg = null; mapImg = null;
} }
msgQ = [];
} }
}); });
@ -73,10 +76,7 @@ function dial() {
lagDiv.style.display = "none"; lagDiv.style.display = "none";
} }
while (msgQ.some(m=>m)) { emptyMsgQ();
publish(msgQ[0]);
msgQ.shift();
}
closeErr(); closeErr();
tabletop = $("tabletop"); tabletop = $("tabletop");
@ -117,8 +117,15 @@ function dial() {
} }
} }
function emptyMsgQ() {
while (msgQ.some(m=>m)) {
publish(msgQ[0]);
msgQ.shift();
}
}
async function publish(msg) { async function publish(msg) {
if (offline) { if (offline || q) {
msgQ.push(msg); msgQ.push(msg);
} else { } else {
@ -202,7 +209,7 @@ function logDice(dice) {
function setAuxMsg(msg) { function setAuxMsg(msg) {
const auxDiv = $("aux"); const auxDiv = $("aux");
if (auxDiv) { if (auxDiv) {
auxDiv.innerText = msg; auxDiv.innerText = msg || " ";
} }
} }

View file

@ -23,5 +23,5 @@
{{end}} {{end}}
</main> </main>
</body> </body>
<script src="/table/util.js?v=0.2.5" type="text/javascript"></script> <script src="/table/util.js?v=0.2.6" type="text/javascript"></script>
</html> </html>

View file

@ -19,5 +19,5 @@
{{end}} {{end}}
</main> </main>
</body> </body>
<script src="/table/util.js?v=0.2.5" type="text/javascript"></script> <script src="/table/util.js?v=0.2.6" type="text/javascript"></script>
</html> </html>