@@ -6,18 +6,34 @@ use rw3d_core::utils::{scripts_execute_formatter, scripts_root_path_formatter, m
66
77pub ( crate ) trait HandleResponse {
88 fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) ;
9+ /// Whether the handler has finished the work
910 fn is_done ( & self ) -> bool ;
11+ /// Max time for the next response to come in millis
12+ /// Used to indicate when the game needs to do some work before sending the response
13+ fn response_await_time ( & self ) -> u64 ;
1014}
1115
1216
1317
1418pub ( crate ) struct ScriptsReloadPrinter {
15- has_finished : bool ,
19+ max_compile_time : u64 ,
1620 warnings : Vec < String > ,
17- errors : Vec < String >
21+ errors : Vec < String > ,
22+ is_compiling : bool ,
23+ has_finished : bool
1824}
1925
2026impl ScriptsReloadPrinter {
27+ pub fn new ( max_compile_time : u64 ) -> Self {
28+ ScriptsReloadPrinter {
29+ max_compile_time,
30+ warnings : Vec :: new ( ) ,
31+ errors : Vec :: new ( ) ,
32+ is_compiling : false ,
33+ has_finished : false ,
34+ }
35+ }
36+
2137 fn print_summary ( & self ) {
2238 println ! ( "========== {} Errors, {} Warnings ==========\n " , self . errors. len( ) , self . warnings. len( ) ) ;
2339
@@ -33,16 +49,6 @@ impl ScriptsReloadPrinter {
3349 }
3450}
3551
36- impl Default for ScriptsReloadPrinter {
37- fn default ( ) -> Self {
38- ScriptsReloadPrinter {
39- has_finished : false ,
40- warnings : Vec :: new ( ) ,
41- errors : Vec :: new ( ) ,
42- }
43- }
44- }
45-
4652impl HandleResponse for ScriptsReloadPrinter {
4753 fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) {
4854 let msg = scripts_reload_formatter ( & response) ;
@@ -61,7 +67,9 @@ impl HandleResponse for ScriptsReloadPrinter {
6167 ScriptsReloadResponseType :: Finished ( _) => {
6268 self . has_finished = true ;
6369 }
64- _ => { }
70+ ScriptsReloadResponseType :: Log ( s) => {
71+ self . is_compiling = s. contains ( "Compiling functions" ) ;
72+ }
6573 }
6674 }
6775
@@ -79,6 +87,14 @@ impl HandleResponse for ScriptsReloadPrinter {
7987 fn is_done ( & self ) -> bool {
8088 self . has_finished
8189 }
90+
91+ fn response_await_time ( & self ) -> u64 {
92+ if self . is_compiling {
93+ self . max_compile_time
94+ } else {
95+ 500
96+ }
97+ }
8298}
8399
84100
@@ -97,6 +113,10 @@ impl HandleResponse for ScriptsExecutePrinter {
97113 fn is_done ( & self ) -> bool {
98114 true // only one packet
99115 }
116+
117+ fn response_await_time ( & self ) -> u64 {
118+ 500
119+ }
100120}
101121
102122
@@ -115,6 +135,10 @@ impl HandleResponse for ScriptsRootpathPrinter {
115135 fn is_done ( & self ) -> bool {
116136 true // only one packet
117137 }
138+
139+ fn response_await_time ( & self ) -> u64 {
140+ 500
141+ }
118142}
119143
120144
@@ -133,6 +157,10 @@ impl HandleResponse for ModlistPrinter {
133157 fn is_done ( & self ) -> bool {
134158 true // only one packet
135159 }
160+
161+ fn response_await_time ( & self ) -> u64 {
162+ 500
163+ }
136164}
137165
138166
@@ -151,6 +179,10 @@ impl HandleResponse for OpcodePrinter {
151179 fn is_done ( & self ) -> bool {
152180 true // only one packet
153181 }
182+
183+ fn response_await_time ( & self ) -> u64 {
184+ 500
185+ }
154186}
155187
156188
@@ -169,4 +201,8 @@ impl HandleResponse for VarlistPrinter {
169201 fn is_done ( & self ) -> bool {
170202 true // only one packet
171203 }
204+
205+ fn response_await_time ( & self ) -> u64 {
206+ 500
207+ }
172208}
0 commit comments