beyond-all-reason / bar-lobby

BAR Lobby Client
https://beyond-all-reason.github.io/bar-lobby/
MIT License
32 stars 28 forks source link

BattlePreview has fatal error due to not recognizing scored battles as abstract battles. #245

Open JasonReed-2 opened 10 months ago

JasonReed-2 commented 10 months ago

Issue When clicking on "Multiplayer" tab, I receive this error: image

Impact Users can't open the custom battle list browser. Also: letting this error sit with the electron app open will cause a massive slowdown as it eats up all the computers memory :(

Investigation Looking at this code: image

When debugged: props.battle.contenders is actually ComputedRefImpl object. To access the value, it should be "props.battle.contenders.value".

So the code is recognizing the battle as a Replay when it actually should recognized as an AbstractBattle and enter the if block where the ComputedRefImpl objects are handled appropriately.

So why is the battle being treated as a replay and not a battle?

Looking in type-checkers.ts: image

So we only recognize a battle as an abstract battle if instanceof abstract battle. Explanation of instanceof from stackoverflow: https://stackoverflow.com/questions/2449254/what-is-the-instanceof-operator-in-javascript

tldr: instanceof checks that the object has the constructor for the given class.

So that means that an object must be instantiated using the constructor of the class [or subclass] to be recognized by instanceof.

Looking at custom.vue in scoreBattle function: image

So while typescript recognizes this as a scoredSpadsBattle: instanceof will not because the object wasn't created used the constructor of a subclass of AbstractBattle.

Solution Fold the scored battles data into the SpadsBattle class. Have the custom.vue component interact with the scored battles data that is stored within the SpadsBattle.