10 |
public static boolean dbg = false; |
public static boolean dbg = false; |
11 |
private static void pa(String s) { System.out.println(s); } |
private static void pa(String s) { System.out.println(s); } |
12 |
|
|
13 |
public CommandCall currentAction; |
public CommandCall currentCommand; |
14 |
|
public int currentWin; |
15 |
|
|
16 |
protected Fallback fallback; |
protected Fallback fallback; |
17 |
protected Map bindings; |
protected Map bindings; |
18 |
|
|
19 |
|
public Set markedCells = new HashSet(); |
20 |
|
|
21 |
/** An arrow key. |
/** An arrow key. |
22 |
* Can be a value in the <code>bindings</code> map. |
* Can be a value in the <code>bindings</code> map. |
23 |
*/ |
*/ |
25 |
int win, axis, dir; |
int win, axis, dir; |
26 |
public Arrow(int w, int a, int d) { win=w; axis=a; dir=d; } |
public Arrow(int w, int a, int d) { win=w; axis=a; dir=d; } |
27 |
} |
} |
28 |
|
public static class Action { |
29 |
|
CommandCall command; |
30 |
|
int window; |
31 |
|
|
32 |
|
public Action(CommandCall command, int window) { |
33 |
|
this.command = command; |
34 |
|
this.window = window; |
35 |
|
} |
36 |
|
} |
37 |
|
|
38 |
public PotionFallbackBinder(Map bindings) { |
public PotionFallbackBinder(Map bindings) { |
39 |
this.bindings = bindings; |
this.bindings = bindings; |
48 |
if(dbg) pa("Binding: "+binding); |
if(dbg) pa("Binding: "+binding); |
49 |
if(binding == null) { |
if(binding == null) { |
50 |
// no binding for this key: clear pending |
// no binding for this key: clear pending |
51 |
currentAction = null; |
currentCommand = null; |
52 |
AbstractUpdateManager.chg(); |
AbstractUpdateManager.chg(); |
53 |
} else if(binding instanceof CommandCall) { |
} else if(binding instanceof Action) { |
54 |
currentAction = (CommandCall)binding; |
Action action = (Action)binding; |
55 |
if(dbg) pa("Replaced currentAction."); |
currentCommand = action.command; |
56 |
if(currentAction.isComplete()) { |
currentWin = action.window; |
57 |
if(dbg) pa("Execute: "+currentAction); |
if(dbg) pa("Replaced currentCommand."); |
58 |
Map context = getContext(fallback.windows[1]); |
if(currentCommand.isComplete()) { |
59 |
currentAction.execute(context); |
if(dbg) pa("Execute: "+currentCommand); |
60 |
currentAction = null; |
Map context = getContext(fallback.windows[currentWin]); |
61 |
|
currentCommand.execute(context); |
62 |
|
currentCommand = null; |
63 |
} |
} |
64 |
} else if(binding instanceof Arrow) { |
} else if(binding instanceof Arrow) { |
65 |
Arrow a = (Arrow)binding; |
Arrow a = (Arrow)binding; |
66 |
Fallback.Win w = fallback.windows[a.win]; |
Fallback.Win w = fallback.windows[a.win]; |
67 |
AbstractUpdateManager.prioritize(w.getScreen()); |
AbstractUpdateManager.prioritize(w.getScreen()); |
68 |
|
|
69 |
if(currentAction == null) { |
if(currentCommand == null) { |
70 |
if(dbg) pa("Move."); |
if(dbg) pa("Move."); |
71 |
Cell n = w.cursor.s(w.dims[a.axis], a.dir); |
Cell n = w.cursor.s(w.dims[a.axis], a.dir); |
72 |
if(n != null) w.cursor = n; |
if(n != null) w.cursor = n; |
73 |
} else { |
} else { |
74 |
Map context = getContext(w); |
Map context = getContext(w); |
75 |
Type t = currentAction.getNextParam(); |
Type t = currentCommand.getNextParam(); |
76 |
FunctionExpression e = t.readDir(a.win, a.axis, a.dir, context); |
FunctionExpression e = t.readDir(a.win, a.axis, a.dir, context); |
77 |
if(dbg) pa("Read direction: "+e); |
if(dbg) pa("Read direction: "+e); |
78 |
if(e == null) { |
if(e == null) { |
79 |
AbstractUpdateManager.chg(); |
AbstractUpdateManager.chg(); |
80 |
return; |
return; |
81 |
} |
} |
82 |
currentAction = (CommandCall)currentAction.setNextParam(e); |
currentCommand = (CommandCall)currentCommand.setNextParam(e); |
83 |
if(dbg) pa("Updated currentAction: "+currentAction); |
if(dbg) pa("Updated currentCommand: "+currentCommand); |
84 |
if(currentAction.isComplete()) { |
if(currentCommand.isComplete()) { |
85 |
if(dbg) pa("Execute: "+currentAction); |
if(dbg) pa("Execute: "+currentCommand); |
86 |
currentAction.execute(context); |
currentCommand.execute(context); |
87 |
currentAction = null; |
currentCommand = null; |
88 |
} |
} |
89 |
} |
} |
90 |
} |
} |
96 |
Map context = new HashMap(); |
Map context = new HashMap(); |
97 |
context.put(Space.class, fallback.space); |
context.put(Space.class, fallback.space); |
98 |
context.put(ViewContext.class, win); |
context.put(ViewContext.class, win); |
99 |
|
context.put(PotionFallbackBinder.class, this); |
100 |
return context; |
return context; |
101 |
} |
} |
102 |
|
|
103 |
|
public boolean isMarked(Cell c){ |
104 |
|
return markedCells.contains(c); |
105 |
|
} |
106 |
|
|
107 |
public void mouse(MouseEvent e, Fallback.Win win) { |
public void mouse(MouseEvent e, Fallback.Win win) { |
108 |
// no bindings implemented... |
// no bindings implemented... |
109 |
} |
} |