Repository navigation
Expand file tree
/
Copy pathfile_rw_lvlx.cpp
More file actions
2611 lines (2284 loc) · 115 KB
/
Copy pathfile_rw_lvlx.cpp
File metadata and controls
2611 lines (2284 loc) · 115 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Platformer Game Engine by Wohlstand, a free platform for game making
* Copyright (c) 2014-2020 Vitaly Novichkov <admin@wohlnet.ru>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pge_file_lib_sys.h"
#include "file_formats.h"
#include "file_strlist.h"
#include "pge_x.h"
#include "pge_x_macro.h"
#include <cfloat>
//*********************************************************
//****************READ FILE FORMAT*************************
//*********************************************************
bool FileFormats::ReadExtendedLvlFileHeader(PGESTRING filePath, LevelData &FileData)
{
CreateLevelHeader(FileData);
FileData.meta.RecentFormat = LevelData::PGEX;
PGE_FileFormats_misc::TextFileInput inf;
if(!inf.open(filePath, true))
{
FileData.meta.ERROR_info = "Can't open file";
FileData.meta.ReadFileValid = false;
return false;
}
return ReadExtendedLvlFileHeaderT(inf, FileData);
}
bool FileFormats::ReadExtendedLvlFileHeaderRaw(PGESTRING &rawdata, PGESTRING filePath, LevelData &FileData)
{
CreateLevelHeader(FileData);
FileData.meta.RecentFormat = LevelData::PGEX;
PGE_FileFormats_misc::RawTextInput inf;
if(!inf.open(&rawdata, filePath))
{
FileData.meta.ERROR_info = "Can't open file";
FileData.meta.ReadFileValid = false;
return false;
}
return ReadExtendedLvlFileHeaderT(inf, FileData);
}
bool FileFormats::ReadExtendedLvlFileHeaderT(PGE_FileFormats_misc::TextInput &inf, LevelData &FileData)
{
PGESTRING line;
int str_count = 0;
bool valid = false;
PGE_FileFormats_misc::FileInfo in_1(inf.getFilePath());
FileData.meta.filename = in_1.basename();
FileData.meta.path = in_1.dirpath();
#define NextLine(line) str_count++;line = inf.readLine();
//Find level header part
do
{
str_count++;
NextLine(line);
}
while((line != "HEAD") && (!IsNULL(line)));
PGESTRINGList header;
bool closed = false;
if(line != "HEAD")//Header not found, this level is head-less
goto skipHeaderParse;
NextLine(line);
while((line != "HEAD_END") && (!IsNULL(line)))
{
header.push_back(line);
str_count++;
NextLine(line);
if(line == "HEAD_END")
closed = true;
}
if(!closed)
goto badfile;
for(pge_size_t qq = 0; qq < header.size(); qq++)
{
PGESTRING &header_line = header[qq];
PGELIST<PGESTRINGList >data = PGEFile::splitDataLine(header_line, &valid);
for(pge_size_t i = 0; i < data.size(); i++)
{
if(data[i].size() != 2)
goto badfile;
if(data[i][0] == "TL") //Level Title
{
if(PGEFile::IsQoutedString(data[i][1]))
FileData.LevelName = PGEFile::X2STRING(data[i][1]);
else
goto badfile;
}
else if(data[i][0] == "SZ") //Starz number
{
if(PGEFile::IsIntU(data[i][1]))
FileData.stars = toInt(data[i][1]);
else
goto badfile;
}
else if(data[i][0] == "DL") //Open Level on player's fail
{
if(PGEFile::IsQoutedString(data[i][1]))
FileData.open_level_on_fail = PGEFile::X2STRING(data[i][1]);
else
goto badfile;
}
else if(data[i][0] == "DE") //Target WarpID of fail-level entrace
{
if(PGEFile::IsIntU(data[i][1]))
FileData.open_level_on_fail_warpID = toUInt(data[i][1]);
else
goto badfile;
}
else if(data[i][0] == "NO") //Overrides of player names
{
if(PGEFile::IsStringArray(data[i][1]))
FileData.player_names_overrides = PGEFile::X2STRArr(data[i][1]);
else
goto badfile;
}
else if(data[i][0] == "XTRA") //Extra settings
{
if(PGEFile::IsQoutedString(data[i][1]))
FileData.custom_params = PGEFile::X2STRING(data[i][1]);
else
goto badfile;
}
}
}
skipHeaderParse:
FileData.CurSection = 0;
FileData.playmusic = 0;
FileData.meta.ReadFileValid = true;
return true;
badfile:
FileData.meta.ERROR_info = "Invalid file format";
FileData.meta.ERROR_linenum = static_cast<long>(str_count);
FileData.meta.ERROR_linedata = line;
FileData.meta.ReadFileValid = false;
PGE_CutLength(FileData.meta.ERROR_linedata, 50);
PGE_FilterBinary(FileData.meta.ERROR_linedata);
return false;
}
bool FileFormats::ReadExtendedLvlFileF(PGESTRING filePath, LevelData &FileData)
{
FileData.meta.ERROR_info.clear();
PGE_FileFormats_misc::TextFileInput file;
if(!file.open(filePath, true))
{
FileData.meta.ERROR_info = "Failed to open file for read";
FileData.meta.ERROR_linedata = "";
FileData.meta.ERROR_linenum = -1;
FileData.meta.ReadFileValid = false;
return false;
}
return ReadExtendedLvlFile(file, FileData);
}
bool FileFormats::ReadExtendedLvlFileRaw(PGESTRING &rawdata, PGESTRING filePath, LevelData &FileData)
{
FileData.meta.ERROR_info.clear();
PGE_FileFormats_misc::RawTextInput file;
if(!file.open(&rawdata, filePath))
{
FileData.meta.ERROR_info = "Failed to open raw string for read";
FileData.meta.ERROR_linedata = "";
FileData.meta.ERROR_linenum = -1;
FileData.meta.ReadFileValid = false;
return false;
}
return ReadExtendedLvlFile(file, FileData);
}
bool FileFormats::ReadExtendedLvlFile(PGE_FileFormats_misc::TextInput &in, LevelData &FileData)
{
PGESTRING errorString;
PGESTRING filePath = in.getFilePath();
PGESTRING line; /*Current Line data*/
//LevelData FileData;
CreateLevelData(FileData);
FileData.meta.RecentFormat = LevelData::PGEX;
//Add path data
if(filePath.size() > 0)
{
PGE_FileFormats_misc::FileInfo in_1(filePath);
FileData.meta.filename = in_1.basename();
FileData.meta.path = in_1.dirpath();
}
FileData.meta.untitled = false;
FileData.meta.modified = false;
LevelSection lvl_section;
PlayerPoint player;
LevelBlock block;
LevelBGO bgodata;
LevelNPC npcdata;
LevelDoor door;
LevelPhysEnv physiczone;
LevelLayer layer;
LevelSMBX64Event event;
LevelVariable variable;
LevelArray array_field;
LevelScript script;
LevelItemSetup38A customcfg38A;
///////////////////////////////////////Begin file///////////////////////////////////////
PGEX_FileParseTree(in.readAll());
PGEX_FetchSection() //look sections
{
PGEX_FetchSection_begin()
///////////////////HEADER//////////////////////
PGEX_Section("HEAD")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_StrVal("TL", FileData.LevelName) //Level Title
PGEX_USIntVal("SZ", FileData.stars) //Starz number
PGEX_StrVal("DL", FileData.open_level_on_fail) //Open level on fail
PGEX_UIntVal("DE", FileData.open_level_on_fail_warpID) //Open level's warpID on fail
PGEX_StrArrVal("NO", FileData.player_names_overrides) //Overrides of player names
PGEX_StrVal("XTRA", FileData.custom_params) //Level-wide Extra settings
}
}
}//HEADER
///////////////////////////////MetaDATA/////////////////////////////////////////////
PGEX_Section("META_BOOKMARKS")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
Bookmark meta_bookmark;
meta_bookmark.bookmarkName.clear();
meta_bookmark.x = 0;
meta_bookmark.y = 0;
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_StrVal("BM", meta_bookmark.bookmarkName) //Bookmark name
PGEX_FloatVal("X", meta_bookmark.x) // Position X
PGEX_FloatVal("Y", meta_bookmark.y) // Position Y
}
FileData.metaData.bookmarks.push_back(meta_bookmark);
}
}
////////////////////////meta bookmarks////////////////////////
PGEX_Section("META_SYS_CRASH")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
FileData.metaData.crash.used = true;
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_BoolVal("UT", FileData.metaData.crash.untitled) //Untitled
PGEX_BoolVal("MD", FileData.metaData.crash.modifyed) //Modyfied
PGEX_SIntVal("FF", FileData.metaData.crash.fmtID) //Recent File format
PGEX_UIntVal("FV", FileData.metaData.crash.fmtVer) //Recent File format version
PGEX_StrVal("N", FileData.metaData.crash.filename) //Filename
PGEX_StrVal("P", FileData.metaData.crash.path) //Path
PGEX_StrVal("FP", FileData.metaData.crash.fullPath) //Full file Path
}
}
}//meta sys crash
///////////////////////////////MetaDATA//End////////////////////////////////////////
///////////////////SECTION//////////////////////
PGEX_Section("SECTION")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
lvl_section = CreateLvlSection();
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_USIntVal("SC", lvl_section.id) //Section ID
PGEX_SLongVal("L", lvl_section.size_left) //Left side
PGEX_SLongVal("R", lvl_section.size_right)//Right side
PGEX_SLongVal("T", lvl_section.size_top) //Top side
PGEX_SLongVal("B", lvl_section.size_bottom)//Bottom side
PGEX_UIntVal("MZ", lvl_section.music_id)//Built-in music ID
PGEX_UIntVal("BG", lvl_section.background)//Built-in background ID
PGEX_SIntVal("LT", lvl_section.lighting_value)//Lighting value
PGEX_StrVal("MF", lvl_section.music_file) //External music file path
PGEX_BoolVal("CS", lvl_section.wrap_h)//Connect sides horizontally
PGEX_BoolVal("CSV", lvl_section.wrap_v)//Connect sides vertically
PGEX_BoolVal("OE", lvl_section.OffScreenEn)//Offscreen exit
PGEX_BoolVal("SR", lvl_section.lock_left_scroll)//Right-way scroll only (No Turn-back)
PGEX_BoolVal("SL", lvl_section.lock_right_scroll)//Left-way scroll only (No Turn-forward)
PGEX_BoolVal("SD", lvl_section.lock_up_scroll)//Down-way scroll only (No Turn-forward)
PGEX_BoolVal("SU", lvl_section.lock_down_scroll)//Up-way scroll only (No Turn-forward)
PGEX_BoolVal("UW", lvl_section.underwater)//Underwater bit
PGEX_StrVal("XTRA", lvl_section.custom_params)//Custom JSON data tree
}
lvl_section.PositionX = lvl_section.size_left - 10;
lvl_section.PositionY = lvl_section.size_top - 10;
//add captured value into array
bool found = false;
pge_size_t q = 0;
pge_size_t sections_count = FileData.sections.size();
if(lvl_section.id >= (int)sections_count)
{
pge_size_t needToAdd = (FileData.sections.size() - 1) - static_cast<pge_size_t>(lvl_section.id);
while(needToAdd > 0)
{
LevelSection dummySct = CreateLvlSection();
dummySct.id = (int)FileData.sections.size();
FileData.sections.push_back(dummySct);
needToAdd--;
}
}
for(q = 0; q < sections_count; q++)
{
if(FileData.sections[q].id == lvl_section.id)
{
found = true;
break;
}
}
if(found)
FileData.sections[q] = lvl_section;
else
FileData.sections.push_back(lvl_section);
}
}//SECTION
///////////////////STARTPOINT//////////////////////
PGEX_Section("STARTPOINT")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
player = CreateLvlPlayerPoint();
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_UIntVal("ID", player.id) //ID of player point
PGEX_SLongVal("X", player.x)
PGEX_SLongVal("Y", player.y)
PGEX_SIntVal("D", player.direction)
}
//add captured value into array
bool found = false;
pge_size_t q = 0;
pge_size_t playersCount = FileData.players.size();
for(q = 0; q < playersCount; q++)
{
if(FileData.players[q].id == player.id)
{
found = true;
break;
}
}
PlayerPoint sz = CreateLvlPlayerPoint(player.id);
player.w = sz.w;
player.h = sz.h;
if(found)
FileData.players[q] = player;
else
FileData.players.push_back(player);
}
}//STARTPOINT
///////////////////BLOCK//////////////////////
PGEX_Section("BLOCK")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
block = CreateLvlBlock();
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_ULongVal("ID", block.id) //Block ID
PGEX_SLongVal("X", block.x) // Position X
PGEX_SLongVal("Y", block.y) //Position Y
PGEX_USLongVal("W", block.w) //Width
PGEX_USLongVal("H", block.h) //Height
PGEX_BoolVal("AS", block.autoscale)//Enable auto-Scaling
PGEX_StrVal("GXN", block.gfx_name) //38A GFX-Name
PGEX_SLongVal("GXX", block.gfx_dx) //38A graphics extend x
PGEX_SLongVal("GXY", block.gfx_dy) //38A graphics extend y
PGEX_SLongVal("CN", block.npc_id) //Contains (coins/NPC)
PGEX_SLongVal("CS", block.npc_special_value) //Special value for contained NPC
PGEX_BoolVal("IV", block.invisible) //Invisible
PGEX_BoolVal("SL", block.slippery) //Slippery
PGEX_StrVal("LR", block.layer) //Layer name
PGEX_StrVal("ED", block.event_destroy) //Destroy event slot
PGEX_StrVal("EH", block.event_hit) //Hit event slot
PGEX_StrVal("EE", block.event_emptylayer) //Hit event slot
PGEX_StrVal("XTRA", block.meta.custom_params)//Custom JSON data tree
}
block.meta.array_id = FileData.blocks_array_id++;
block.meta.index = static_cast<unsigned int>(FileData.blocks.size());
FileData.blocks.push_back(block);
}
}//BLOCK
///////////////////BGO//////////////////////
PGEX_Section("BGO")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
bgodata = CreateLvlBgo();
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_ULongVal("ID", bgodata.id) //BGO ID
PGEX_SLongVal("X", bgodata.x) //X Position
PGEX_SLongVal("Y", bgodata.y) //Y Position
PGEX_SLongVal("GXX", bgodata.gfx_dx) //38A graphics extend x
PGEX_SLongVal("GXY", bgodata.gfx_dy) //38A graphics extend y
PGEX_FloatVal("ZO", bgodata.z_offset) //Z Offset
PGEX_SIntVal("ZP", bgodata.z_mode) //Z Position
PGEX_SLongVal("SP", bgodata.smbx64_sp) //SMBX64 Sorting priority
PGEX_StrVal("LR", bgodata.layer) //Layer name
PGEX_StrVal("XTRA", bgodata.meta.custom_params)//Custom JSON data tree
}
bgodata.meta.array_id = FileData.bgo_array_id++;
bgodata.meta.index = static_cast<unsigned int>(FileData.bgo.size());
FileData.bgo.push_back(bgodata);
}
}//BGO
///////////////////NPC//////////////////////
PGEX_Section("NPC")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
npcdata = CreateLvlNpc();
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_ULongVal("ID", npcdata.id) //NPC ID
PGEX_SLongVal("X", npcdata.x) //X position
PGEX_SLongVal("Y", npcdata.y) //Y position
PGEX_StrVal("GXN", npcdata.gfx_name) //38A GFX-Name
PGEX_SLongVal("GXX", npcdata.gfx_dx) //38A graphics extend x
PGEX_SLongVal("GXY", npcdata.gfx_dy) //38A graphics extend y
PGEX_SLongVal("OW", npcdata.override_width) //Override width
PGEX_SLongVal("OH", npcdata.override_height) //Override height
PGEX_BoolVal("GAS", npcdata.gfx_autoscale) //Autoscale GFX on size override
PGEX_SLongVal("WGT", npcdata.wings_type) //38A: Wings type
PGEX_SLongVal("WGS", npcdata.wings_style) //38A: Wings style
PGEX_SIntVal("D", npcdata.direct) //Direction
PGEX_SLongVal("CN", npcdata.contents) //Contents of container-NPC
PGEX_SLongVal("S1", npcdata.special_data) //Special value 1
PGEX_SLongVal("S2", npcdata.special_data2) //Special value 2
PGEX_BoolVal("GE", npcdata.generator) //Generator
PGEX_SIntVal("GT", npcdata.generator_type) //Generator type
PGEX_SIntVal("GD", npcdata.generator_direct) //Generator direction
PGEX_USIntVal("GM", npcdata.generator_period) //Generator period
PGEX_FloatVal("GA", npcdata.generator_custom_angle) //Generator custom angle
PGEX_USIntVal("GB", npcdata.generator_branches) //Generator number of branches
PGEX_FloatVal("GR", npcdata.generator_angle_range) //Generator angle range
PGEX_FloatVal("GS", npcdata.generator_initial_speed) //Generator custom initial speed
PGEX_StrVal("MG", npcdata.msg) //Message
PGEX_BoolVal("FD", npcdata.friendly) //Friendly
PGEX_BoolVal("NM", npcdata.nomove) //Don't move
PGEX_BoolVal("BS", npcdata.is_boss) //Enable boss mode!
PGEX_StrVal("LR", npcdata.layer) //Layer
PGEX_StrVal("LA", npcdata.attach_layer) //Attach Layer
PGEX_StrVal("SV", npcdata.send_id_to_variable) //Send ID to variable
PGEX_StrVal("EA", npcdata.event_activate) //Event slot "Activated"
PGEX_StrVal("ED", npcdata.event_die) //Event slot "Death/Take/Destroy"
PGEX_StrVal("ET", npcdata.event_talk) //Event slot "Talk"
PGEX_StrVal("EE", npcdata.event_emptylayer) //Event slot "Layer is empty"
PGEX_StrVal("EG", npcdata.event_grab)//Event slot "On grab"
PGEX_StrVal("EO", npcdata.event_touch)//Event slot "On touch"
PGEX_StrVal("EF", npcdata.event_nextframe)//Evemt slot "Trigger every frame"
PGEX_StrVal("XTRA", npcdata.meta.custom_params)//Custom JSON data tree
}
npcdata.meta.array_id = FileData.npc_array_id++;
npcdata.meta.index = static_cast<unsigned int>(FileData.npc.size());
FileData.npc.push_back(npcdata);
}
}//TILES
///////////////////PHYSICS//////////////////////
PGEX_Section("PHYSICS")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
physiczone = CreateLvlPhysEnv();
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_USIntVal("ET", physiczone.env_type) //Environment type
PGEX_SLongVal("X", physiczone.x) //X position
PGEX_SLongVal("Y", physiczone.y) //Y position
PGEX_USLongVal("W", physiczone.w) //Width
PGEX_USLongVal("H", physiczone.h) //Height
PGEX_StrVal("LR", physiczone.layer) //Layer
PGEX_FloatVal("FR", physiczone.friction) //Friction
PGEX_FloatVal("AD", physiczone.accel_direct) //Custom acceleration direction
PGEX_FloatVal("AC", physiczone.accel) //Custom acceleration
PGEX_FloatVal("MV", physiczone.max_velocity) //Maximal velocity
PGEX_StrVal("EO", physiczone.touch_event) //Touch event/script
PGEX_StrVal("XTRA", physiczone.meta.custom_params)//Custom JSON data tree
}
physiczone.meta.array_id = FileData.physenv_array_id++;
physiczone.meta.index = static_cast<unsigned int>(FileData.physez.size());
FileData.physez.push_back(physiczone);
}
}//PHYSICS
///////////////////DOORS//////////////////////
PGEX_Section("DOORS")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
door = CreateLvlWarp();
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_SLongVal("IX", door.ix) //Input point
PGEX_SLongVal("IY", door.iy) //Input point
PGEX_SLongVal("OX", door.ox) //Output point
PGEX_SLongVal("OY", door.oy) //Output point
PGEX_UIntVal("IL", door.length_i) //Length of entrance (input) point
PGEX_UIntVal("OL", door.length_o) //Length of exit (output) point
PGEX_USIntVal("DT", door.type) //Input point
PGEX_USIntVal("ID", door.idirect) //Input direction
PGEX_USIntVal("OD", door.odirect) //Output direction
PGEX_SLongVal("WX", door.world_x) //Target world map point
PGEX_SLongVal("WY", door.world_y) //Target world map point
PGEX_StrVal("LF", door.lname) //Target level file
PGEX_USLongVal("LI", door.warpto) //Target level file's input warp
PGEX_BoolVal("ET", door.lvl_i) //Level Entrance
PGEX_BoolVal("EX", door.lvl_o) //Level exit
PGEX_USIntVal("SL", door.stars) //Stars limit
PGEX_StrVal("SM", door.stars_msg) //Message about stars/leeks
PGEX_BoolVal("NV", door.novehicles) //No Vehicles
PGEX_BoolVal("SH", door.star_num_hide) //Don't show stars number
PGEX_BoolVal("AI", door.allownpc) //Allow grabbed items
PGEX_BoolVal("LC", door.locked) //Door is locked
PGEX_BoolVal("LB", door.need_a_bomb) //Door is blocked, need bomb to unlock
PGEX_BoolVal("HS", door.hide_entering_scene) //Don't show entering scene
PGEX_BoolVal("AL", door.allownpc_interlevel) //Allow NPC's inter-level
PGEX_BoolVal("SR", door.special_state_required) //Required a special state to enter
PGEX_BoolVal("STR", door.stood_state_required) //Required a stood state to enter
PGEX_BoolVal("PT", door.cannon_exit) //Cannon exit
PGEX_FloatVal("PS", door.cannon_exit_speed) //Cannon exit speed
PGEX_StrVal("LR", door.layer) //Layer
PGEX_StrVal("EE", door.event_enter) //On-Enter event slot
PGEX_BoolVal("TW", door.two_way) //Two-way warp
PGEX_StrVal("XTRA", door.meta.custom_params)//Custom JSON data tree
}
door.isSetIn = (!door.lvl_i);
door.isSetOut = (!door.lvl_o || (door.lvl_i));
if(!door.isSetIn && door.isSetOut)
{
door.ix = door.ox;
door.iy = door.oy;
}
if(!door.isSetOut && door.isSetIn)
{
door.ox = door.ix;
door.oy = door.iy;
}
door.meta.array_id = FileData.doors_array_id++;
door.meta.index = static_cast<unsigned int>(FileData.doors.size());
FileData.doors.push_back(door);
}
}//DOORS
///////////////////LAYERS//////////////////////
PGEX_Section("LAYERS")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
layer = CreateLvlLayer();
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_StrVal("LR", layer.name) //Layer name
PGEX_BoolVal("HD", layer.hidden) //Hidden
PGEX_BoolVal("LC", layer.locked) //Locked
}
//add captured value into array
bool found = false;
pge_size_t q = 0;
for(q = 0; q < FileData.layers.size(); q++)
{
if(FileData.layers[q].name == layer.name)
{
found = true;
break;
}
}
if(found)
{
layer.meta.array_id = FileData.layers[q].meta.array_id;
FileData.layers[q] = layer;
}
else
{
layer.meta.array_id = FileData.layers_array_id++;
FileData.layers.push_back(layer);
}
}
}//LAYERS
//EVENTS comming soon
// else
// if(sct.first=="EVENTS_CLASSIC") //Action-styled events
// {
// foreach(PGESTRINGList value, sectData) //Look markers and values
// {
// // if(v.marker=="TL") //Level Title
// // {
// // if(PGEFile::IsQStr(v.value))
// // FileData.LevelName = PGEFile::X2STR(v.value);
// // else
// // goto badfile;
// // }
// // else
// // if(v.marker=="SZ") //Starz number
// // {
// // if(PGEFile::IsIntU(v.value))
// // FileData.stars = toInt(v.value);
// // else
// // goto badfile;
// // }
// }
// }//EVENTS
///////////////////EVENTS_CLASSIC//////////////////////
PGEX_Section("EVENTS_CLASSIC")
{
PGEX_SectionBegin(PGEFile::PGEX_Struct);
PGEX_Items()
{
PGEX_ItemBegin(PGEFile::PGEX_Struct);
event = CreateLvlEvent();
PGESTRINGList musicSets;
PGESTRINGList bgSets;
PGESTRINGList ssSets;
PGESTRINGList movingLayers;
PGESTRINGList newSectionSettingsSets;
PGESTRINGList spawnNPCs;
PGESTRINGList spawnEffectss;
PGESTRINGList variablesToUpdate;
PGELIST<bool > controls;
PGEX_Values() //Look markers and values
{
PGEX_ValueBegin()
PGEX_StrVal("ET", event.name) //Event Title
PGEX_StrVal("MG", event.msg) //Event Message
PGEX_USLongVal("SD", event.sound_id) //Play Sound ID
PGEX_USLongVal("EG", event.end_game) //End game algorithm
PGEX_StrArrVal("LH", event.layers_hide) //Hide layers
PGEX_StrArrVal("LS", event.layers_show) //Show layers
PGEX_StrArrVal("LT", event.layers_toggle) //Toggle layers
//Legacy values (without SMBX-38A values support)
PGEX_StrArrVal("SM", musicSets) //Switch music
PGEX_StrArrVal("SB", bgSets) //Switch background
PGEX_StrArrVal("SS", ssSets) //Section Size
//-------------------
//New values (with SMBX-38A values support)
PGEX_StrArrVal("SSS", newSectionSettingsSets) //Section settings in new format
//-------------------
//---SMBX-38A entries-----
PGEX_StrArrVal("MLA", movingLayers) //NPC's to spawn
PGEX_StrArrVal("SNPC", spawnNPCs) //NPC's to spawn
PGEX_StrArrVal("SEF", spawnEffectss) //Effects to spawn
PGEX_StrArrVal("UV", variablesToUpdate) //Variables to update
PGEX_StrVal("TSCR", event.trigger_script) //Trigger script
PGEX_USIntVal("TAPI", event.trigger_api_id) //Trigger script
PGEX_BoolVal("TMR", event.timer_def.enable) //Enable timer
PGEX_USLongVal("TMC", event.timer_def.count) //Count of timer units
PGEX_FloatVal("TMI", event.timer_def.interval) //Interval of timer tick
PGEX_USIntVal("TMD", event.timer_def.count_dir) //Direction of count
PGEX_BoolVal("TMV", event.timer_def.show) //Show timer on screen
//-------------------
PGEX_StrVal("TE", event.trigger) //Trigger event
PGEX_USLongVal("TD", event.trigger_timer) //Trigger delay
PGEX_BoolVal("DS", event.nosmoke) //Disable smoke
PGEX_USIntVal("AU", event.autostart) //Auto start
PGEX_StrVal("AUC", event.autostart_condition) //Auto start condition
PGEX_BoolArrVal("PC", controls) //Player controls
PGEX_StrVal("ML", event.movelayer) //Move layer
PGEX_FloatVal("MX", event.layer_speed_x) //Layer motion speed X
PGEX_FloatVal("MY", event.layer_speed_y) //Layer motion speed Y
PGEX_SLongVal("AS", event.scroll_section) //Autoscroll section ID
PGEX_FloatVal("AX", event.move_camera_x) //Autoscroll speed X
PGEX_FloatVal("AY", event.move_camera_y) //Autoscroll speed Y
}
//Parse new-style parameters
if(!newSectionSettingsSets.empty())
{
for(pge_size_t q = 0; q < newSectionSettingsSets.size(); q++)
{
LevelEvent_Sets sectionSet;
bool valid = false;
PGELIST<PGESTRINGList> sssData = PGEFile::splitDataLine(newSectionSettingsSets[q], &valid);
if(!valid)
{
errorString = "Wrong section settings event encoded sub-entry";
goto badfile;
}
for(pge_size_t ssi = 0; ssi < sssData.size(); ssi++)
{
PGESTRINGList ¶m = sssData[ssi];
if(param[0] == "ID")
{
errorString = "Invalid sectionID value type";
if(PGEFile::IsIntU(param[1]))
sectionSet.id = toLong(param[1]);
else
goto badfile;
}
else if(param[0] == "SL")
{
errorString = "Invalid Section size left value type";
if(PGEFile::IsIntS(param[1]))
sectionSet.position_left = toLong(param[1]);
else
goto badfile;
}
else if(param[0] == "ST")
{
errorString = "Invalid Section size top value type";
if(PGEFile::IsIntS(param[1]))
sectionSet.position_top = toLong(param[1]);
else
goto badfile;
}
else if(param[0] == "SB")
{
errorString = "Invalid Section size bottom value type";
if(PGEFile::IsIntS(param[1]))
sectionSet.position_bottom = toLong(param[1]);
else
goto badfile;
}
else if(param[0] == "SR")
{
errorString = "Invalid Section size right value type";
if(PGEFile::IsIntS(param[1]))
sectionSet.position_right = toLong(param[1]);
else
goto badfile;
}
else if(param[0] == "SXX")
{
errorString = "Invalid Section pos x expression value type";
if(PGEFile::IsQoutedString(param[1]))
sectionSet.expression_pos_x = PGEFile::X2STRING(param[1]);
else
goto badfile;
}
else if(param[0] == "SYX")
{
errorString = "Invalid Section pos y expression value type";
if(PGEFile::IsQoutedString(param[1]))
sectionSet.expression_pos_y = PGEFile::X2STRING(param[1]);
else
goto badfile;
}
else if(param[0] == "SWX")
{
errorString = "Invalid Section pos w expression value type";
if(PGEFile::IsQoutedString(param[1]))
sectionSet.expression_pos_w = PGEFile::X2STRING(param[1]);
else
goto badfile;
}
else if(param[0] == "SWH")
{
errorString = "Invalid Section pos h expression value type";
if(PGEFile::IsQoutedString(param[1]))
sectionSet.expression_pos_h = PGEFile::X2STRING(param[1]);
else
goto badfile;
}
else if(param[0] == "MI")
{
errorString = "Invalid Section music ID value type";
if(PGEFile::IsIntS(param[1]))
sectionSet.music_id = toLong(param[1]);
else
goto badfile;
}
else if(param[0] == "MF")
{
errorString = "Invalid Section music file value type";
if(PGEFile::IsQoutedString(param[1]))
sectionSet.music_file = PGEFile::X2STRING(param[1]);
else
goto badfile;
}
else if(param[0] == "BG")
{
errorString = "Invalid Section background ID value type";
if(PGEFile::IsIntS(param[1]))
sectionSet.background_id = toLong(param[1]);
else
goto badfile;
}
else if(param[0] == "AS")
{
errorString = "Invalid Section Autoscroll value type";
if(PGEFile::IsBool(param[1]))
sectionSet.autoscrol = static_cast<bool>(toInt(param[1]) != 0);
else
goto badfile;
}
else if(param[0] == "AST")
{
errorString = "Invalid Section Autoscroll type value type";
if(PGEFile::IsIntU(param[1]))
sectionSet.autoscroll_style = toUInt(param[1]);
else
goto badfile;
}
else if(param[0] == "ASP")
{
errorString = "Invalid Section Autoscroll path value type";
if(PGEFile::IsIntArray(param[1]))
{
bool valid = false;
PGELIST<long> arr = PGEFile::X2IntArr(param[1], &valid);
if(!valid)
goto badfile;
if(arr.size() % 4)
{
errorString = "Invalid Section Autoscroll path data contains non-multiple 4 entries";
goto badfile;
}
for(pge_size_t pe = 0; pe < arr.size(); pe += 4)
{
LevelEvent_Sets::AutoScrollStopPoint stop;
stop.x = arr[pe + 0];
stop.y = arr[pe + 1];
stop.type = arr[pe + 2];
stop.speed = arr[pe + 3];
sectionSet.autoscroll_path.push_back(stop);
}
}
else
goto badfile;
}
else if(param[0] == "AX")
{
errorString = "Invalid Section Autoscroll X value type";
if(PGEFile::IsFloat(param[1]))
sectionSet.autoscrol_x = toFloat(param[1]);
else
goto badfile;
}
else if(param[0] == "AY")
{
errorString = "Invalid Section Autoscroll Y value type";
if(PGEFile::IsFloat(param[1]))
sectionSet.autoscrol_y = toFloat(param[1]);
else
goto badfile;
}
else if(param[0] == "AXX")
{
errorString = "Invalid Section Autoscroll X expression value type";
if(PGEFile::IsQoutedString(param[1]))
sectionSet.expression_autoscrool_x = PGEFile::X2STRING(param[1]);
else
goto badfile;
}
else if(param[0] == "AYX")
{
errorString = "Invalid Section Autoscroll y expression value type";
if(PGEFile::IsQoutedString(param[1]))
sectionSet.expression_autoscrool_y = PGEFile::X2STRING(param[1]);
else
goto badfile;
}
}//for parameters
if(
((sectionSet.id < 0) || (sectionSet.id >= static_cast<long>(event.sets.size())))
)//Append sections
{
if(sectionSet.id < 0)
{
errorString = "Section settings event contains negative section ID value or missed!";
goto badfile;//Missmatched section ID!
}
long last = static_cast<long>(event.sets.size() - 1);
while(sectionSet.id >= static_cast<long>(event.sets.size()))
{
LevelEvent_Sets set;
set.id = last;
event.sets.push_back(set);
last++;
}
}
event.sets[static_cast<pge_size_t>(sectionSet.id)] = sectionSet;
}//for section settings entries
}//If new-styled section settings are gotten
//Parse odl-style parameters
else
{
//Apply MusicSets
pge_size_t q = 0;
for(q = 0; q < event.sets.size() && q < musicSets.size(); q++)
{
event.sets[q].id = static_cast<long>(q);
if(!PGEFile::IsIntS(musicSets[q])) goto badfile;
event.sets[q].music_id = toLong(musicSets[q]);
}
//Apply Background sets
for(q = 0; q < event.sets.size() && q < bgSets.size(); q++)
{
event.sets[q].id = static_cast<long>(q);
if(!PGEFile::IsIntS(bgSets[q])) goto badfile;
event.sets[q].background_id = toLong(bgSets[q]);
}
//Apply section sets
for(q = 0; q < event.sets.size() && q < ssSets.size(); q++)
{
event.sets[q].id = static_cast<long>(q);
PGESTRINGList sizes;