-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStage.java
173 lines (158 loc) · 4.93 KB
/
Stage.java
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import processing.core.*;
import processing.data.*;
import java.util.ArrayList;
class Stage implements Serialization {
public static final Identifier ID = new Identifier("Stage");
static transient skiny_mann source;
public ArrayList<StageComponent> parts = new ArrayList<>(), interactables=new ArrayList<>();
public ArrayList<StageEntity> entities = new ArrayList<>();
public boolean is3D=false;
public String type, name;
public int stageID, skyColor=-9131009;
Stage(JSONArray file) {//single varible instance for a stage
load(file);
}
Stage(String Name, String Type) {
name=Name;
type=Type;
is3D=type.equals("3Dstage")||type.equals("3D blueprint");
}
public Stage(SerialIterator iterator){
parts = iterator.getArrayList();
entities = iterator.getArrayList();
is3D = iterator.getBoolean();
type = iterator.getString();
name = iterator.getString();
stageID = iterator.getInt();
skyColor = iterator.getInt();
}
void load(JSONArray file) {
type=file.getJSONObject(0).getString("type");
name=file.getJSONObject(0).getString("name");
try {
skyColor=file.getJSONObject(0).getInt("sky color");
}
catch(Throwable e) {
}
if (type.equals("stage")||type.equals("3Dstage")||type.equals("blueprint")||type.equals("3D blueprint")) {
is3D=type.equals("3Dstage")||type.equals("3D blueprint");
for (int i=1; i<file.size(); i++) {
try {
JSONObject ob=file.getJSONObject(i);
String otype=ob.getString("type");
if (otype.equals("ground")) {
parts.add(new Ground(ob, is3D));
}
else if (otype.equals("holo")) {
parts.add(new Holo(ob, is3D));
}
else if (otype.equals("dethPlane")) {
parts.add(new DethPlane(ob, is3D));
}
else if (otype.equals("check point")) {
parts.add(new CheckPoint(ob, is3D));
}
else if (otype.equals("goal")) {
parts.add(new Goal(ob, is3D));
}
else if (otype.equals("coin")) {
parts.add(new Coin(ob, is3D));
}
else if (otype.equals("interdimentional Portal")) {
parts.add(new Interdimentional_Portal(ob, is3D));
}
else if (otype.equals("sloap")) {
parts.add(new Sloap(ob, is3D));
}
else if (otype.equals("holoTriangle")) {
parts.add(new HoloTriangle(ob, is3D));
}
else if (otype.equals("3DonSW")) {
parts.add(new SWon3D(ob, is3D));
}
else if (otype.equals("3DoffSW")) {
parts.add(new SWoff3D(ob, is3D));
}
else if (otype.equals("WritableSign")) {
parts.add(new WritableSign(ob, is3D));
}
else if (otype.equals("sound box")) {
parts.add(new SoundBox(ob, is3D));
}
else if (otype.equals("logic button")) {
parts.add(new LogicButton(ob, is3D));
interactables.add(parts.get(parts.size()-1));
}
else{
//if the current thing is an entity, load it
StageEntity ent = source.entityRegistry.get(otype);
if(ent!=null){
entities.add(ent.create(ob,this));
}
}
}
catch(Throwable e) {
}
}
}
}
String save() {
JSONArray staeg = new JSONArray();
JSONObject head=new JSONObject();
head.setString("name", name);
head.setString("type", type);
head.setInt("sky color", skyColor);
staeg.setJSONObject(0, head);
for (int i=0; i<parts.size(); i++) {
staeg.append(parts.get(i).save(is3D));
}
for(int i=0;i<entities.size();i++){
staeg.append(entities.get(i).save());
}
source.saveJSONArray(staeg, source.rootPath+"/"+name+".json");
return "/"+name+".json";
}
void respawnEntities(){
for(StageEntity se : entities){
se.respawn();
}
}
@Override
public SerializedData serialize() {
SerializedData data = new SerializedData(id());
data.addObject(SerializedData.ofArrayList(parts,new Identifier("StageComponent")));
data.addObject(SerializedData.ofArrayList(entities,new Identifier("StageEntity")));
data.addBool(is3D);
data.addObject(SerializedData.ofString(type));
data.addObject(SerializedData.ofString(name));
data.addInt(stageID);
data.addInt(skyColor);
return data;
}
@Override
public Identifier id() {
return ID;
}
public boolean equals(Object o){
if(o instanceof Stage){
Stage s = (Stage)o;
if(!s.name.equals(name)){
return false;
}
if(!s.type.equals(type)){
return false;
}
if(stageID!=s.stageID){
return false;
}
if(skyColor!=s.skyColor){
return false;
}
if(parts.size()!=s.parts.size()){
return false;
}
return true;
}
return false;
}
}