20
20
import com .bladecoder .engine .ink .InkManager ;
21
21
import com .bladecoder .engine .model .BaseActor ;
22
22
import com .bladecoder .engine .model .InteractiveActor ;
23
+ import com .bladecoder .engine .model .Inventory ;
23
24
import com .bladecoder .engine .model .Scene ;
24
25
import com .bladecoder .engine .model .UIActors ;
25
26
import com .bladecoder .engine .model .Verb ;
@@ -48,6 +49,7 @@ public class ActionCallbackSerialization {
48
49
private static final String SEPARATION_SYMBOL = "#" ;
49
50
private static final String INK_MANAGER_TAG = "INK_MANAGER" ;
50
51
private static final String UIACTORS_TAG = "UIACTORS" ;
52
+ private static final String INVENTORY_TAG = "INVENTORY" ;
51
53
private static final String DEFAULT_VERB_TAG = "DEFAULT_VERB" ;
52
54
53
55
private static String find (ActionCallback cb , Verb v ) {
@@ -152,6 +154,22 @@ private static String find(ActionCallback cb, UIActors uia) {
152
154
153
155
return null ;
154
156
}
157
+
158
+ private static String find (ActionCallback cb , Inventory inv ) {
159
+ for (int i =0 ; i < inv .getNumItems (); i ++) {
160
+ InteractiveActor a = inv .get (i );
161
+ String id = find (cb , a );
162
+
163
+ if (id != null ) {
164
+ StringBuilder stringBuilder = new StringBuilder (INVENTORY_TAG );
165
+ stringBuilder .append (SEPARATION_SYMBOL ).append (id );
166
+
167
+ return stringBuilder .toString ();
168
+ }
169
+ }
170
+
171
+ return null ;
172
+ }
155
173
156
174
/**
157
175
* Generates a String for serialization that allows locate the
@@ -171,6 +189,12 @@ public static String find(ActionCallback cb) {
171
189
// search in UIActors
172
190
id = find (cb , World .getInstance ().getUIActors ());
173
191
192
+ if (id != null )
193
+ return id ;
194
+
195
+ // search in inventory
196
+ id = find (cb , World .getInstance ().getInventory ());
197
+
174
198
if (id != null )
175
199
return id ;
176
200
@@ -188,6 +212,7 @@ public static String find(ActionCallback cb) {
188
212
if (id != null )
189
213
return id ;
190
214
215
+ // search in player
191
216
id = find (cb , s .getPlayer ());
192
217
if (id != null )
193
218
return id ;
@@ -248,7 +273,7 @@ public static ActionCallback find(String id) {
248
273
String verbId ;
249
274
int actionPos = -1 ;
250
275
251
- if (id .startsWith (UIACTORS_TAG )) {
276
+ if (id .startsWith (UIACTORS_TAG ) || id . startsWith ( INVENTORY_TAG ) ) {
252
277
253
278
actorId = split [1 ];
254
279
verbId = split [2 ];
@@ -276,15 +301,20 @@ public static ActionCallback find(String id) {
276
301
} else {
277
302
a = (InteractiveActor ) s .getActor (actorId , true );
278
303
279
- if (a == null )
304
+ if (a == null ) {
305
+ EngineLogger .error ("ActionCallbackSerialization - Actor not found: " + actorId + " cb: " + id );
280
306
return null ;
307
+ }
281
308
282
309
v = a .getVerbManager ().getVerbs ().get (verbId );
283
310
}
284
311
}
285
312
286
- if (v == null )
313
+ if (v == null ) {
314
+ EngineLogger .error ("ActionCallbackSerialization - Verb not found: " + verbId + " cb: " + id );
315
+
287
316
return null ;
317
+ }
288
318
289
319
if (actionPos == -1 )
290
320
return v ;
@@ -293,6 +323,8 @@ public static ActionCallback find(String id) {
293
323
294
324
if (action instanceof ActionCallback )
295
325
return (ActionCallback ) action ;
326
+
327
+ EngineLogger .error ("ActionCallbackSerialization - CB not found: " + id );
296
328
297
329
return null ;
298
330
}
0 commit comments