@@ -13,46 +13,71 @@ internal class World : IWorld
13
13
private readonly IntPtr _nativePointer ;
14
14
private readonly Plugin _plugin ;
15
15
16
- public TimeData Time
16
+ public World ( IntPtr nativePointer , Plugin plugin )
17
+ {
18
+ _nativePointer = nativePointer ;
19
+ _plugin = plugin ;
20
+ }
21
+
22
+ public Task SetTimeAsync ( TimeData time )
17
23
{
18
- get => StructConverter . PointerToStruct < TimeData > ( Rage . World . World_GetTime ( _nativePointer ) ) ;
19
- set => Rage . World . World_SetTime ( _nativePointer , value ) ;
24
+ return _plugin . Schedule ( ( ) => Rage . World . World_SetTime ( _nativePointer , time ) ) ;
20
25
}
21
26
22
- public WeatherType Weather
27
+ public async Task < TimeData > GetTimeAsync ( )
23
28
{
24
- get => ConvertWeatherNameToType ( StringConverter . PointerToString ( Rage . World . World_GetWeather ( _nativePointer ) ) ) ;
25
- set
29
+ var timePointer = await _plugin
30
+ . Schedule ( ( ) => Rage . World . World_GetTime ( _nativePointer ) )
31
+ . ConfigureAwait ( false ) ;
32
+
33
+ return StructConverter . PointerToStruct < TimeData > ( timePointer ) ;
34
+ }
35
+
36
+ public async Task SetWeatherAsync ( WeatherType type )
37
+ {
38
+ var weatherName = ConvertWeatherTypeToName ( type ) ;
39
+ if ( string . IsNullOrEmpty ( weatherName ) )
26
40
{
27
- var weatherName = ConvertWeatherTypeToName ( value ) ;
28
- if ( string . IsNullOrEmpty ( weatherName ) )
29
- {
30
- return ;
31
- }
32
-
33
- using ( var converter = new StringConverter ( ) )
34
- {
35
- Rage . World . World_SetWeather ( _nativePointer , converter . StringToPointer ( weatherName ) ) ;
36
- }
41
+ return ;
42
+ }
43
+
44
+ using ( var converter = new StringConverter ( ) )
45
+ {
46
+ var weatherPointer = converter . StringToPointer ( weatherName ) ;
47
+
48
+ await _plugin
49
+ . Schedule ( ( ) => Rage . World . World_SetWeather ( _nativePointer , weatherPointer ) )
50
+ . ConfigureAwait ( false ) ;
37
51
}
38
52
}
39
53
40
- public bool AreTrafficLightsLocked
54
+ public async Task < WeatherType > GetWeatherAsync ( )
41
55
{
42
- get => Rage . World . World_AreTrafficLightsLocked ( _nativePointer ) ;
43
- set => Rage . World . World_LockTrafficLights ( _nativePointer , value ) ;
56
+ var weatherPointer = await _plugin
57
+ . Schedule ( ( ) => Rage . World . World_GetWeather ( _nativePointer ) )
58
+ . ConfigureAwait ( false ) ;
59
+
60
+ return ConvertWeatherNameToType ( StringConverter . PointerToString ( weatherPointer ) ) ;
44
61
}
45
62
46
- public int TrafficLightsState
63
+ public Task SetTrafficLightsLockedAsync ( bool locked )
47
64
{
48
- get => Rage . World . World_GetTrafficLightsState ( _nativePointer ) ;
49
- set => Rage . World . World_SetTrafficLightsState ( _nativePointer , value ) ;
65
+ return _plugin . Schedule ( ( ) => Rage . World . World_LockTrafficLights ( _nativePointer , locked ) ) ;
50
66
}
51
67
52
- public World ( IntPtr nativePointer , Plugin plugin )
68
+ public Task < bool > AreTrafficLightsLockedAsync ( )
53
69
{
54
- _nativePointer = nativePointer ;
55
- _plugin = plugin ;
70
+ return _plugin . Schedule ( ( ) => Rage . World . World_AreTrafficLightsLocked ( _nativePointer ) ) ;
71
+ }
72
+
73
+ public Task SetTrafficLightsStateAsync ( int state )
74
+ {
75
+ return _plugin . Schedule ( ( ) => Rage . World . World_SetTrafficLightsState ( _nativePointer , state ) ) ;
76
+ }
77
+
78
+ public Task < int > GetTrafficLightsStateAsync ( )
79
+ {
80
+ return _plugin . Schedule ( ( ) => Rage . World . World_GetTrafficLightsState ( _nativePointer ) ) ;
56
81
}
57
82
58
83
public async Task SetWeatherTransitionAsync ( WeatherType weather , float time )
0 commit comments