Skip to content

Commit

Permalink
chore: use window size & refresh counter list
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Oct 26, 2024
1 parent be7dabc commit 7c6d9cf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
9 changes: 4 additions & 5 deletions packages/server/assets/ingame.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ body.-editing {
background-size: cover;
pointer-events: none;
opacity: 0;
translate: -5px -5px;
z-index: 10000;
transition: opacity 0.5s ease;
}

main.main {
width: var(--w);
height: var(--h);
width: 100vw;
height: 100vh;
z-index: 1;

&::before {
Expand All @@ -118,8 +117,8 @@ main.main {
color: #46515e;
top: 0;
left: 0;
width: var(--w);
height: var(--h);
width: 100vw;
height: 100vh;
padding: 3em;
opacity: 0;
background: hsl(from #2a323b h s l / 75%);
Expand Down
32 changes: 6 additions & 26 deletions packages/server/assets/ingame.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ const app = createApp({


window.addEventListener('resize', (event) => {
max_width.value = max_width.value;
max_height.value = max_height.value;
max_width.value = window.innerWidth;
max_height.value = window.innerHeight;
});


Expand Down Expand Up @@ -704,6 +704,7 @@ const app = createApp({
};

socket.sendCommand('getSettings', encodeURI('__ingame__'));
socket.sendCommand('getCounters', encodeURI('__ingame__'));
socket.commands((data) => {
try {

Expand All @@ -713,36 +714,15 @@ const app = createApp({
overlays.value = message.overlays;
};
};
} catch (error) {
console.log(error);
};
});


socket.api_v2((data) => {
try {
if (data.settings.resolution.fullscreen) {
if (max_width.value != data.settings.resolution.widthFullscreen)
max_width.value = data.settings.resolution.widthFullscreen;
if (max_height.value != data.settings.resolution.heightFullscreen)
max_height.value = data.settings.resolution.heightFullscreen;

return;
if (command == 'getCounters' && Array.isArray(message)) {
available_overlays.value = message;
}

if (max_width.value != data.settings.resolution.width)
max_width.value = data.settings.resolution.width;
if (max_height.value != data.settings.resolution.height)
max_height.value = data.settings.resolution.height;
} catch (error) {
console.log(error);
};
}, [
{
field: 'settings',
keys: ['resolution']
}
]);
});


return {
Expand Down
11 changes: 11 additions & 0 deletions packages/server/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export default function buildBaseApi(server: Server) {
);
fs.unlinkSync(tempPath);

server.WS_COMMANDS.socket.emit(
'message',
`getCounters:__ingame__`
);

sendJson(res, {
status: 'Finished',
path: result
Expand Down Expand Up @@ -219,6 +224,12 @@ export default function buildBaseApi(server: Server) {
);

fs.rmSync(folderPath, { recursive: true, force: true });

server.WS_COMMANDS.socket.emit(
'message',
`getCounters:__ingame__`
);

return sendJson(res, {
status: 'deleted'
});
Expand Down
16 changes: 16 additions & 0 deletions packages/server/utils/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JsonSafeParse, wLogger } from '@tosu/common';

import { getLocalCounters } from './counters';
import { parseCounterSettings } from './parseSettings';
import { ModifiedWebsocket } from './socket';

Expand All @@ -18,6 +19,21 @@ export function handleSocketCommands(data: string, socket: ModifiedWebsocket) {
const requestedFrom = decodeURI(socket.query?.l || '');
const requestedName = decodeURI(payload || '');
switch (command) {
case 'getCounters': {
if (
requestedFrom !== '__ingame__' ||
requestedName !== requestedFrom
) {
message = {
error: 'Wrong overlay'
};
break;
}

message = getLocalCounters();
break;
}

case 'getSettings': {
if (requestedName !== requestedFrom) {
message = {
Expand Down

0 comments on commit 7c6d9cf

Please sign in to comment.