7 |
import java.util.*; |
import java.util.*; |
8 |
|
|
9 |
public class PotionFallbackBinder implements FallbackBinder { |
public class PotionFallbackBinder implements FallbackBinder { |
10 |
|
public static boolean dbg = false; |
11 |
|
private static void pa(String s) { System.out.println(s); } |
12 |
|
|
13 |
public CommandCall currentAction; |
public CommandCall currentAction; |
14 |
|
|
30 |
public void setFallback(Fallback f) { fallback=f; } |
public void setFallback(Fallback f) { fallback=f; } |
31 |
|
|
32 |
public void keystroke(String k, Fallback.Win win) { |
public void keystroke(String k, Fallback.Win win) { |
33 |
|
if(dbg) pa("Key: "+k); |
34 |
|
|
35 |
Object binding = bindings.get(k); |
Object binding = bindings.get(k); |
36 |
|
if(dbg) pa("Binding: "+binding); |
37 |
if(binding == null) |
if(binding == null) |
38 |
// no binding for this key |
// no binding for this key |
39 |
return; |
return; |
40 |
|
|
41 |
else if(binding instanceof CommandCall) { |
else if(binding instanceof CommandCall) { |
42 |
currentAction = (CommandCall)binding; |
currentAction = (CommandCall)binding; |
43 |
|
if(dbg) pa("Replaced currentAction."); |
44 |
if(currentAction.isComplete()) { |
if(currentAction.isComplete()) { |
45 |
|
if(dbg) pa("Execute: "+currentAction); |
46 |
Map context = getContext(fallback.windows[1]); |
Map context = getContext(fallback.windows[1]); |
47 |
currentAction.execute(context); |
currentAction.execute(context); |
48 |
currentAction = null; |
currentAction = null; |
50 |
} else if(binding instanceof Arrow) { |
} else if(binding instanceof Arrow) { |
51 |
Arrow a = (Arrow)binding; |
Arrow a = (Arrow)binding; |
52 |
Fallback.Win w = fallback.windows[a.win]; |
Fallback.Win w = fallback.windows[a.win]; |
53 |
|
AbstractUpdateManager.prioritize(w.getScreen()); |
54 |
|
|
55 |
if(currentAction == null) { |
if(currentAction == null) { |
56 |
|
if(dbg) pa("Move."); |
57 |
Cell n = w.cursor.s(w.dims[a.axis], a.dir); |
Cell n = w.cursor.s(w.dims[a.axis], a.dir); |
58 |
if(n != null) w.cursor = n; |
if(n != null) w.cursor = n; |
59 |
} else { |
} else { |
60 |
Map context = getContext(w); |
Map context = getContext(w); |
61 |
Type t = currentAction.getNextParam(); |
Type t = currentAction.getNextParam(); |
62 |
FunctionExpression e = t.readDir(a.win, a.axis, a.dir, context); |
FunctionExpression e = t.readDir(a.win, a.axis, a.dir, context); |
63 |
if(e == null) return; |
if(dbg) pa("Read direction: "+e); |
64 |
|
if(e == null) { |
65 |
|
AbstractUpdateManager.chg(); |
66 |
|
return; |
67 |
|
} |
68 |
currentAction = (CommandCall)currentAction.setNextParam(e); |
currentAction = (CommandCall)currentAction.setNextParam(e); |
69 |
|
if(dbg) pa("Updated currentAction: "+currentAction); |
70 |
if(currentAction.isComplete()) { |
if(currentAction.isComplete()) { |
71 |
|
if(dbg) pa("Execute: "+currentAction); |
72 |
currentAction.execute(context); |
currentAction.execute(context); |
73 |
currentAction = null; |
currentAction = null; |
74 |
} |
} |
75 |
} |
} |
76 |
} |
} |
77 |
|
|
78 |
|
AbstractUpdateManager.chg(); |
79 |
} |
} |
80 |
|
|
81 |
public Map getContext(Fallback.Win win) { |
public Map getContext(Fallback.Win win) { |