-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ScreenData record to pass persistent arguments between screens
- Loading branch information
Showing
8 changed files
with
85 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 31 additions & 3 deletions
34
src/core/src/com/mygdx/scngame/screens/data/ScreenData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
package com.mygdx.scngame.screens.data; | ||
|
||
import com.badlogic.gdx.Game; | ||
import com.badlogic.gdx.assets.AssetManager; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; | ||
import com.mygdx.scngame.settings.Settings; | ||
|
||
public record ScreenData(Game game, SpriteBatch batch, ShapeRenderer shapeRenderer, Settings settings) { | ||
|
||
} | ||
/** | ||
* Holds all the data that is required between different game screens. | ||
* | ||
* This is used instead of individual arguments for a number of reasons: | ||
* <ol> | ||
* <li>Records are immutable. Although not forced, it encourages | ||
* a ScreenData instance to persist across screens instead of | ||
* re-instantiating everything | ||
* </li> | ||
* | ||
* <li> | ||
* Reduces the number of arguments in each screen constructor, | ||
* especially since every screen will require these values | ||
* </li> | ||
* | ||
* <li> | ||
* Still allows for testing screens with fake values. Using singletons | ||
* or static values held in the main game class wouldn't allow for this, and could | ||
* create some gnarly inter-dependencies between sub-systems. | ||
* </li> | ||
* </ol> | ||
* | ||
* @author Silas Hayes-Williams | ||
*/ | ||
public record ScreenData(Game game, | ||
SpriteBatch batch, | ||
ShapeRenderer shapeRenderer, | ||
Settings settings, | ||
AssetManager assets | ||
) {} |