@@ -8,15 +8,13 @@ public partial class StageProducer : Node
88 //Generate a map, starting as a width x height grid, pick a starting spot and do (path) paths from that to the last
99 //row, connecting the path, then connect all at the end to the boss room.
1010 public static RandomNumberGenerator GlobalRng = new RandomNumberGenerator ( ) ;
11- private ulong _seed ;
12- private ulong _lastRngState ;
1311 public static bool IsInitialized ;
1412
1513 private Stages _curStage = Stages . Title ; //TODO: State Machine kinda deal?
1614 private Node _curScene ;
17- public static MapGrid . Room CurRoom { get ; private set ; }
18- public static Vector2I MapSize { get ; private set ; } = new Vector2I ( 7 , 6 ) ; //For now, make width an odd number
15+ public static int CurRoom { get ; private set ; }
1916
17+ public static Vector2I MapSize { get ; private set ; } = new Vector2I ( 7 , 6 ) ; //For now, make width an odd number
2018 public static MapGrid Map { get ; } = new MapGrid ( ) ;
2119
2220 public static BattleConfig Config ;
@@ -25,6 +23,8 @@ public partial class StageProducer : Node
2523 //TODO: Allow for permanent changes and battle temporary stat changes.
2624 public static PlayerStats PlayerStats ;
2725
26+ public static CanvasLayer ContrastFilter ;
27+
2828 public override void _EnterTree ( )
2929 {
3030 InitFromCfg ( ) ;
@@ -38,21 +38,66 @@ private void InitFromCfg()
3838 TranslationServer . SetLocale (
3939 SaveSystem . GetConfigValue ( SaveSystem . ConfigSettings . LanguageKey ) . As < string > ( )
4040 ) ;
41+ ContrastFilter = GD . Load < PackedScene > ( "res://Globals/ContrastFilter/ContrastFilter.tscn" )
42+ . Instantiate < CanvasLayer > ( ) ;
43+ ContrastFilter . Visible = SaveSystem
44+ . GetConfigValue ( SaveSystem . ConfigSettings . HighContrast )
45+ . AsBool ( ) ;
46+ GetTree ( ) . Root . CallDeferred ( "add_child" , ContrastFilter ) ;
4147 }
4248
4349 public void StartGame ( )
4450 {
45- Map . InitMapGrid ( MapSize . X , MapSize . Y , 3 ) ;
4651 GlobalRng . Randomize ( ) ;
47- _seed = GlobalRng . Seed ;
48- _lastRngState = GlobalRng . State ;
52+ GenerateMapConsistent ( ) ;
4953 PlayerStats = new PlayerStats ( ) ;
5054
51- CurRoom = Map . GetRooms ( ) [ 0 ] ;
55+ CurRoom = Map . GetRooms ( ) [ 0 ] . Idx ;
56+ IsInitialized = true ;
57+ }
58+
59+ public bool LoadGame ( )
60+ {
61+ SaveSystem . SaveFile sv = SaveSystem . LoadGame ( ) ;
62+ if ( sv == null )
63+ {
64+ GD . PushError (
65+ "StageProducer.LoadGame(): Can't load game, either file 404 or invalid file."
66+ ) ;
67+ return false ;
68+ }
69+ GlobalRng . Seed = sv . RngSeed ;
70+ GenerateMapConsistent ( ) ;
71+ GlobalRng . State = sv . RngState ;
72+ CurRoom = sv . LastRoomIdx ;
73+
74+ PlayerStats = new PlayerStats ( ) ;
75+ PlayerStats . CurNotes = Array . Empty < Note > ( ) ;
76+ foreach ( int noteId in sv . NoteIds )
77+ {
78+ PlayerStats . AddNote ( Scribe . NoteDictionary [ noteId ] ) ;
79+ }
80+ foreach ( int relicId in sv . RelicIds )
81+ {
82+ PlayerStats . AddRelic ( Scribe . RelicDictionary [ relicId ] ) ;
83+ }
84+ PlayerStats . CurrentHealth = sv . PlayerHealth ;
5285 IsInitialized = true ;
86+ return true ;
87+ }
88+
89+ private void GenerateMapConsistent ( )
90+ {
91+ GlobalRng . State = GlobalRng . Seed << 5 / 2 ;
92+ Map . InitMapGrid ( MapSize . X , MapSize . Y , 3 ) ;
5393 }
5494
55- public static void ChangeCurRoom ( MapGrid . Room room )
95+ public static MapGrid . Room GetCurRoom ( )
96+ {
97+ return Map . GetRooms ( ) [ CurRoom ] ;
98+ }
99+
100+ public static void ChangeCurRoom ( int room )
56101 {
57102 CurRoom = room ;
58103 }
@@ -64,6 +109,7 @@ public void TransitionFromRoom(int nextRoomIdx)
64109
65110 public void TransitionStage ( Stages nextStage , int nextRoomIdx = - 1 )
66111 {
112+ GetTree ( ) . Root . RemoveChild ( ContrastFilter ) ;
67113 switch ( nextStage )
68114 {
69115 case Stages . Title :
@@ -89,6 +135,11 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
89135 StartGame ( ) ;
90136 }
91137 break ;
138+ case Stages . Load :
139+ if ( ! LoadGame ( ) )
140+ StartGame ( ) ;
141+ GetTree ( ) . ChangeSceneToFile ( "res://scenes/Maps/cartographer.tscn" ) ;
142+ break ;
92143 case Stages . Quit :
93144 GetTree ( ) . Quit ( ) ;
94145 return ;
@@ -97,6 +148,8 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
97148 break ;
98149 }
99150
151+ //Apply grayscale shader to all scenes
152+ GetTree ( ) . Root . AddChild ( ContrastFilter ) ;
100153 _curStage = nextStage ;
101154 }
102155
0 commit comments