Removed slider image cache since it was buggy

This commit is contained in:
nise.moe 2024-03-03 16:59:19 +01:00
parent 4bb7f0d133
commit 3ddddc168b
4 changed files with 38 additions and 58 deletions

View File

@ -37,7 +37,6 @@
"sonner": "^1.3.1", "sonner": "^1.3.1",
"tailwind-merge": "^2.0.0", "tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"ts-md5": "^1.3.1",
"zustand": "^4.4.1" "zustand": "^4.4.1"
}, },
"devDependencies": { "devDependencies": {
@ -3646,14 +3645,6 @@
"resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz",
"integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==" "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA=="
}, },
"node_modules/ts-md5": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/ts-md5/-/ts-md5-1.3.1.tgz",
"integrity": "sha512-DiwiXfwvcTeZ5wCE0z+2A9EseZsztaiZtGrtSaY5JOD7ekPnR/GoIVD5gXZAlK9Na9Kvpo9Waz5rW64WKAWApg==",
"engines": {
"node": ">=12"
}
},
"node_modules/tslib": { "node_modules/tslib": {
"version": "2.6.2", "version": "2.6.2",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",

View File

@ -46,7 +46,6 @@
"sonner": "^1.3.1", "sonner": "^1.3.1",
"tailwind-merge": "^2.0.0", "tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"ts-md5": "^1.3.1",
"zustand": "^4.4.1" "zustand": "^4.4.1"
} }
} }

View File

@ -1,10 +1,9 @@
import { Vector2 } from "osu-classes"; import { Vector2 } from "osu-classes";
import { Md5 } from "ts-md5";
import p5 from "p5"; import p5 from "p5";
import { loadImageAsync } from "@/utils"; import { loadImageAsync } from "@/utils";
export class Drawer { export class Drawer {
private static imageCache: Record<string, p5.Graphics> = {};
static images = { static images = {
cursor: undefined as any as p5.Image, cursor: undefined as any as p5.Image,
cursortrail: undefined as any as p5.Image, cursortrail: undefined as any as p5.Image,
@ -129,51 +128,47 @@ export class Drawer {
static drawSliderBody(origin: Vector2, path: Vector2[], radius: number) { static drawSliderBody(origin: Vector2, path: Vector2[], radius: number) {
Drawer.p.push(); Drawer.p.push();
const cacheKey = Md5.hashStr(JSON.stringify(path) + JSON.stringify(radius)); const g = Drawer.p.createGraphics(512 * 4, 384 * 4);
if (!this.imageCache[cacheKey]) { g.scale(2);
const g = Drawer.p.createGraphics(512 * 4, 384 * 4); g.translate(512 - 256, 384 - 192);
g.scale(2); //@ts-ignore
g.translate(512 - 256, 384 - 192); const ctx = g.drawingContext;
//@ts-ignore ctx.lineCap = "round";
const ctx = g.drawingContext; ctx.lineJoin = "round";
ctx.lineCap = "round"; g.translate(origin.x, origin.y);
ctx.lineJoin = "round"; g.noFill();
g.translate(origin.x, origin.y);
g.noFill();
g.strokeWeight(radius * 2 - 10); g.strokeWeight(radius * 2 - 10);
g.stroke(255); g.stroke(255);
g.beginShape(); g.beginShape();
for (const node of path) { for (const node of path) {
g.vertex(node.x, node.y); g.vertex(node.x, node.y);
}
g.endShape();
g.strokeWeight(radius * 2 - 17);
g.stroke(10);
g.beginShape();
for (const node of path) {
g.vertex(node.x, node.y);
}
g.endShape();
for (let i = 0; i < radius * 2 - 17; i += 2) {
g.strokeWeight(radius * 2 - 17 - i);
g.stroke(Math.round((i / (radius * 2 - 17)) * 45));
g.beginShape();
for (const node of path) {
g.vertex(node.x, node.y);
}
g.endShape();
}
this.imageCache[cacheKey] = g;
} }
g.endShape();
g.strokeWeight(radius * 2 - 17);
g.stroke(10);
g.beginShape();
for (const node of path) {
g.vertex(node.x, node.y);
}
g.endShape();
for (let i = 0; i < radius * 2 - 17; i += 2) {
g.strokeWeight(radius * 2 - 17 - i);
g.stroke(Math.round((i / (radius * 2 - 17)) * 45));
g.beginShape();
for (const node of path) {
g.vertex(node.x, node.y);
}
g.endShape();
}
Drawer.p.imageMode(Drawer.p.CORNER); Drawer.p.imageMode(Drawer.p.CORNER);
Drawer.p.image(this.imageCache[cacheKey], -256, -192, 512 * 2, 384 * 2); Drawer.p.image(g, -256, -192, 512 * 2, 384 * 2);
Drawer.p.pop(); Drawer.p.pop();
} }

View File

@ -1899,11 +1899,6 @@ ts-interface-checker@^0.1.9:
resolved "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz" resolved "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz"
integrity sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA== integrity sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==
ts-md5@^1.3.1:
version "1.3.1"
resolved "https://registry.npmjs.org/ts-md5/-/ts-md5-1.3.1.tgz"
integrity sha512-DiwiXfwvcTeZ5wCE0z+2A9EseZsztaiZtGrtSaY5JOD7ekPnR/GoIVD5gXZAlK9Na9Kvpo9Waz5rW64WKAWApg==
tslib@^2.0.0, tslib@^2.1.0, tslib@^2.4.0: tslib@^2.0.0, tslib@^2.1.0, tslib@^2.4.0:
version "2.6.2" version "2.6.2"
resolved "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz" resolved "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz"