Browse Source

Dynamically set event labels

Marcus Huderle 6 years ago
parent
commit
a9325fc790
3 changed files with 51 additions and 28 deletions
  1. 20
    0
      map.cpp
  2. 7
    8
      map.h
  3. 24
    20
      project.cpp

+ 20
- 0
map.cpp View File

31
     return constantName;
31
     return constantName;
32
 }
32
 }
33
 
33
 
34
+QString Map::objectEventsLabelFromName(QString mapName)
35
+{
36
+    return QString("%1_EventObjects").arg(mapName);
37
+}
38
+
39
+QString Map::warpEventsLabelFromName(QString mapName)
40
+{
41
+    return QString("%1_MapWarps").arg(mapName);
42
+}
43
+
44
+QString Map::coordEventsLabelFromName(QString mapName)
45
+{
46
+    return QString("%1_MapCoordEvents").arg(mapName);
47
+}
48
+
49
+QString Map::bgEventsLabelFromName(QString mapName)
50
+{
51
+    return QString("%1_MapBGEvents").arg(mapName);
52
+}
53
+
34
 int Map::getWidth() {
54
 int Map::getWidth() {
35
     return layout->width.toInt(nullptr, 0);
55
     return layout->width.toInt(nullptr, 0);
36
 }
56
 }

+ 7
- 8
map.h View File

129
 public:
129
 public:
130
     void setName(QString mapName);
130
     void setName(QString mapName);
131
     static QString mapConstantFromName(QString mapName);
131
     static QString mapConstantFromName(QString mapName);
132
+    static QString objectEventsLabelFromName(QString mapName);
133
+    static QString warpEventsLabelFromName(QString mapName);
134
+    static QString coordEventsLabelFromName(QString mapName);
135
+    static QString bgEventsLabelFromName(QString mapName);
132
     int getWidth();
136
     int getWidth();
133
     int getHeight();
137
     int getHeight();
134
     Tileset* getBlockTileset(int);
138
     Tileset* getBlockTileset(int);
135
-    int getBlockIndex(int layout_id);
136
-    int getSelectedBlockIndex(int layout_id);
137
-    int getDisplayedBlockIndex(int layout_id);
139
+    int getBlockIndex(int);
140
+    int getSelectedBlockIndex(int);
141
+    int getDisplayedBlockIndex(int);
138
     Metatile* getMetatile(int);
142
     Metatile* getMetatile(int);
139
     QImage getMetatileImage(int);
143
     QImage getMetatileImage(int);
140
     QImage getMetatileTile(int);
144
     QImage getMetatileTile(int);
188
     void redo();
192
     void redo();
189
     void commit();
193
     void commit();
190
 
194
 
191
-    QString object_events_label;
192
-    QString warps_label;
193
-    QString coord_events_label;
194
-    QString bg_events_label;
195
-
196
     QList<Event*> getAllEvents();
195
     QList<Event*> getAllEvents();
197
     void removeEvent(Event *event);
196
     void removeEvent(Event *event);
198
     void addEvent(Event *event);
197
     void addEvent(Event *event);

+ 24
- 20
project.cpp View File

1185
 void Project::saveMapEvents(Map *map) {
1185
 void Project::saveMapEvents(Map *map) {
1186
     QString path = root + QString("/data/maps/%1/events.inc").arg(map->name);
1186
     QString path = root + QString("/data/maps/%1/events.inc").arg(map->name);
1187
     QString text = "";
1187
     QString text = "";
1188
+    QString objectEventsLabel = "0x0";
1189
+    QString warpEventsLabel = "0x0";
1190
+    QString coordEventsLabel = "0x0";
1191
+    QString bgEventsLabel = "0x0";
1188
 
1192
 
1189
     if (map->events["object_event_group"].length() > 0) {
1193
     if (map->events["object_event_group"].length() > 0) {
1190
-        text += QString("%1::\n").arg(map->object_events_label);
1194
+        objectEventsLabel = Map::objectEventsLabelFromName(map->name);
1195
+        text += QString("%1::\n").arg(objectEventsLabel);
1191
         for (int i = 0; i < map->events["object_event_group"].length(); i++) {
1196
         for (int i = 0; i < map->events["object_event_group"].length(); i++) {
1192
             Event *object_event = map->events["object_event_group"].value(i);
1197
             Event *object_event = map->events["object_event_group"].value(i);
1193
             text += object_event->buildObjectEventMacro(i);
1198
             text += object_event->buildObjectEventMacro(i);
1196
     }
1201
     }
1197
 
1202
 
1198
     if (map->events["warp_event_group"].length() > 0) {
1203
     if (map->events["warp_event_group"].length() > 0) {
1199
-        text += QString("%1::\n").arg(map->warps_label);
1204
+        warpEventsLabel = Map::warpEventsLabelFromName(map->name);
1205
+        text += QString("%1::\n").arg(warpEventsLabel);
1200
         for (Event *warp : map->events["warp_event_group"]) {
1206
         for (Event *warp : map->events["warp_event_group"]) {
1201
             text += warp->buildWarpEventMacro(mapNamesToMapConstants);
1207
             text += warp->buildWarpEventMacro(mapNamesToMapConstants);
1202
         }
1208
         }
1204
     }
1210
     }
1205
 
1211
 
1206
     if (map->events["coord_event_group"].length() > 0) {
1212
     if (map->events["coord_event_group"].length() > 0) {
1207
-        text += QString("%1::\n").arg(map->coord_events_label);
1213
+        coordEventsLabel = Map::coordEventsLabelFromName(map->name);
1214
+        text += QString("%1::\n").arg(coordEventsLabel);
1208
         for (Event *event : map->events["coord_event_group"]) {
1215
         for (Event *event : map->events["coord_event_group"]) {
1209
             QString event_type = event->get("event_type");
1216
             QString event_type = event->get("event_type");
1210
             if (event_type == EventType::CoordScript) {
1217
             if (event_type == EventType::CoordScript) {
1218
 
1225
 
1219
     if (map->events["bg_event_group"].length() > 0)
1226
     if (map->events["bg_event_group"].length() > 0)
1220
     {
1227
     {
1221
-        text += QString("%1::\n").arg(map->bg_events_label);
1228
+        bgEventsLabel = Map::bgEventsLabelFromName(map->name);
1229
+        text += QString("%1::\n").arg(bgEventsLabel);
1222
         for (Event *event : map->events["bg_event_group"]) {
1230
         for (Event *event : map->events["bg_event_group"]) {
1223
             QString event_type = event->get("event_type");
1231
             QString event_type = event->get("event_type");
1224
             if (event_type == EventType::Sign) {
1232
             if (event_type == EventType::Sign) {
1234
 
1242
 
1235
     text += QString("%1::\n").arg(map->events_label);
1243
     text += QString("%1::\n").arg(map->events_label);
1236
     text += QString("\tmap_events %1, %2, %3, %4\n")
1244
     text += QString("\tmap_events %1, %2, %3, %4\n")
1237
-            .arg(map->object_events_label)
1238
-            .arg(map->warps_label)
1239
-            .arg(map->coord_events_label)
1240
-            .arg(map->bg_events_label);
1245
+            .arg(objectEventsLabel)
1246
+            .arg(warpEventsLabel)
1247
+            .arg(coordEventsLabel)
1248
+            .arg(bgEventsLabel);
1241
 
1249
 
1242
     saveTextFile(path, text);
1250
     saveTextFile(path, text);
1243
 }
1251
 }
1255
     }
1263
     }
1256
 
1264
 
1257
     QStringList *labels = getLabelValues(parseAsm(text), map->events_label);
1265
     QStringList *labels = getLabelValues(parseAsm(text), map->events_label);
1258
-    map->object_events_label = labels->value(0);
1259
-    map->warps_label = labels->value(1);
1260
-    map->coord_events_label = labels->value(2);
1261
-    map->bg_events_label = labels->value(3);
1266
+    QString objectEventsLabel = labels->value(0);
1267
+    QString warpEventsLabel = labels->value(1);
1268
+    QString coordEventsLabel = labels->value(2);
1269
+    QString bgEventsLabel = labels->value(3);
1262
 
1270
 
1263
-    QList<QStringList> *object_events = getLabelMacros(parseAsm(text), map->object_events_label);
1271
+    QList<QStringList> *object_events = getLabelMacros(parseAsm(text), objectEventsLabel);
1264
     map->events["object_event_group"].clear();
1272
     map->events["object_event_group"].clear();
1265
     for (QStringList command : *object_events) {
1273
     for (QStringList command : *object_events) {
1266
         if (command.value(0) == "object_event") {
1274
         if (command.value(0) == "object_event") {
1285
         }
1293
         }
1286
     }
1294
     }
1287
 
1295
 
1288
-    QList<QStringList> *warps = getLabelMacros(parseAsm(text), map->warps_label);
1296
+    QList<QStringList> *warps = getLabelMacros(parseAsm(text), warpEventsLabel);
1289
     map->events["warp_event_group"].clear();
1297
     map->events["warp_event_group"].clear();
1290
     for (QStringList command : *warps) {
1298
     for (QStringList command : *warps) {
1291
         if (command.value(0) == "warp_def") {
1299
         if (command.value(0) == "warp_def") {
1310
         }
1318
         }
1311
     }
1319
     }
1312
 
1320
 
1313
-    QList<QStringList> *coords = getLabelMacros(parseAsm(text), map->coord_events_label);
1321
+    QList<QStringList> *coords = getLabelMacros(parseAsm(text), coordEventsLabel);
1314
     map->events["coord_event_group"].clear();
1322
     map->events["coord_event_group"].clear();
1315
     for (QStringList command : *coords) {
1323
     for (QStringList command : *coords) {
1316
         if (command.value(0) == "coord_event") {
1324
         if (command.value(0) == "coord_event") {
1349
         }
1357
         }
1350
     }
1358
     }
1351
 
1359
 
1352
-    QList<QStringList> *bgs = getLabelMacros(parseAsm(text), map->bg_events_label);
1360
+    QList<QStringList> *bgs = getLabelMacros(parseAsm(text), bgEventsLabel);
1353
     map->events["bg_event_group"].clear();
1361
     map->events["bg_event_group"].clear();
1354
     for (QStringList command : *bgs) {
1362
     for (QStringList command : *bgs) {
1355
         if (command.value(0) == "bg_event") {
1363
         if (command.value(0) == "bg_event") {
1394
 }
1402
 }
1395
 
1403
 
1396
 void Project::setNewMapEvents(Map *map) {
1404
 void Project::setNewMapEvents(Map *map) {
1397
-    map->object_events_label = "0x0";
1398
-    map->warps_label = "0x0";
1399
-    map->coord_events_label = "0x0";
1400
-    map->bg_events_label = "0x0";
1401
     map->events["object_event_group"].clear();
1405
     map->events["object_event_group"].clear();
1402
     map->events["warp_event_group"].clear();
1406
     map->events["warp_event_group"].clear();
1403
     map->events["coord_event_group"].clear();
1407
     map->events["coord_event_group"].clear();