-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeDataSource.pde
More file actions
106 lines (82 loc) · 2.26 KB
/
Copy pathCodeDataSource.pde
File metadata and controls
106 lines (82 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
public class CodeItem {
private String codetext;
private int id;
private boolean finalScene;
private int nextSymbolID;
private String nextMarkerText;
private boolean isDummy;
public String getNextMarkerText()
{
return this.nextMarkerText;
}
public boolean getFinalScene()
{
return this.finalScene;
}
public void setFinalScene(boolean finalScene)
{
this.finalScene = finalScene;
}
public boolean getIsDummy(){
return isDummy;
}
public void setIsDummy(boolean isDummy){
this.isDummy = isDummy;
}
public void setNextMarkerText(String nextMarkerText)
{
this.nextMarkerText = nextMarkerText;
}
public int getNextSymbolId()
{
return this.nextSymbolID;
}
public void setNextSymbolId(int nextSymbolID)
{
this.nextSymbolID = nextSymbolID;
}
public CodeItem(int id, String codetext) {
this.id = id;
this.codetext = codetext;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setCodeText(String codetext) {
this.codetext = codetext;
}
public String getCodeText() {
return codetext;
}
}
public class CodeDataSource {
private JSONArray jsonObject;
public String dataJSONPath = "";
private String jsonPath = "code.json";
private HashMap<Integer, CodeItem> hashMapData;
public CodeDataSource() {
// Set the path to the JSON file
dataJSONPath = sketchPath("data/");
jsonObject = loadJSONArray(dataJSONPath+jsonPath);
hashMapData = new HashMap<Integer, CodeItem>();
}
public CodeItem getTextById(int symbolId) {
return hashMapData.get(symbolId);
}
public void parse() {
if (jsonObject != null) {
for (int code = 0; code < jsonObject.size(); code++) {
JSONObject currentCodeObject = jsonObject.getJSONObject(code);
CodeItem item = new CodeItem(currentCodeObject.getInt("id"), currentCodeObject.getString("code"));
item.setFinalScene(currentCodeObject.getBoolean("finalScene"));
item.setNextMarkerText(currentCodeObject.getString("nextMarkerText"));
item.setNextSymbolId(currentCodeObject.getInt("nextSymbolID"));
item.setIsDummy(currentCodeObject.getBoolean("isDummyData"));
hashMapData.put(item.getId(), item);
}
}
}
}