Page MenuHomeWildfire Games

Refactor Savegame page to use object-oriented style / classes
ClosedPublic

Authored by elexis on Sep 20 2019, 1:54 PM.

Details

Summary

The unification of the savegame and loadgame dialog in rP22923 / D2290
introduced the new SavegameWriter class, but didn't change everything to classes in that folder,
while having moved the former gui/common/functions_utility_loadsave.js without deuglifying it,
while leaving one unused function (getSavedGameData()) and one wrong reference saveGame()).

This patch rewrites everything to use the OOP style with the classes keyword.

Test Plan

Examine the syntactical marvel. Make sure that "everything works", that is:

  • Saving
  • Loading
  • Deleting the last game and ending up with the new last item being selected
  • First savegame selected when opening the load dialog
  • Nothing selected when opening the savegame dialog
  • Confirm and delete button disabled if nothing is selected, otherwise enabled
  • "invalidGame" being shown if nothing is selected, otherwise details presented

Notice that for this iteration of the patch, the "confirmButton" seems cleaner than splitting it into two conditionally visible buttons.
That might change when adding support to load savegames during the game.

Make sure the GUI metadata is saved and loaded (i.e. controlgroups).

Notice that the only new code is the register handler function system that allows avoiding all globals but one (and g_CivData considered unrelated for this diff) by using event / subscription based system.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

elexis created this revision.Sep 20 2019, 1:54 PM
elexis updated the Trac tickets for this revision.Sep 20 2019, 1:54 PM

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/262/display/redirect

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 4 tabs but found 5.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
| 190| 190| 		"tooltip": translate("Exits the game."),
| 191| 191| 		"onPress": () => {
| 192| 192| 			messageBox(
| 193|    |-					400, 200,
|    | 193|+				400, 200,
| 194| 194| 					translate("Are you sure you want to quit 0 A.D.?"),
| 195| 195| 					translate("Confirmation"),
| 196| 196| 					[translate("No"), translate("Yes")],
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 4 tabs but found 5.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
| 191| 191| 		"onPress": () => {
| 192| 192| 			messageBox(
| 193| 193| 					400, 200,
| 194|    |-					translate("Are you sure you want to quit 0 A.D.?"),
|    | 194|+				translate("Are you sure you want to quit 0 A.D.?"),
| 195| 195| 					translate("Confirmation"),
| 196| 196| 					[translate("No"), translate("Yes")],
| 197| 197| 					[null, Engine.Exit]);
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 4 tabs but found 5.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
| 192| 192| 			messageBox(
| 193| 193| 					400, 200,
| 194| 194| 					translate("Are you sure you want to quit 0 A.D.?"),
| 195|    |-					translate("Confirmation"),
|    | 195|+				translate("Confirmation"),
| 196| 196| 					[translate("No"), translate("Yes")],
| 197| 197| 					[null, Engine.Exit]);
| 198| 198| 		}
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 4 tabs but found 5.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
| 193| 193| 					400, 200,
| 194| 194| 					translate("Are you sure you want to quit 0 A.D.?"),
| 195| 195| 					translate("Confirmation"),
| 196|    |-					[translate("No"), translate("Yes")],
|    | 196|+				[translate("No"), translate("Yes")],
| 197| 197| 					[null, Engine.Exit]);
| 198| 198| 		}
| 199| 199| 	}
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 4 tabs but found 5.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/pregame/MainMenuItems.js
| 194| 194| 					translate("Are you sure you want to quit 0 A.D.?"),
| 195| 195| 					translate("Confirmation"),
| 196| 196| 					[translate("No"), translate("Yes")],
| 197|    |-					[null, Engine.Exit]);
|    | 197|+				[null, Engine.Exit]);
| 198| 198| 		}
| 199| 199| 	}
| 200| 200| ];

binaries/data/mods/public/gui/loadgame/SavegameList.js
|  80| »   »   »   switch·(sortKey)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 4.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/loadgame/SavegameDeleter.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/loadgame/SavegameDeleter.js
|  24|  24| 	deleteButtonTooltip()
|  25|  25| 	{
|  26|  26| 		let tooltip = colorizeHotkey(
|  27|    |-				translate("Delete the selected savegame using %(hotkey)s."),
|    |  27|+			translate("Delete the selected savegame using %(hotkey)s."),
|  28|  28| 				"session.savedgames.delete");
|  29|  29| 
|  30|  30| 		if (tooltip)
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 4.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/loadgame/SavegameDeleter.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/loadgame/SavegameDeleter.js
|  25|  25| 	{
|  26|  26| 		let tooltip = colorizeHotkey(
|  27|  27| 				translate("Delete the selected savegame using %(hotkey)s."),
|  28|    |-				"session.savedgames.delete");
|    |  28|+			"session.savedgames.delete");
|  29|  29| 
|  30|  30| 		if (tooltip)
|  31|  31| 			tooltip += colorizeHotkey(
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/loadgame/SavegameDeleter.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/loadgame/SavegameDeleter.js
|  55|  55| 			error("Could not delete saved game: " + gameID);
|  56|  56| 
|  57|  57| 		for (let handler of this.savegameListChangeHandlers)
|  58|    |-			handler.onSavegameListChange()
|    |  58|+			handler.onSavegameListChange();
|  59|  59| 	}
|  60|  60| }

binaries/data/mods/public/gui/loadgame/SavegameDeleter.js
|  58| »   »   »   handler.onSavegameListChange()
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/774/display/redirect

This revision was not accepted when it landed; it landed in state Needs Review.Sep 23 2019, 12:06 PM
This revision was automatically updated to reflect the committed changes.
Owners added a subscriber: Restricted Owners Package.Sep 23 2019, 12:06 PM