From cb47753b91abc89f2b34a844b9348f7bc57038f0 Mon Sep 17 00:00:00 2001 From: Cazka Date: Sun, 13 Mar 2022 16:03:21 +0100 Subject: [PATCH] add support for solid background command --- src/arena_scaling.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/arena_scaling.ts b/src/arena_scaling.ts index 781a992..022de34 100644 --- a/src/arena_scaling.ts +++ b/src/arena_scaling.ts @@ -1,15 +1,30 @@ import { Vector } from './vector'; import { CanvasKit } from './canvas_kit'; import { camera } from './camera'; +import { game } from './game'; class ArenaScaling { #scalingFactor = 1; + #drawSolidBackground = false; constructor() { - CanvasKit.hook('stroke', (target, thisArg, args) => { - if (thisArg.fillStyle === '#cdcdcd' && thisArg.globalAlpha !== 0) { - this.#scalingFactor = thisArg.globalAlpha * 10; + game.once('ready', () => { + window.input.set_convar = new Proxy(window.input.set_convar, { + apply: (target, thisArg, args) => { + if (args[0] === 'ren_solid_background') this.#drawSolidBackground = args[1]; + else Reflect.apply(target, thisArg, args); + }, + }); + }); + + CanvasKit.replace('stroke', (target, thisArg, args) => { + if (thisArg.fillStyle !== '#cdcdcd' || thisArg.globalAlpha === 0) { + return Reflect.apply(target, thisArg, args); } + + this.#scalingFactor = thisArg.globalAlpha * 10; + + if (!this.#drawSolidBackground) return Reflect.apply(target, thisArg, args); }); }