@@ -9,6 +9,17 @@ namespace TetrEnvironment;
9
9
10
10
public class Environment
11
11
{
12
+ #region Enum
13
+
14
+ public enum GameModeEnum
15
+ {
16
+ SelfControl ,
17
+ Normal ,
18
+ EventBased
19
+ }
20
+
21
+ #endregion
22
+
12
23
#region Infos
13
24
14
25
public GarbageInfo GarbageInfo { get ; private set ; }
@@ -29,7 +40,7 @@ public class Environment
29
40
private readonly GameType ? _gameType ;
30
41
private readonly Environment _manager ;
31
42
private ServiceProvider _provider ;
32
- private readonly EventFullData _eventFull ;
43
+ private readonly EventFullOptionsData _eventFullOptions ;
33
44
34
45
#endregion
35
46
@@ -44,10 +55,10 @@ public int CurrentFrame
44
55
public string ? Username { get ; private set ; }
45
56
public bool [ ] PressingKeys { get ; private set ; }
46
57
public int TotalFrame { get ; private set ; }
47
- public bool IsSelfControlMode { get ; private set ; }
58
+ public readonly GameModeEnum GameMode ;
48
59
public GameData GameData { get ; private set ; }
49
60
public CustomStats CustomStats { get ; private set ; }
50
- internal readonly KicksetBase Kickset ;
61
+ public KicksetBase Kickset { get ; private set ; }
51
62
52
63
#endregion
53
64
@@ -61,11 +72,9 @@ public int CurrentFrame
61
72
/// <exception cref="Exception"></exception>
62
73
public Environment ( IReadOnlyList < Event > ? events , GameType ? gametype )
63
74
{
64
- IsSelfControlMode = false ;
75
+ GameMode = GameModeEnum . Normal ;
65
76
_manager = this ;
66
77
_events = events ;
67
- //todo:implement it in Options
68
- Kickset = new KicksetSRSPlus ( ) ;
69
78
70
79
if ( events != null &&
71
80
events . FirstOrDefault ( @event => @event . type == EventType . End ) is EventEnd eventEnd )
@@ -75,33 +84,39 @@ public Environment(IReadOnlyList<Event>? events, GameType? gametype)
75
84
76
85
try
77
86
{
78
- _eventFull = ( events . First ( @event => @event . type == EventType . Full ) as EventFull ) . data ;
87
+ _eventFullOptions = ( events . First ( @event => @event . type == EventType . Full ) as EventFull ) . data . options ;
79
88
}
80
89
catch ( Exception e )
81
90
{
82
91
throw new Exception (
83
- "some of games in this replay has no FULL event! it will be ignored in TETR.IO. please consider to remove spetific game." ) ;
92
+ "some of games in this replay has no Full event! it will be ignored in TETR.IO. please consider to remove spetific game." ) ;
84
93
}
85
94
86
95
_gameType = gametype ;
87
96
Reset ( ) ;
88
97
89
- Username = _eventFull . options . username ;
98
+ Username = _eventFullOptions . username ;
90
99
}
91
100
92
101
/// <summary>
93
102
/// for self control
94
103
/// </summary>
95
- /// <param name="fullData "></param>
96
- public Environment ( EventFullData fullData )
104
+ /// <param name="fullOptionsData "></param>
105
+ public Environment ( EventFullOptionsData fullOptionsData )
97
106
{
98
- IsSelfControlMode = true ;
107
+ GameMode = GameModeEnum . SelfControl ;
99
108
TotalFrame = - 1 ;
100
109
_manager = this ;
101
- _eventFull = fullData ;
110
+ _eventFullOptions = fullOptionsData ;
102
111
Reset ( ) ;
103
112
}
104
113
114
+ public Environment ( EventFullOptions options )
115
+ {
116
+ GameMode = GameModeEnum . EventBased ;
117
+ _manager = this ;
118
+ }
119
+
105
120
private void SolveWithDI ( ServiceProvider provider )
106
121
{
107
122
GarbageInfo = provider . GetService < GarbageInfo > ( ) ?? throw new InvalidOperationException ( ) ;
@@ -116,7 +131,7 @@ private void SolveWithDI(ServiceProvider provider)
116
131
LineInfo = provider . GetService < LineInfo > ( ) ?? throw new InvalidOperationException ( ) ;
117
132
}
118
133
119
- private void InitDI ( EventFullData fullData , ref ServiceProvider provider )
134
+ private void InitDI ( EventFullOptionsData fullDataOptions , ref ServiceProvider provider )
120
135
{
121
136
ServiceCollection service = new ServiceCollection ( ) ;
122
137
service . AddSingleton < BagInfo > ( ) ;
@@ -134,65 +149,57 @@ private void InitDI(EventFullData fullData, ref ServiceProvider provider)
134
149
service . AddSingleton < Options > ( ) ;
135
150
service . AddSingleton < Stats > ( ) ;
136
151
service . AddSingleton < LineInfo > ( ) ;
137
- service . AddSingleton < EventFullData > ( fullData ) ;
152
+ service . AddSingleton < EventFullOptionsData > ( fullDataOptions ) ;
138
153
service . AddSingleton < Environment > ( this ) ;
139
154
service . AddSingleton < Handling > ( new Handling ( )
140
155
{
141
- ARR = fullData . options . handling . arr ?? 5 ,
142
- DAS = fullData . options . handling . das ?? 12 ,
143
- SDF = fullData . options . handling . sdf ?? 20 ,
144
- DCD = fullData . options . handling . dcd ?? 20 ,
145
- Cancel = fullData . options . handling . cancel ?? false ,
146
- SafeLock = fullData . options . handling . safelock == true ? 1 : 0 ,
156
+ ARR = fullDataOptions . handling . arr ?? 5 ,
157
+ DAS = fullDataOptions . handling . das ?? 12 ,
158
+ SDF = fullDataOptions . handling . sdf ?? 20 ,
159
+ DCD = fullDataOptions . handling . dcd ?? 20 ,
160
+ Cancel = fullDataOptions . handling . cancel ?? false ,
161
+ SafeLock = fullDataOptions . handling . safelock == true ? 1 : 0 ,
147
162
} ) ;
148
163
149
164
#if DEBUG
150
- if ( fullData . options ? . handling ? . arr == null )
165
+ if ( fullDataOptions . handling ? . arr == null )
151
166
Debug . WriteLine ( "options.handling is initialized by default. it is wrong in most case." ) ;
152
167
#endif
153
168
154
169
provider = service . BuildServiceProvider ( ) ;
155
170
}
156
171
157
-
172
+ /// <summary>
173
+ /// for normal
174
+ /// </summary>
175
+ /// <returns></returns>
176
+ /// <exception cref="Exception"></exception>
158
177
public bool NextFrame ( )
159
178
{
179
+ if ( GameMode != GameModeEnum . Normal )
180
+ throw new Exception ( "This NextFrame function is for normal." ) ;
181
+
182
+
160
183
if ( _manager . FrameInfo . CurrentFrame > TotalFrame )
161
184
return false ;
162
185
163
186
GameData . SubFrame = 0 ;
164
187
_manager . FrameInfo . PullEvents ( _events ) ;
165
188
CurrentFrame ++ ;
166
189
167
- _manager . HandleInfo . ProcessShift ( false , 1 - GameData . SubFrame ) ;
168
- _manager . FallInfo . FallEvent ( null , 1 - GameData . SubFrame ) ;
169
- _manager . WaitingFrameInfo . ExcuteWaitingFrames ( ) ;
170
-
171
- //unsafe waiting
172
-
173
- if ( _manager . GameData . Options . GravityIncrease > 0 &&
174
- CurrentFrame > _manager . GameData . Options . GravityMargin )
175
- _manager . GameData . Gravity += _manager . GameData . Options . GravityIncrease / 60 ;
176
-
177
- if ( _manager . GameData . Options . GarbageIncrease > 0 &&
178
- CurrentFrame > _manager . GameData . Options . GarbageMargin )
179
- _manager . GameData . Options . GarbageMultiplier += _manager . GameData . Options . GarbageIncrease / 60 ;
180
-
181
- if ( _manager . GameData . Options . GarbageCapIncrease > 0 )
182
- _manager . GameData . Options . GarbageCap += _manager . GameData . Options . GarbageCapIncrease / 60 ;
183
-
190
+ InternalNextFrame ( ) ;
184
191
185
192
return true ;
186
193
}
187
194
188
195
/// <summary>
189
- /// for self control
196
+ /// for self control or event-based
190
197
/// </summary>
191
198
/// <param name="event"></param>
192
199
public void NextFrame ( Queue < Event > events )
193
200
{
194
- if ( ! IsSelfControlMode )
195
- throw new Exception ( "This NextFrame is for self control, please consider using normal NextFrame ." ) ;
201
+ if ( GameMode is GameModeEnum . EventBased or GameModeEnum . SelfControl )
202
+ throw new Exception ( "This NextFrame function is for self control or event-based ." ) ;
196
203
197
204
GameData . SubFrame = 0 ;
198
205
@@ -203,7 +210,12 @@ public void NextFrame(Queue<Event> events)
203
210
}
204
211
205
212
CurrentFrame ++ ;
213
+ InternalNextFrame ( ) ;
214
+ }
206
215
216
+
217
+ private void InternalNextFrame ( )
218
+ {
207
219
_manager . HandleInfo . ProcessShift ( false , 1 - GameData . SubFrame ) ;
208
220
_manager . FallInfo . FallEvent ( null , 1 - GameData . SubFrame ) ;
209
221
_manager . WaitingFrameInfo . ExcuteWaitingFrames ( ) ;
@@ -220,10 +232,10 @@ public void NextFrame(Queue<Event> events)
220
232
_manager . GameData . Options . GarbageCap += _manager . GameData . Options . GarbageCapIncrease / 60 ;
221
233
}
222
234
223
-
224
235
public void Reset ( )
225
236
{
226
- InitDI ( _eventFull , ref _provider ) ;
237
+ Kickset = new KicksetSRSPlus ( ) ;
238
+ InitDI ( _eventFullOptions , ref _provider ) ;
227
239
SolveWithDI ( _provider ) ;
228
240
GameData = new GameData ( ) ;
229
241
GameData . Initialize ( _provider , _gameType ) ;
0 commit comments