Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1004 chris 1
package com.gebauz.bauzoid.menu;
2
 
3
import java.util.Vector;
4
 
5
import com.gebauz.bauzoid.parser.ScanException;
6
import com.gebauz.bauzoid.parser.Tokenizer;
7
 
8
/** Provides static functions for processing default commands in events. */
9
public class EventProcessor
10
{
11
        // Constants========================================================================================
12
 
13
        // Embedded Types===================================================================================
14
 
15
        // Fields===========================================================================================
16
 
17
        // Methods==========================================================================================
18
 
19
        /** Breaks the parameter down to a list of Strings containing a statement/instruction each for easier parsing. */
20
        public static Vector<String> parseParameter(String param)
21
        {
22
                Vector<String> paramList = new Vector<String>();
23
 
24
                Tokenizer t = new Tokenizer(param);
25
 
26
                try
27
                {
28
                        while (!t.isEndOfString())
29
                        {
30
                                String p = t.readUntilToken(";");
31
                                if (!p.isEmpty())
32
                                        paramList.add(p);
33
 
34
                                if (t.isEndOfString() || !t.checkToken(";"))
35
                                        break;
36
 
37
                                t.readToken(";");
38
                        }
39
                }
40
                catch (ScanException e)
41
                {
42
                        e.log("DefaultEventProcessor");
43
                }
44
 
45
                return paramList;
46
        }
47
 
48
        public static void processEvent(Menu menu, MenuItem sender, String msgType, String param)
49
        {
50
                Tokenizer t = new Tokenizer(param);
51
 
52
                try
53
                {
54
                        String command = t.readIdentifier();
55
 
56
                        if (command.equalsIgnoreCase("switchState"))
57
                        {
58
                                // stitch together identifier
59
                                String switchState = t.readIdentifier();
60
 
61
                                while (t.checkToken("."))
62
                                {
63
                                        t.readToken(".");
64
                                        switchState = switchState + "." + t.readIdentifier();
65
                                }
66
 
67
                                String switchParam = t.readUntilEndOfString();
68
 
69
                                menu.getGame().getGameStateManager().switchTo(switchState, switchParam);
70
                        }
71
/*                      else if (command.equalsIgnoreCase("fadeOut"))
72
                        {
73
                                menu.startFadeOut();
74
                        }*/
75
                        else
76
                        {
77
                                // unknown command -> skip
78
                                return;
79
                        }
80
                }
81
                catch (ScanException e)
82
                {
83
                        e.log("DefaultEventProcessor");
84
                }
85
        }
86
 
87
        // Getters/Setters==================================================================================
88
}