WIP
This commit is contained in:
parent
34ac200437
commit
39b0160064
136 changed files with 7144 additions and 1965 deletions
40
src/game-loop/render-input-cache.ts
Normal file
40
src/game-loop/render-input-cache.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { activeVibe } from '../settings';
|
||||
import { hexToRgb } from '../vibes';
|
||||
import { RenderInputs } from './game-loop-types';
|
||||
|
||||
export class RenderInputCache {
|
||||
private cachedVibeId: string | null = null;
|
||||
private cachedRenderInputs?: RenderInputs;
|
||||
private previousAccentColor = '';
|
||||
|
||||
public invalidate(): void {
|
||||
this.cachedVibeId = null;
|
||||
this.cachedRenderInputs = undefined;
|
||||
}
|
||||
|
||||
public get(): RenderInputs {
|
||||
if (this.cachedRenderInputs && this.cachedVibeId === activeVibe.id) {
|
||||
return this.cachedRenderInputs;
|
||||
}
|
||||
|
||||
this.cachedVibeId = activeVibe.id;
|
||||
this.cachedRenderInputs = {
|
||||
channelColors: activeVibe.colors.map(hexToRgb),
|
||||
backgroundColor: hexToRgb(activeVibe.backgroundColor),
|
||||
};
|
||||
|
||||
return this.cachedRenderInputs;
|
||||
}
|
||||
|
||||
public updateAccentColor(color: [number, number, number]): void {
|
||||
const accentColor = `rgb(${Math.round(color[0] * 255)},${Math.round(
|
||||
color[1] * 255
|
||||
)},${Math.round(color[2] * 255)})`;
|
||||
if (this.previousAccentColor === accentColor) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.previousAccentColor = accentColor;
|
||||
document.documentElement.style.setProperty('--accent-color', accentColor);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue