Cazka / diepAPI

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

entityManager.entities doesn't hold the entities from the current frame, but the frame before. #50

Closed Cazka closed 1 year ago

Cazka commented 1 year ago

This is an issue, which I discovered, when I had a new idea for a script, which displays the discord pfp of your friends on their tank body.

Here is a demo that shows the issue

https://user-images.githubusercontent.com/30176357/194759199-cba5f476-d212-4173-a8be-94f65263ee63.mp4

First i thought, that the diepAPI.apis.scaling.toCanvasPos() is not perfect https://github.com/Cazka/diepAPI/issues/49

But after some testing i found out that entityManager.entities doesn't store the information of the entities from the current frame.

https://github.com/Cazka/diepAPI/blob/a6900e25909a9107228d741e20b54b3ffd12339b/src/extensions/entity_manager.ts#L20-L23

The entities from the current frame are stored in #entities and are later in the next frame copied over to #entitiesUpdated.

https://github.com/Cazka/diepAPI/blob/a6900e25909a9107228d741e20b54b3ffd12339b/src/extensions/entity_manager.ts#L38-L40

The solution is to remove #entitiesUpdated and only store entity information in #entities. There also needs to be found a solution for the game.on('frame') listener to be called after all other listeners have been triggered.