Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scenario loading to game state #516

Closed
xsebek opened this issue Jun 30, 2022 · 0 comments · Fixed by #1277
Closed

Fix scenario loading to game state #516

xsebek opened this issue Jun 30, 2022 · 0 comments · Fixed by #1277
Assignees
Labels
Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. Z-Refactoring This issue is about restructuring the code without changing the behaviour to improve code quality.

Comments

@xsebek
Copy link
Member

xsebek commented Jun 30, 2022

See the discussion in #515:

Changes to the entity map are permanent. For example, to reproduce:

  1. Start Swarm in cheat mode
  2. Load the new testing scenario containing Tardis ("Install one device")
  3. Quit to the menu
  4. Start a creative mode game
  5. Execute create "Tardis": it should say "I've never heard of a Tardis", but instead, it works. That's because the Tardis was added to the entityMap when loading the test scenario, and it was never removed.

We will have the same problem with recipes.

The problem is that scenarioToGameState modifies the existing GameState instead of creating a brand new one from scratch. I am actually not sure right now whether there are good reasons for this. But I think the "right" solution, assuming it is not too difficult for some reason I can't think of right now, is to create a new GameState from scratch every time we load a new scenario. But if we don't want to actually reread the entities and recipes from disk every time, we will have to save copies of the "pristine" versions somewhere, which is what my comment do we need to keep an old entity map around??? was supposed to mean.

Solution

Store the original game state (or at least entity map and recipes) and update it when loading the scenario.

@xsebek xsebek added Bug The observed behaviour is incorrect or unexpected. G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. labels Jun 30, 2022
@byorgey byorgey added Z-Refactoring This issue is about restructuring the code without changing the behaviour to improve code quality. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. labels Jun 30, 2022
@byorgey byorgey added the C-Low Hanging Fruit Ideal issue for new contributors. label Oct 1, 2022
@byorgey byorgey self-assigned this Oct 20, 2022
@mergify mergify bot closed this as completed in #1277 May 25, 2023
mergify bot pushed a commit that referenced this issue May 25, 2023
All info that needs to be persistent (*e.g.* the set of standard/default entities and recipes) is now stored in the `RuntimeState`.  The `GameState` record is now recreated completely from scratch every time upon starting a new scenario, so custom entities and recipes from the previous scenario do not persist into the next.

Fixes #516.  Fixes #689.

Also a bunch of related refactoring/simplification relating to how we were initializing state for tests and benchmarks.

I also want to refactor the tests so we only load data from disk once, but I have split that out into a separate issue (#1279).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. Z-Refactoring This issue is about restructuring the code without changing the behaviour to improve code quality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants