-
Notifications
You must be signed in to change notification settings - Fork 6
/
file_rw_lvl.cpp
1493 lines (1275 loc) · 48.8 KB
/
file_rw_lvl.cpp
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
/*
* PGE File Library - a library to process file formats, part of Moondust project
*
* Copyright (c) 2014-2024 Vitaly Novichkov <[email protected]>
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "pge_file_lib_sys.h"
#include "file_formats.h"
#include "file_strlist.h"
#include "smbx64.h"
#include "smbx64_macro.h"
#include "CSVUtils.h"
static int s_smbx64_flags = FileFormats::F_SMBX64_NO_FLAGS;
void FileFormats::SetSMBX64LvlFlags(int flags)
{
s_smbx64_flags = flags;
}
//*********************************************************
//****************READ FILE FORMAT*************************
//*********************************************************
struct LevelEvent_layers
{
PGESTRING hide;
PGESTRING show;
PGESTRING toggle;
};
bool FileFormats::ReadSMBX64LvlFileHeader(const PGESTRING &filePath, LevelData &FileData)
{
FileData.meta.ERROR_info.clear();
CreateLevelHeader(FileData);
FileData.meta.RecentFormat = LevelData::SMBX64;
FileData.meta.RecentFormatVersion = 64;
PGE_FileFormats_misc::TextFileInput inf;
if(!inf.open(filePath, false))
{
FileData.meta.ERROR_info = "Can't open file";
FileData.meta.ReadFileValid = false;
return false;
}
return ReadSMBX64LvlFileHeaderT(inf, FileData);
}
bool FileFormats::ReadSMBX64LvlFileHeaderRaw(PGESTRING &rawdata, const PGESTRING &filePath, LevelData &FileData)
{
FileData.meta.ERROR_info.clear();
CreateLevelHeader(FileData);
FileData.meta.RecentFormat = LevelData::SMBX64;
FileData.meta.RecentFormatVersion = 64;
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 ReadSMBX64LvlFileHeaderT(inf, FileData);
}
bool FileFormats::ReadSMBX64LvlFileHeaderT(PGE_FileFormats_misc::TextInput &inf, LevelData &FileData)
{
PGE_FileFormats_misc::FileInfo in_1(inf.getFilePath());
FileData.meta.filename = in_1.basename();
FileData.meta.path = in_1.dirpath();
FileData.meta.RecentFormat = LevelData::SMBX64;
FileData.meta.RecentFormatVersion = 64;
inf.seek(0, PGE_FileFormats_misc::TextFileInput::begin);
SMBX64_FileBegin();
#define nextLineH() line = inf.readCVSLine()
try
{
nextLineH(); //Read first line
SMBX64::ReadUInt(&file_format, line); //File format number
FileData.meta.RecentFormatVersion = file_format;
if(file_format >= 17)
{
nextLineH(); //Read second Line
SMBX64::ReadUInt(&FileData.stars, line); //Number of stars
}
else
FileData.stars = 0;
if(file_format >= 60)
{
nextLineH(); //Read third line
SMBX64::ReadStr(&FileData.LevelName, line); //LevelTitle
}
else
FileData.LevelName.clear();
FileData.CurSection = 0;
FileData.playmusic = false;
FileData.meta.ReadFileValid = true;
return true;
}
catch(const std::exception &err)
{
if(file_format > 0)
FileData.meta.ERROR_info = "Detected file format: SMBX-" + fromNum(file_format) + " is invalid\n";
else
FileData.meta.ERROR_info = "It is not an SMBX level file\n";
#ifdef PGE_FILES_QT
FileData.meta.ERROR_info += QString::fromStdString(exception_to_pretty_string(err));
#else
FileData.meta.ERROR_info += exception_to_pretty_string(err);
#endif
FileData.meta.ERROR_linenum = inf.getCurrentLineNumber();
FileData.meta.ERROR_linedata = std::move(line);
FileData.meta.ReadFileValid = false;
PGE_CutLength(FileData.meta.ERROR_linedata, 50);
PGE_FilterBinary(FileData.meta.ERROR_linedata);
return false;
}
}
bool FileFormats::ReadSMBX64LvlFileF(const PGESTRING &filePath, LevelData &FileData)
{
PGE_FileFormats_misc::TextFileInput file;
if(!file.open(filePath, false))
{
FileData.meta.ERROR_info = "Failed to open file for read";
FileData.meta.ERROR_linedata.clear();
FileData.meta.ERROR_linenum = -1;
FileData.meta.ReadFileValid = false;
return false;
}
return ReadSMBX64LvlFile(file, FileData);
}
bool FileFormats::ReadSMBX64LvlFileRaw(PGESTRING &rawdata, const PGESTRING &filePath, LevelData &FileData)
{
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.clear();
FileData.meta.ERROR_linenum = -1;
FileData.meta.ReadFileValid = false;
return false;
}
return ReadSMBX64LvlFile(file, FileData);
}
bool FileFormats::ReadSMBX64LvlFile(PGE_FileFormats_misc::TextInput &in, LevelData &FileData)
{
SMBX64_FileBegin();
PGESTRING filePath = in.getFilePath();
//SMBX64_File( RawData );
int i; //counters
CreateLevelData(FileData);
FileData.meta.RecentFormat = LevelData::SMBX64;
FileData.meta.RecentFormatVersion = 64;
FileData.LevelName.clear();
FileData.stars = 0;
FileData.CurSection = 0;
FileData.playmusic = false;
//Enable strict mode for SMBX LVL file format
FileData.meta.smbx64strict = true;
//Begin all ArrayID's here;
FileData.blocks_array_id = 1;
FileData.bgo_array_id = 1;
FileData.npc_array_id = 1;
FileData.doors_array_id = 1;
FileData.physenv_array_id = 1;
FileData.layers_array_id = 1;
FileData.events_array_id = 1;
FileData.layers.clear();
FileData.events.clear();
LevelSection section;
int sct;
PlayerPoint players;
LevelBlock blocks;
LevelBGO bgodata;
LevelNPC npcdata;
LevelDoor doors;
LevelPhysEnv waters;
LevelLayer layers;
LevelSMBX64Event events;
LevelEvent_layers events_layers;
LevelEvent_Sets events_sets;
//Add path data
if(!IsEmpty(filePath))
{
PGE_FileFormats_misc::FileInfo in_1(filePath);
FileData.meta.filename = in_1.basename();
FileData.meta.path = in_1.dirpath();
}
try
{
///////////////////////////////////////Begin file///////////////////////////////////////
nextLine(); //Read first line
SMBX64::ReadUInt(&file_format, line);//File format number
FileData.meta.RecentFormatVersion = file_format;
if(ge(17))
{
nextLine();
SMBX64::ReadUInt(&FileData.stars, line); //Number of stars
}
else
FileData.stars = 0; //-V1048
if(ge(60))
{
nextLine(); //LevelTitle
SMBX64::ReadStr(&FileData.LevelName, line);
}
//total sections
sct = (ge(8) ? 21 : 6);
////////////SECTION Data//////////
for(i = 0; i < sct; i++)
{
section = CreateLvlSection();
nextLine();
SMBX64::ReadSIntFromFloat(§ion.size_left, line);
nextLine();
SMBX64::ReadSIntFromFloat(§ion.size_top, line);
nextLine();
SMBX64::ReadSIntFromFloat(§ion.size_bottom, line); //bottom
nextLine();
SMBX64::ReadSIntFromFloat(§ion.size_right, line); //right
nextLine();
SMBX64::ReadUInt(§ion.music_id, line); //Music ID
nextLine();
SMBX64::ReadUInt(§ion.bgcolor, line); //BG Color
nextLine();
SMBX64::ReadCSVBool(§ion.wrap_h, line); //Connect sides of section
nextLine();
SMBX64::ReadCSVBool(§ion.OffScreenEn, line);//Offscreen exit
nextLine();
SMBX64::ReadUInt(§ion.background, line); //BackGround id
if(ge(1))
{
nextLine(); //Don't walk to left (no turn back)
SMBX64::ReadCSVBool(§ion.lock_left_scroll, line);
}
if(ge(30))
{
nextLine(); //Underwater
SMBX64::ReadCSVBool(§ion.underwater, line);
}
if(ge(2))
{
nextLine(); //Custom Music
SMBX64::ReadStr(§ion.music_file, line);
}
//Very important data! I'ts a camera position in the editor!
section.PositionX = section.size_left - 10; //left
section.PositionY = section.size_top - 10; //top
section.id = i;
if(i < static_cast<signed>(FileData.sections.size()))
FileData.sections[static_cast<pge_size_t>(i)] = section; //Replace if already exists
else
FileData.sections.push_back(section); //Add Section in main array
}
if(lt(8))
for(; i < 21; i++)
{
section = CreateLvlSection();
section.id = i;
if(i < static_cast<signed>(FileData.sections.size()))
FileData.sections[static_cast<pge_size_t>(i)] = section; //Replace if already exists
else
FileData.sections.push_back(section); //Add Section in main array
}
//Player's point config
for(i = 0; i < 2; i++)
{
players = CreateLvlPlayerPoint();
nextLine();
SMBX64::ReadSIntFromFloat(&players.x, line);//Player x
nextLine();
SMBX64::ReadSIntFromFloat(&players.y, line);//Player y
nextLine();
SMBX64::ReadUInt(&players.w, line);//Player w
nextLine();
SMBX64::ReadUInt(&players.h, line);//Player h
players.id = static_cast<unsigned int>(i) + 1u;
if(players.x != 0 && players.y != 0 && players.w != 0 && players.h != 0) //Don't add into array non-exist point
FileData.players.push_back(players); //Add player in array
}
////////////Block Data//////////
nextLine();
while(line != "next")
{
blocks = CreateLvlBlock();
SMBX64::ReadSIntFromFloat(&blocks.x, line);
nextLine();
SMBX64::ReadSIntFromFloat(&blocks.y, line);
nextLine();
SMBX64::ReadSIntFromFloat(&blocks.h, line);
nextLine();
SMBX64::ReadSIntFromFloat(&blocks.w, line);
nextLine();
SMBX64::ReadUInt(&blocks.id, line);
long xnpcID;
nextLine();
SMBX64::ReadUInt(&xnpcID, line); //Containing NPC id
{
//Convert NPC-ID value from SMBX1/2 to SMBX64
if((s_smbx64_flags & F_SMBX64_KEEP_LEGACY_NPC_IN_BLOCK_CODES) == 0)
{
switch(xnpcID)
{
case 100:
xnpcID = 1009;
break;//Mushroom
case 101:
xnpcID = 1001;
break;//Goomba
case 102:
xnpcID = 1014;
break;//Fire flower
case 103:
xnpcID = 1034;
break;//Super leaf
case 104:
xnpcID = 1035;
break;//Shoe
case 105:
xnpcID = 1095;
break;//Green Yoshi
case 201:
xnpcID = 1186;
break;//Life mushroom
default:
break;
}
}
// Convert NPC-ID value from SMBX64 into Moondust format
if(xnpcID != 0)
{
if(xnpcID > 1000)
xnpcID = xnpcID - 1000;
else
xnpcID *= -1;
}
blocks.npc_id = xnpcID;
}
nextLine();
SMBX64::ReadCSVBool(&blocks.invisible, line);
if(ge(61))
{
nextLine();
SMBX64::ReadCSVBool(&blocks.slippery, line);
}
if(ge(10))
{
nextLine();
SMBX64::ReadStr(&blocks.layer, line);
}
if(ge(14))
{
nextLine();
SMBX64::ReadStr(&blocks.event_destroy, line);
nextLine();
SMBX64::ReadStr(&blocks.event_hit, line);
nextLine();
SMBX64::ReadStr(&blocks.event_emptylayer, line);
}
blocks.meta.array_id = FileData.blocks_array_id++;
blocks.meta.index = static_cast<unsigned int>(FileData.blocks.size()); //Apply element index
FileData.blocks.push_back(blocks); //AddBlock into array
nextLine();
}
////////////BGO Data//////////
nextLine();
while(line != "next")
{
bgodata = CreateLvlBgo();
SMBX64::ReadSIntFromFloat(&bgodata.x, line);
nextLine();
SMBX64::ReadSIntFromFloat(&bgodata.y, line);
nextLine();
SMBX64::ReadUInt(&bgodata.id, line);
if(ge(10))
{
nextLine();
SMBX64::ReadStr(&bgodata.layer, line);
}
bgodata.smbx64_sp = -1;
if((file_format < 30) && (bgodata.id == 65)) //set foreground for BGO-65 (SMBX 1.0)
{
bgodata.z_mode = LevelBGO::Foreground1;
bgodata.smbx64_sp = 125;
}
bgodata.meta.array_id = FileData.bgo_array_id++;
bgodata.meta.index = static_cast<unsigned int>(FileData.bgo.size()); //Apply element index
FileData.bgo.push_back(bgodata); //Add Background object into array
nextLine();
}
////////////NPC Data//////////
nextLine();
while(line != "next")
{
npcdata = CreateLvlNpc();
SMBX64::ReadSIntFromFloat(&npcdata.x, line);
nextLine();
SMBX64::ReadSIntFromFloat(&npcdata.y, line);
nextLine();
SMBX64::ReadSInt(&npcdata.direct, line); //NPC direction
nextLine();
SMBX64::ReadUInt(&npcdata.id, line); //NPC id
npcdata.special_data = 0;
npcdata.contents = 0;
switch(npcdata.id)
{
//SMBX64 Fixed special options for NPC
/*parakoopas*/
case 76: case 121: case 122: case 123:
case 124: case 161: case 176: case 177:
/*Paragoomba*/
case 243: case 244:
/*Cheep-Cheep*/
case 28: case 229: case 230: case 232:
case 233: case 234: case 236:
/*WarpSelection*/
case 288: case 289:
/*firebar*/
case 260:
{
if(npcdata.id == 76 && lt(15))
{
npcdata.special_data = 0; //-V1048
}
else if(npcdata.id == 28 && lt(31))
{
npcdata.special_data = 2;
}
else
{
nextLine();
SMBX64::ReadSInt(&npcdata.special_data, line); //NPC special option
}
break;
}
/*Containers*/
case 91: /*buried*/
case 96: /*egg*/
case 283:/*Bubble*/
case 284:/*SMW Lakitu*/
{
nextLine();
SMBX64::ReadSInt(&npcdata.contents, line);
if(npcdata.id == 91)
{
switch(npcdata.contents)
{
/*WarpSelection*/
case 288: /*case 289:*/ /*firebar*/ /*case 260:*/
nextLine();
SMBX64::ReadSInt(&npcdata.special_data, line);
break;
default:
break;
}
}
break;
}
default:
break;
}
if(ge(3))
{
nextLine();
SMBX64::ReadCSVBool(&npcdata.generator, line); //Generator enabled
npcdata.generator_direct = 1;
npcdata.generator_type = 1;
if(npcdata.generator)
{
nextLine();
SMBX64::ReadSInt(&npcdata.generator_direct, line); //Generator direction (1, 2, 3, 4)
if(npcdata.generator_direct < 0)
npcdata.generator_direct = 1; //Fix of old accidental mistake causes -1 value
nextLine();
SMBX64::ReadUInt(&npcdata.generator_type, line); //Generator type [1] Warp, [2] Projectile
nextLine();
SMBX64::ReadUInt(&npcdata.generator_period, line); //Generator period ( sec*10 ) [1-600]
}
}
if(ge(5))
{
nextLine();
//strVarMultiLine(npcdata.msg, line)//Message
SMBX64::ReadStr(&npcdata.msg, line);//Message
}
if(ge(6))
{
nextLine();
SMBX64::ReadCSVBool(&npcdata.friendly, line);//Friendly NPC
nextLine();
SMBX64::ReadCSVBool(&npcdata.nomove, line); //Don't move NPC
}
if(ge(9))
{
nextLine();
SMBX64::ReadCSVBool(&npcdata.is_boss, line); //Set as boss flag
}
else
{
switch(npcdata.id)
{
//set boss flag to TRUE for old file formats automatically
case 15:
case 39:
case 86:
npcdata.is_boss = true;
break;
default:
break;
}
}
if(ge(10))
{
nextLine();
SMBX64::ReadStr(&npcdata.layer, line);
nextLine();
SMBX64::ReadStr(&npcdata.event_activate, line);
nextLine();
SMBX64::ReadStr(&npcdata.event_die, line);
nextLine();
SMBX64::ReadStr(&npcdata.event_talk, line);
}
if(ge(14))
{
nextLine(); //No more objects in layer event
SMBX64::ReadStr(&npcdata.event_emptylayer, line);
}
if(ge(63))
{
nextLine(); //Layer name to attach
SMBX64::ReadStr(&npcdata.attach_layer, line);
}
npcdata.meta.array_id = FileData.npc_array_id++;
npcdata.meta.index = static_cast<unsigned>(FileData.npc.size()); //Apply element index
FileData.npc.push_back(npcdata); //Add NPC into array
nextLine();
}
////////////Warp and Doors Data//////////
nextLine();
while(
((line != "next") && (file_format >= 10))
|| ((file_format < 10) && (!IsEmpty(line)) && (!in.eof()))
)
{
doors = CreateLvlWarp();
doors.isSetIn = true;
doors.isSetOut = true;
SMBX64::ReadSIntFromFloat(&doors.ix, line); //Entrance x
nextLine();
SMBX64::ReadSIntFromFloat(&doors.iy, line); //Entrance y
nextLine();
SMBX64::ReadSIntFromFloat(&doors.ox, line); //Exit x
nextLine();
SMBX64::ReadSIntFromFloat(&doors.oy, line); //Exit y
nextLine();
SMBX64::ReadUInt(&doors.idirect, line); //Entrance direction: [3] down, [1] up, [2] left, [4] right
nextLine();
SMBX64::ReadUInt(&doors.odirect, line); //Exit direction: [1] down [3] up [4] left [2] right
nextLine();
SMBX64::ReadUInt(&doors.type, line); //Door type: [1] pipe, [2] door, [0] instant
if(ge(3))
{
nextLine();
SMBX64::ReadStr(&doors.lname, line); //Warp to level
nextLine();
SMBX64::ReadUInt(&doors.warpto, line); //Normal entrance or Warp to other door
nextLine();
SMBX64::ReadCSVBool(&doors.lvl_i, line); //Level Entrance (cannot enter)
doors.isSetIn = !doors.lvl_i;
}
if(ge(4)) //-V112
{
nextLine();
SMBX64::ReadCSVBool(&doors.lvl_o, line); //-V112
doors.isSetOut = (!doors.lvl_o || (doors.lvl_i));
nextLine();
SMBX64::ReadSInt(&doors.world_x, line); //WarpTo X
nextLine();
SMBX64::ReadSInt(&doors.world_y, line); //WarpTo y
}
if(ge(7))
{
nextLine(); //Need a stars
SMBX64::ReadUInt(&doors.stars, line);
}
if(ge(12))
{
nextLine();
SMBX64::ReadStr(&doors.layer, line); //Layer
nextLine();
SMBX64::ReadCSVBool(&doors.unknown, line);
} //<unused>, always FALSE
if(ge(23))
{
nextLine(); //Deny vehicles
SMBX64::ReadCSVBool(&doors.novehicles, line);
}
if(ge(25))
{
nextLine(); //Allow carried items
SMBX64::ReadCSVBool(&doors.allownpc, line);
}
if(ge(26))
{
nextLine(); //Locked
SMBX64::ReadCSVBool(&doors.locked, line);
}
doors.meta.array_id = FileData.doors_array_id++;
doors.meta.index = static_cast<unsigned>(FileData.doors.size()); //Apply element index
FileData.doors.push_back(doors); //Add NPC into array
nextLine();
}
////////////Water/QuickSand Data//////////
if(file_format >= 29)
{
nextLine();
while(line != "next")
{
waters = CreateLvlPhysEnv();
SMBX64::ReadSIntFromFloat(&waters.x, line);
nextLine();
SMBX64::ReadSIntFromFloat(&waters.y, line);
nextLine();
SMBX64::ReadUInt(&waters.w, line);
nextLine();
SMBX64::ReadUInt(&waters.h, line);
nextLine();
SMBX64::ReadFloat(&waters.buoy, line);
if(ge(62))
{
nextLine();
SMBX64::ReadCSVBool(&waters.env_type, line);
}
nextLine();
SMBX64::ReadStr(&waters.layer, line);
waters.meta.array_id = FileData.physenv_array_id++;
waters.meta.index = static_cast<unsigned>(FileData.physez.size()); //Apply element index
FileData.physez.push_back(waters); //Add Water area into array
nextLine();
}
}
if(ge(10))
{
////////////Layers Data//////////
nextLine();
while((line != "next") && (!in.eof()) && (!IsEmpty(line)))
{
SMBX64::ReadStr(&layers.name, line); //Layer name
nextLine();
SMBX64::ReadCSVBool(&layers.hidden, line); //hidden layer
layers.locked = false;
layers.meta.array_id = FileData.layers_array_id++;
FileData.layers.push_back(layers); //Add Water area into array
nextLine();
}
////////////Events Data//////////
nextLine();
while((!IsEmpty(line)) && (!in.eof()))
{
events = CreateLvlEvent();
SMBX64::ReadStr(&events.name, line);//Event name
if(ge(11))
{
nextLine();
SMBX64::ReadStr(&events.msg, line);//Event message
}
if(ge(14))
{
nextLine();
SMBX64::ReadUInt(&events.sound_id, line);
}
if(ge(18))
{
nextLine();
SMBX64::ReadUInt(&events.end_game, line);
}
PGELIST<LevelEvent_layers > events_layersArr;
events_layersArr.clear();
events.layers_hide.clear();
events.layers_show.clear();
events.layers_toggle.clear();
for(i = 0; i < sct; i++)
{
nextLine();
SMBX64::ReadStr(&events_layers.hide, line); //Hide layer
nextLine();
SMBX64::ReadStr(&events_layers.show, line); //Show layer
if(ge(14))
{
nextLine();
SMBX64::ReadStr(&events_layers.toggle, line);//Toggle layer
}
else
events_layers.toggle.clear();
if(!IsEmpty(events_layers.hide))
events.layers_hide.push_back(events_layers.hide);
if(!IsEmpty(events_layers.show))
events.layers_show.push_back(events_layers.show);
if(!IsEmpty(events_layers.toggle))
events.layers_toggle.push_back(events_layers.toggle);
events_layersArr.push_back(events_layers);
}
if(ge(13))
{
events.sets.clear();
for(i = 0; i < 21; i++)
{
events_sets.id = i;
nextLine();
SMBX64::ReadSInt(&events_sets.music_id, line); //Set Music
nextLine();
SMBX64::ReadSInt(&events_sets.background_id, line); //Set Background
nextLine();
SMBX64::ReadSInt(&events_sets.position_left, line); //Set Position to: LEFT
nextLine();
SMBX64::ReadSInt(&events_sets.position_top, line); //Set Position to: TOP
nextLine();
SMBX64::ReadSInt(&events_sets.position_bottom, line); //Set Position to: BOTTOM
nextLine();
SMBX64::ReadSInt(&events_sets.position_right, line); //Set Position to: RIGHT
events.sets.push_back(events_sets);
}
}
if(ge(26))
{
nextLine();
SMBX64::ReadStr(&events.trigger, line); //Trigger
nextLine();
SMBX64::ReadUInt(&events.trigger_timer, line);
} //Start trigger event after x [1/10 sec]. Etc. 153,2 sec
if(ge(27))
{
nextLine(); //Don't smoke tobacco, let's healthy! :D
SMBX64::ReadCSVBool(&events.nosmoke, line);
}
if(ge(28))
{
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_altjump, line);//Hold ALT-JUMP player control
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_altrun, line); //ALT-RUN
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_down, line); //DOWN
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_drop, line); //DROP
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_jump, line); //JUMP
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_left, line); //LEFT
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_right, line); //RIGHT
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_run, line); //RUN
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_start, line); //START
nextLine();
SMBX64::ReadCSVBool(&events.ctrl_up, line); //UP
events.ctrls_enable = events.ctrlKeyPressed();
events.ctrl_lock_keyboard = events.ctrls_enable;
}
if(ge(32)) //-V112
{
nextLine();
SMBX64::ReadCSVBool(&events.autostart, line); //Auto start
nextLine();
SMBX64::ReadStr(&events.movelayer, line); //Layer for movement
nextLine();
SMBX64::ReadFloat(&events.layer_speed_x, line); //Layer moving speed - horizontal
nextLine();
SMBX64::ReadFloat(&events.layer_speed_y, line); //Layer moving speed - vertical
if(!IsEmpty(events.movelayer))
{
LevelEvent_MoveLayer mvl;
mvl.name = events.movelayer;
mvl.speed_x = events.layer_speed_x;
mvl.speed_y = events.layer_speed_y;
events.moving_layers.push_back(mvl);
}
}
if(ge(33))
{
nextLine();
SMBX64::ReadFloat(&events.move_camera_x, line); //Move screen horizontal speed
nextLine();
SMBX64::ReadFloat(&events.move_camera_y, line); //Move screen vertical speed
nextLine();
SMBX64::ReadSInt(&events.scroll_section, line); //Scroll section x, (in file value is x-1)
// !!!This code intended to convert old autoscroll into new, but, this is a source of the bug, so, don't do that!!!
// if(((events.move_camera_x != 0.0) || (events.move_camera_y != 0.0)) && (events.scroll_section < static_cast<long>(events.sets.size())))
// {
// pge_size_t scroll_section = static_cast<pge_size_t>(events.scroll_section);
// LevelEvent_Sets &set = events.sets[scroll_section];
// set.autoscrol = true;
// set.autoscrol_x = static_cast<float>(events.move_camera_x);
// set.autoscrol_y = static_cast<float>(events.move_camera_y);
// set.expression_autoscrool_x = fromNum(events.move_camera_x);
// set.expression_autoscrool_y = fromNum(events.move_camera_y);
// }
}
events.meta.array_id = FileData.events_array_id++;
FileData.events.push_back(events);
nextLine();
}
}
LevelAddInternalEvents(FileData);
///////////////////////////////////////EndFile///////////////////////////////////////
FileData.meta.ReadFileValid = true;
return true;
}
catch(const std::exception &err)
{
if(file_format > 0)
FileData.meta.ERROR_info = "Detected file format: SMBX-" + fromNum(file_format) + " is invalid\n";
else
FileData.meta.ERROR_info = "It is not an SMBX level file\n";
#ifdef PGE_FILES_QT
FileData.meta.ERROR_info += QString::fromStdString(exception_to_pretty_string(err));
#else
FileData.meta.ERROR_info += exception_to_pretty_string(err);
#endif
FileData.meta.ERROR_linenum = in.getCurrentLineNumber();
FileData.meta.ERROR_linedata = std::move(line);
FileData.meta.ReadFileValid = false;
PGE_CutLength(FileData.meta.ERROR_linedata, 50);
PGE_FilterBinary(FileData.meta.ERROR_linedata);
return false;
}
}
//*********************************************************
//****************WRITE FILE FORMAT************************
//*********************************************************
bool FileFormats::WriteSMBX64LvlFileF(const PGESTRING &filePath, LevelData &FileData, unsigned int file_format)
{
FileData.meta.ERROR_info.clear();
PGE_FileFormats_misc::TextFileOutput file;
if(!file.open(filePath, false, true, PGE_FileFormats_misc::TextOutput::truncate))
{
FileData.meta.ERROR_info = "Fail to open file for write";
return false;
}
return WriteSMBX64LvlFile(file, FileData, file_format);
}
bool FileFormats::WriteSMBX64LvlFileRaw(LevelData &FileData, PGESTRING &rawdata, unsigned int file_format)
{
FileData.meta.ERROR_info.clear();
PGE_FileFormats_misc::RawTextOutput file;
if(!file.open(&rawdata, PGE_FileFormats_misc::TextOutput::truncate))
{
FileData.meta.ERROR_info = "Failed to open raw string for write";
return false;
}
return WriteSMBX64LvlFile(file, FileData, file_format);
}
bool FileFormats::WriteSMBX64LvlFile(PGE_FileFormats_misc::TextOutput &out, LevelData &FileData, unsigned int file_format)
{
pge_size_t i, j;
//Count placed stars on this level
FileData.stars = 0;
for(auto &n : FileData.npc)
{
if(n.is_star)
FileData.stars++;
}
//Sort blocks array by X->Y