HomeWildfire Games

Refactor diplomacy dialog to use object orientation paradigm using the class…
AuditedrP23065

Description

Refactor diplomacy dialog to use object orientation paradigm using the class keyword, refs #5387.

Includes dilomacy colors, tribute buttons, spy request buttons, attack request buttons, minimap panel, idle worker button, ceasefire counter.
Differential Revision: https://code.wildfiregames.com/D2365

Use hotkey release event from rP19028 to remove input.js state and evil global nested closure hackery from rP13201, refs #1839, #3194.
Fixes masstribute selecitonchange issue subject of D1191.

Event Timeline

Stan raised a concern with this commit.EditedOct 26 2019, 12:09 PM
Stan added a subscriber: Stan.

If you start a game on Danubius in Atlas you get this

WARNING: JavaScript warning: gui/common/gamedescription.js line 326 reference to undefined property g_GameAttributes.settings.Ceasefire

WARNING: JavaScript warning: gui/common/l10n.js line 83 Script value conversion check failed: v.isNumber() (got type undefined)

Guess it needs something similar than rP23071

This commit now has outstanding concerns.Oct 26 2019, 12:09 PM
In rP23065#39126, @Stan wrote:

If you start a game on Danubius in Atlas you get this

WARNING: JavaScript warning: gui/common/gamedescription.js line 326 reference to undefined property g_GameAttributes.settings.Ceasefire

WARNING: JavaScript warning: gui/common/l10n.js line 83 Script value conversion check failed: v.isNumber() (got type undefined)

Guess it needs something similar than rP23071

That warning doesn't come from the diplomacy dialog rP23065 but from the objectives dialog rP23076.

The error does occur on all random maps generated in atlas when starting the simulation but no skirmish maps loaded in atlas and starting the simulation.

Random maps do set g_GameAttributes.settings and few attributes of it, but not Ceasefire, that's why the atlas check in rP23076 and the one in rP23071 are insufficient, it needs a hard check for !Engine.IsAtlasRunning().

Catch 22 is that this might also be insufficient for autostarted games (was fixed for ceasefire but perhaps not for every property #4606).

That rabbithole further leads down to #4504 and #5075. The problem is that there are three mechanisms to setup g_GameAttributes and they all do something different when they should do the same.

elexis requested verification of this commit.Oct 27 2019, 2:40 PM

Thanks for the report

This commit now requires verification by auditors.Oct 27 2019, 2:40 PM
Stan accepted this commit.Nov 20 2019, 2:22 PM
All concerns with this commit have now been addressed.Nov 20 2019, 2:22 PM
Freagarach raised a concern with this commit.Apr 18 2020, 8:54 PM
Freagarach added a subscriber: Freagarach.
Freagarach added inline comments.
/ps/trunk/binaries/data/mods/public/gui/session/diplomacy/playercontrols/TributeButton.js
104

#5625.
PetraAI still expects all recources to be specified, although with "0" (diplomacyManager.js L 136).

This commit now has outstanding concerns.Apr 18 2020, 8:54 PM
Freagarach added inline comments.
/ps/trunk/binaries/data/mods/public/gui/session/diplomacy/playercontrols/TributeButton.js
104
elexis added inline comments.Apr 22 2020, 3:03 PM
/ps/trunk/binaries/data/mods/public/gui/session/diplomacy/playercontrols/TributeButton.js
104

(You are correct in flagging this as a concern here since I changed behavior of the GUI and didn't check the effects on simulation.
I would like to add that the GUI is only one way to send simulation orders, modders can change it, and one can send them using F9 -> Engine.PostNetworkCommand too)

Freagarach added inline comments.Apr 22 2020, 4:33 PM
/ps/trunk/binaries/data/mods/public/gui/session/diplomacy/playercontrols/TributeButton.js
104

The reason why I raised the concern was that it was to be fixed and I was too lazy to make the diff. But I only retained that lazyness for about five minutes, though. I have no interest in blaming or shaming, shizzle happens, especially on large rewrites. (Doesn't mean one should commit broken or inproperly tested code, though, just that things might slip through.)

Can you elaborate on the second statement, please? Is it you want to say that PetraAI should handle these cases more gracefully, as proposed in the diff? Or is there something else you want to convey here?

elexis added inline comments.Apr 22 2020, 5:50 PM
/ps/trunk/binaries/data/mods/public/gui/session/diplomacy/playercontrols/TributeButton.js
104

Just wanted to say that simulation code that processes client data should consider what malicious or defect clients could send (never trust the client, https://en.wikipedia.org/wiki/Defensive_programming). There have been various fixes for developer-debugging commands and GUI-trusting simulation commands that could result in players receiving indefinite resources (NaN batch train count), exiting the program for everyone (simulation command, see Commands.js history), colorizing buildings (Commands.js history), sending chat in the name of other players (Commands.js chat command), or ordering spies for enemy players (see spies commit). So I mention it so that it can be kept in mind whenever writing simulation processing commands. I don't know if there are oversights in the proposed patch, but sometimes one can construct some by reading the code and trying to invalidate its assumptions.

Freagarach accepted this commit.Apr 22 2020, 8:50 PM

My concern regarding PetraAI expecting resources amounts of 0 for all resources was fixed in rP23596.

All concerns with this commit have now been addressed.Apr 22 2020, 8:50 PM