Skip to content

Commit

Permalink
feat: bump version, fix that gameplayData can't be updated, add dumb …
Browse files Browse the repository at this point in the history
…page for static, add configuration file creation
  • Loading branch information
KotRikD committed Apr 16, 2023
1 parent 6139d7f commit 3734b39
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
tsosu.env
dist/
node_modules
yarn-error.log
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Mikhail Babynichev",
"name": "osumemory-ts",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/index.js",
"bin": "dist/index.js",
"license": "GPL-3.0",
Expand Down
12 changes: 7 additions & 5 deletions src/Instances/Osu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class OsuInstance {
}

try {
for (const baseKey of Object.keys(SCAN_PATTERNS)) {
for (const baseKey in SCAN_PATTERNS) {
basesRepo.setBase(
baseKey as never,
this.process.scanSync(SCAN_PATTERNS[baseKey], true)
Expand Down Expand Up @@ -173,7 +173,7 @@ export class OsuInstance {
]);

// osu! calculates audioTrack length a little bit after updating menuData, sooo.. lets this thing run regardless of menuData updating
menuData.updateMP3Length();
await menuData.updateMP3Length();

if (!settings.gameFolder) {
settings.setGameFolder(path.join(this.path, '../'));
Expand Down Expand Up @@ -201,7 +201,7 @@ export class OsuInstance {
break;
case 2:
if (allTimesData.PlayTime < 150) {
return;
continue;
}
await gamePlayData.updateState();
if (retriesTemp > gamePlayData.Retries) {
Expand All @@ -216,7 +216,9 @@ export class OsuInstance {
await resultsScreenData.updateState();
break;
case 22:
this.isTourneyManager = true;
if (!this.isTourneyManager) {
this.isTourneyManager = true;
}
await tourneyManagerData.updateState();
break;
default:
Expand All @@ -243,7 +245,7 @@ export class OsuInstance {
switch (allTimesData.Status) {
case 2:
if (allTimesData.PlayTime < 150) {
return;
continue;
}

await gamePlayData.updateKeyOverlay();
Expand Down
8 changes: 6 additions & 2 deletions src/Utils/calculateGrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export const calculateGrade = (
}

return 'D';
} else if (mode === 2) {
}

if (mode === 2) {
if (acc == 100) {
return SSGrade;
}
Expand All @@ -54,7 +56,9 @@ export const calculateGrade = (
}

return 'D';
} else if (mode === 3) {
}

if (mode === 3) {
if (acc == 100) {
return SSGrade;
}
Expand Down
18 changes: 17 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import * as dotenv from 'dotenv';
import fs from 'fs';

dotenv.config();
const curDir = fs.readdirSync('./');
if (!curDir.includes('tsosu.env')) {
fs.writeFileSync(
'./tsosu.env',
`DEBUG_LOG=false
CALCULATE_PP=true
ENABLE_KEY_OVERLAY=true
WS_SEND_INTERVAL=150
POLL_RATE=150
KEYOVERLAY_POLL_RATE=150`
);
}

dotenv.config({
path: 'tsosu.env'
});

export const config = {
debugLogging: (process.env.DEBUG_LOG || '') === 'true',
Expand Down
33 changes: 33 additions & 0 deletions src/constants/overlaysStatic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export const OVERLAYS_STATIC = `<html>
<head>
<title>ts osu overlays list</title>
</head>
<body>
<ul id="overlays-list">
</ul>
</body>
<script lang="text/javascript" defer>
(async () => {
const overlaysList = document.getElementById("overlays-list")
try {
const res = await fetch("/api/getOverlays")
const overlayList = await res.json()
overlayList.innerHTML = ''
for (const overlay of overlayList) {
const newLi = document.createElement("li")
newLi.innerHTML = \`<a href="/\${overlay}/index.html">\${overlay}</a>\`
overlaysList.appendChild(newLi)
}
console.log(overlayList);
} catch (e) {
console.error(e)
overlaysList.innerHTML = \`
<li>failed to get overlays</li>
\`
}
})();
</script>
</html>`;
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Router from '@koa/router';
import fs from 'fs';
import Koa from 'koa';
import send from 'koa-send';
import serve from 'koa-static';
Expand All @@ -8,6 +9,7 @@ import { InstancesManager } from './Instances/InstancesManager';
import { OsuInstance } from './Instances/Osu';
import { sleep } from './Utils/sleep';
import { config } from './config';
import { OVERLAYS_STATIC } from './constants/overlaysStatic';
import { wLogger } from './logger';

interface CustomContext extends Koa.Context {
Expand Down Expand Up @@ -50,8 +52,8 @@ interface CustomContext extends Koa.Context {
router.get('/(.*)', async (ctx, next) => {
const staticPath = ctx.request.path.replace(/^\/static/g, '');
if (staticPath === '/') {
ctx.body =
'please enter correct static path, you can find needed folder in your static folder';
ctx.type = 'html';
ctx.body = OVERLAYS_STATIC;
return;
}

Expand Down Expand Up @@ -92,6 +94,11 @@ interface CustomContext extends Koa.Context {
).getState(ctx.instancesManager);
});

router.get('/api/getOverlays', async (ctx) => {
ctx.body = await fs.promises.readdir('./static');
return;
});

const wsRouter = new Router();
wsRouter.use(async (ctx, next) => {
ctx.instancesManager = instancesManager;
Expand Down

0 comments on commit 3734b39

Please sign in to comment.