Cazka / diepAPI

An API for https://diep.io
MIT License
15 stars 8 forks source link

diepAPI.player.level has a bug #36

Closed gurumnyang closed 2 years ago

gurumnyang commented 2 years ago

diepAPI.player.level cannot detect level if tank type name contains a blank character.

[ /diepAPI/src/player.ts ]

        CanvasKit.hook('fillText', (target, thisArg, args) => {
            const text = args[0];
            const match = text.match(/^Lvl (\d+) (\w*)$/);   // problem!
            if (match == null) {
                return;
            }

            const newLevel = Number(match[1]);
            const newTank = match[2];

            // make sure to trigger events for all levels in between.
            while (newLevel > this.#level + 1) {
                super.emit('level', ++this.#level);
            }

            if (newLevel !== this.#level) super.emit('level', newLevel);
            if (newTank !== this.#tank) super.emit('tank', newTank);

            this.#level = newLevel;
            this.#tank = match[2];
        });

the way to fix the bug.

const match = text.match(/^Lvl (\d+) (\w*)$/); ( x ) const match = text.match(/^Lvl (\d+) (\w*\s?\w*)$/); ( o )

Cazka commented 2 years ago

Closed by #44