-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerraGen.lua
More file actions
2930 lines (2497 loc) · 147 KB
/
Copy pathTerraGen.lua
File metadata and controls
2930 lines (2497 loc) · 147 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
-- MIT License
-- Copyright (c) 2022 Rebmiami
-- 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.
-- Set to true to enable certain developer features
-- Should always be false on releases
local devMode = false
-- Check if the current snapshot supports tmp3/tmp4
-- Otherwise, use pavg0/1
local tmp3 = "pavg0"
local tmp4 = "pavg1"
if sim.FIELD_TMP3 then -- Returns nil if tmp3 is not part of the current snapshot
tmp3 = "tmp3"
tmp4 = "tmp4"
end
--[[ json.lua
A compact pure-Lua JSON library.
The main functions are: json.stringify, json.parse.
## json.stringify:
This expects the following to be true of any tables being encoded:
* They only have string or number keys. Number keys must be represented as
strings in json; this is part of the json spec.
* They are not recursive. Such a structure cannot be specified in json.
A Lua table is considered to be an array if and only if its set of keys is a
consecutive sequence of positive integers starting at 1. Arrays are encoded like
so: `[2, 3, false, "hi"]`. Any other type of Lua table is encoded as a json
object, encoded like so: `{"key1": 2, "key2": false}`.
Because the Lua nil value cannot be a key, and as a table value is considerd
equivalent to a missing key, there is no way to express the json "null" value in
a Lua table. The only way this will output "null" is if your entire input obj is
nil itself.
An empty Lua table, {}, could be considered either a json object or array -
it's an ambiguous edge case. We choose to treat this as an object as it is the
more general type.
To be clear, none of the above considerations is a limitation of this code.
Rather, it is what we get when we completely observe the json specification for
as arbitrary a Lua object as json is capable of expressing.
## json.parse:
This function parses json, with the exception that it does not pay attention to
\u-escaped unicode code points in strings.
It is difficult for Lua to return null as a value. In order to prevent the loss
of keys with a null value in a json string, this function uses the one-off
table value json.null (which is just an empty table) to indicate null values.
This way you can check if a value is null with the conditional
`val == json.null`.
If you have control over the data and are using Lua, I would recommend just
avoiding null values in your data to begin with.
--]]
json = {}
-- Internal functions.
local function kind_of(obj)
if type(obj) ~= 'table' then return type(obj) end
local i = 1
for _ in pairs(obj) do
if obj[i] ~= nil then i = i + 1 else return 'table' end
end
if i == 1 then return 'table' else return 'array' end
end
local function escape_str(s)
local in_char = {'\\', '"', '/', '\b', '\f', '\n', '\r', '\t'}
local out_char = {'\\', '"', '/', 'b', 'f', 'n', 'r', 't'}
for i, c in ipairs(in_char) do
s = s:gsub(c, '\\' .. out_char[i])
end
return s
end
-- Returns pos, did_find; there are two cases:
-- 1. Delimiter found: pos = pos after leading space + delim; did_find = true.
-- 2. Delimiter not found: pos = pos after leading space; did_find = false.
-- This throws an error if err_if_missing is true and the delim is not found.
local function skip_delim(str, pos, delim, err_if_missing)
pos = pos + #str:match('^%s*', pos)
if str:sub(pos, pos) ~= delim then
if err_if_missing then
error('Expected ' .. delim .. ' near position ' .. pos)
end
return pos, false
end
return pos + 1, true
end
-- Expects the given pos to be the first character after the opening quote.
-- Returns val, pos; the returned pos is after the closing quote character.
local function parse_str_val(str, pos, val)
val = val or ''
local early_end_error = 'End of input found while parsing string.'
if pos > #str then error(early_end_error) end
local c = str:sub(pos, pos)
if c == '"' then return val, pos + 1 end
if c ~= '\\' then return parse_str_val(str, pos + 1, val .. c) end
-- We must have a \ character.
local esc_map = {b = '\b', f = '\f', n = '\n', r = '\r', t = '\t'}
local nextc = str:sub(pos + 1, pos + 1)
if not nextc then error(early_end_error) end
return parse_str_val(str, pos + 2, val .. (esc_map[nextc] or nextc))
end
-- Returns val, pos; the returned pos is after the number's final character.
local function parse_num_val(str, pos)
local num_str = str:match('^-?%d+%.?%d*[eE]?[+-]?%d*', pos)
local val = tonumber(num_str)
if not val then error('Error parsing number at position ' .. pos .. '.') end
return val, pos + #num_str
end
-- Public values and functions.
function json.stringify(obj, as_key)
local s = {} -- We'll build the string as an array of strings to be concatenated.
local kind = kind_of(obj) -- This is 'array' if it's an array or type(obj) otherwise.
if kind == 'array' then
if as_key then error('Can\'t encode array as key.') end
s[#s + 1] = '['
for i, val in ipairs(obj) do
if i > 1 then s[#s + 1] = ', ' end
s[#s + 1] = json.stringify(val)
end
s[#s + 1] = ']'
elseif kind == 'table' then
if as_key then error('Can\'t encode table as key.') end
s[#s + 1] = '{'
for k, v in pairs(obj) do
if #s > 1 then s[#s + 1] = ', ' end
s[#s + 1] = json.stringify(k, true)
s[#s + 1] = ':'
s[#s + 1] = json.stringify(v)
end
s[#s + 1] = '}'
elseif kind == 'string' then
return '"' .. escape_str(obj) .. '"'
elseif kind == 'number' then
if as_key then return '"' .. tostring(obj) .. '"' end
return tostring(obj)
elseif kind == 'boolean' then
return tostring(obj)
elseif kind == 'nil' then
return 'null'
else
error('Unjsonifiable type: ' .. kind .. '.')
end
return table.concat(s)
end
json.null = {} -- This is a one-off table to represent the null value.
function json.parse(str, pos, end_delim)
pos = pos or 1
if pos > #str then error('Reached unexpected end of input.') end
local pos = pos + #str:match('^%s*', pos) -- Skip whitespace.
local first = str:sub(pos, pos)
if first == '{' then -- Parse an object.
local obj, key, delim_found = {}, true, true
pos = pos + 1
while true do
key, pos = json.parse(str, pos, '}')
if key == nil then return obj, pos end
if not delim_found then error('Comma missing between object items.') end
pos = skip_delim(str, pos, ':', true) -- true -> error if missing.
obj[key], pos = json.parse(str, pos)
pos, delim_found = skip_delim(str, pos, ',')
end
elseif first == '[' then -- Parse an array.
local arr, val, delim_found = {}, true, true
pos = pos + 1
while true do
val, pos = json.parse(str, pos, ']')
if val == nil then return arr, pos end
if not delim_found then error('Comma missing between array items.') end
arr[#arr + 1] = val
pos, delim_found = skip_delim(str, pos, ',')
end
elseif first == '"' then -- Parse a string.
return parse_str_val(str, pos + 1)
elseif first == '-' or first:match('%d') then -- Parse a number.
return parse_num_val(str, pos)
elseif first == end_delim then -- End of an object or array.
return nil, pos + 1
else -- Parse true, false, or null.
local literals = {['true'] = true, ['false'] = false, ['null'] = json.null}
for lit_str, lit_val in pairs(literals) do
local lit_end = pos + #lit_str - 1
if str:sub(pos, lit_end) == lit_str then return lit_val, lit_end + 1 end
end
local pos_info_str = 'position ' .. pos .. ': ' .. str:sub(pos, pos + 10)
error('Invalid json syntax starting at ' .. pos_info_str)
end
end
-- return json
-- Code from https://gist.github.com/tylerneylon/59f4bcf316be525b30ab
local versionMajor = 1 -- Increment for any change that significantly changes features that older versions rely on
local versionMinor = 1 -- Increment for any change that adds new features not supported by older versions
local OldDataPath = "TerraGen/"
local DataPath = "Territect/"
local PresetPath = DataPath .. "Presets.tgdata"
local TempPresetPath = DataPath .. "Presets.tgdata.temp"
local BackupPresetPath = DataPath .. "Presets.tgdata.bak"
local SettingsPath = DataPath .. "Settings.tgdata"
local DownloadFolderName = "Downloaded"
local magicWord = 0x7454 -- "Tt"
local maxEmbedSize = 256
local maxEmbedPartCt = maxEmbedSize * maxEmbedSize - 2 -- 65536 minus 2 for header and footer
local MaxPresetSize = maxEmbedPartCt * 8 -- 512kib (only applies to embedding) excluding header and footer
local MaxPasses = 32
local function GetDefaultLayer()
return { type = elem.DEFAULT_PT_SAND, thickness = 30, variation = 5, mode = 1 }
end
local function GetDefaultPass()
return { bottom = 40, layers = { GetDefaultLayer(), }, settleTime = 60 }
end
local presetModeNames = {
"Uniform",
"Padded",
"Veins",
"Replace",
}
local presetModeShortNames = {
"Uni.",
"Pad.",
"Vein",
"Rep.",
}
-- Contains default values as well as the fields themselves
local presetModeFields = {
{
type = elem.DEFAULT_PT_SAND,
mode = 1,
thickness = 30,
variation = 5,
},
{
type = elem.DEFAULT_PT_SAND,
mode = 2,
thickness = 30,
variation = 5,
},
{
type = elem.DEFAULT_PT_SAND,
mode = 3,
minY = 15,
maxY = 20,
width = 120,
height = 3,
veinCount = 15
},
{
type = elem.DEFAULT_PT_GOLD,
mode = 4,
oldType = elem.DEFAULT_PT_BMTL,
percent = 100,
inExisting = false,
inLayer = true,
preserveProps = false,
}
}
-- Never narrow the ranges between minor updates
local presetModeFieldConstraints = {
{
{ prop = "thickness", type = "number", text = "Thickness", min = "-600", max = "600", fraction = true },
{ prop = "variation", type = "number", text = "Variation", min = "0", max = "600", fraction = true }
},
{
{ prop = "thickness", type = "number", text = "Thickness", min = "-600", max = "600", fraction = true },
{ prop = "variation", type = "number", text = "Variation", min = "0", max = "600", fraction = true }
},
{
{ prop = "minY", type = "number", text = "Min Y", min = "-600", max = "600", fraction = true },
{ prop = "maxY", type = "number", text = "Max Y", min = "-600", max = "600", fraction = true },
{ prop = "width", type = "number", text = "Vein Width", min = "0", max = "600", fraction = true },
{ prop = "height", type = "number", text = "Vein Height", min = "0", max = "600", fraction = true },
{ prop = "veinCount", type = "number", text = "Vein Count", min = "0", max = "10000", fraction = false },
},
{
{ prop = "oldType", type = "element", text = "To Replace" },
{ prop = "percent", type = "number", text = "Percent", min = "0", max = "100", fraction = true },
{ prop = "inExisting", type = "boolean", text = "Replace Existing" },
{ prop = "inLayer", type = "boolean", text = "Replace in Layer" },
{ prop = "preserveProps", type = "boolean", text = "Keep Old Properties" },
}
}
-- Return format:
-- (any type) The closest acceptable value if the provided one is invalid
-- (boolean) Whether or not the constraint is met
-- (boolean) Whether the value was only slightly wrong (false) or really wrong (true)
function enforceModeFieldConstraints(mode, field, value)
local constraints = presetModeFieldConstraints[mode][field]
local newValue = value
local defaultValue = presetModeFields[mode][constraints.prop]
local reallyWrong = false
if newValue == nil or type(newValue) ~= type(defaultValue) then
newValue = defaultValue
reallyWrong = true
end
if constraints.type == "number" then
newValue = math.min(math.max(newValue, constraints.min), constraints.max)
if not constraints.fraction then
newValue = math.floor(newValue)
end
end
if constraints.type == "element" then
-- No additional correction required
end
if constraints.type == "boolean" then
-- No additional correction necessary
end
return newValue, value == newValue, reallyWrong
end
function getElementIDFromName(targetName)
for i=0,2^sim.PMAPBITS-1 do
local isElem, name = validateElemID(i)
if isElem and name == string.upper(targetName) then
return i
end
end
return nil
end
local settings = {
}
function validateElemID(id)
local isElem, name = pcall(function() return elem.property(id, "Name") end)
if not isElem then return false end
local isModded = string.sub(elem.property(id, "Identifier"), 0, 8) ~= "DEFAULT_"
return isElem and (not isModded) or settings.allowModdedElems, name, isModded
end
-- TODO: The stuff in this table doesn't actually do anything; the real values are stored elsewhere
-- Make option screen use this data
local settingFieldConstraints = {
{ prop = "drawTerritectLogo", type = "boolean", text = "Draw Territect logo on embedded presets" },
{ prop = "showWarnings", type = "boolean", text = "Show embedded preset warnings (highly recommended)" },
{ prop = "resetSimProps", type = "boolean", text = "Reset simulation settings when generating preset (highly recommended)" },
{ prop = "automaticBackups", type = "boolean", text = "Automatically backup presets (backups stored in data folder)" },
{ prop = "allowModdedElems", type = "boolean", text = "Allow modded elements in presets (not recommended)" },
{ prop = "backupNumber", type = "number", text = "Number of backups", min = "1", max = "20", fraction = true },
}
local function resetLayerMode(layer)
local template = presetModeFields[layer.mode]
for k,j in pairs(template) do
if layer[k] == nil then
layer[k] = template[k]
end
end
for k,j in pairs(layer) do
if template[k] == nil then
layer[k] = nil
end
end
end
-- Creates a copy of the table as a new object
local function CopyTable(table)
local copy = {}
for i,j in pairs(table) do
if type(j) == "table" then
copy[i] = CopyTable(j)
else
copy[i] = j
end
end
return copy
end
-- Sorts the keys of the table and returns them sorted alphabetically in a sequence
local function SortKeysAlphabetical(toSort)
local sequence = {}
for i,j in pairs(toSort) do
table.insert(sequence, i)
end
table.sort(sequence)
return sequence
-- Cook & eat sequence
end
local factoryPresets = {
["Basic Lakes"] = '{"versionMinor":1, "versionMajor":1, "passes":[{"bottom":40, "layers":[{"type":5, "variation":5, "mode":1, "thickness":10}, {"type":47, "variation":5, "mode":1, "thickness":10}, {"type":30, "variation":5, "mode":1, "thickness":10}, {"minY":15, "mode":3, "maxY":20, "type":133, "width":120, "height":3, "veinCount":15}, {"type":5, "variation":5, "mode":1, "thickness":10}, {"minY":15, "mode":3, "maxY":35, "type":73, "width":80, "height":3, "veinCount":20}, {"type":44, "variation":5, "mode":2, "thickness":10}, {"minY":30, "mode":3, "maxY":30, "type":27, "width":60, "height":15, "veinCount":6}], "settleTime":80}, {"settleTime":160, "bottom":160, "layers":[{"type":20, "variation":3, "mode":1, "thickness":2}], "addGravityToSolids":1}]}',
["Caves v2"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"bottom\":4, \"layers\":[{\"type\":22, \"variation\":5, \"mode\":1, \"thickness\":85}, {\"type\":67, \"variation\":5, \"mode\":1, \"thickness\":65}, {\"type\":0, \"variation\":0, \"mode\":1, \"thickness\":5}, {\"type\":5, \"variation\":5, \"mode\":1, \"thickness\":20}, {\"type\":44, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"minY\":15, \"veinCount\":15, \"maxY\":60, \"type\":132, \"mode\":3, \"height\":3, \"width\":120}, {\"minY\":140, \"width\":80, \"maxY\":180, \"veinCount\":20, \"height\":3, \"mode\":3, \"type\":187}, {\"width\":100, \"type\":59, \"maxY\":100, \"veinCount\":30, \"mode\":3, \"height\":3, \"minY\":15}, {\"minY\":0, \"width\":120, \"maxY\":30, \"veinCount\":6, \"height\":3, \"mode\":3, \"type\":170}, {\"width\":200, \"minY\":60, \"maxY\":120, \"type\":0, \"height\":40, \"mode\":3, \"veinCount\":15}, {\"minY\":60, \"width\":30, \"maxY\":120, \"veinCount\":15, \"height\":50, \"mode\":3, \"type\":0}, {\"width\":70, \"type\":0, \"maxY\":150, \"veinCount\":1, \"mode\":3, \"height\":70, \"minY\":150}], \"settleTime\":120}, {\"bottom\":4, \"layers\":[{\"minY\":120, \"veinCount\":15, \"maxY\":160, \"type\":24, \"mode\":3, \"height\":100, \"width\":15}, {\"minY\":20, \"width\":15, \"maxY\":40, \"veinCount\":15, \"height\":100, \"mode\":3, \"type\":22}], \"settleTime\":120}, {\"bottom\":4, \"layers\":[{\"type\":190, \"variation\":10, \"mode\":1, \"thickness\":40}, {\"type\":142, \"variation\":10, \"mode\":1, \"thickness\":100}, {\"minY\":60, \"width\":120, \"maxY\":90, \"veinCount\":15, \"height\":10, \"mode\":3, \"type\":2}], \"settleTime\":30}, {\"bottom\":20, \"layers\":[{\"minY\":180, \"veinCount\":200, \"maxY\":190, \"type\":181, \"mode\":3, \"height\":1, \"width\":1}], \"settleTime\":60}, {\"bottom\":4, \"layers\":[{\"inLayer\":false, \"oldType\":22, \"inExisting\":true, \"type\":155, \"percent\":100, \"mode\":4, \"preserveProps\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":181, \"type\":114, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":142, \"inExisting\":true, \"type\":67, \"percent\":100, \"mode\":4, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"type\":28, \"variation\":0, \"mode\":1, \"thickness\":200}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":187, \"inLayer\":false, \"type\":179, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":67, \"mode\":4, \"type\":155, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":24, \"inLayer\":false, \"type\":155, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":5, \"inExisting\":true, \"type\":67, \"percent\":100, \"mode\":4, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":5, \"percent\":25, \"mode\":4, \"inExisting\":true}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inExisting\":true, \"type\":47, \"percent\":33, \"mode\":4, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":132, \"inExisting\":true, \"type\":133, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":59, \"inLayer\":false, \"type\":73, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":170, \"mode\":4, \"type\":135, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":179, \"inLayer\":false, \"type\":187, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":5, \"percent\":50, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"mode\":4, \"type\":30, \"percent\":100, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":5, \"inLayer\":false, \"type\":155, \"percent\":25, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":28, \"inLayer\":false, \"type\":0, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":5, \"mode\":4, \"type\":190, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":47, \"inLayer\":false, \"type\":45, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":67, \"inExisting\":true, \"type\":5, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":30, \"inLayer\":false, \"type\":67, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":73, \"inLayer\":false, \"type\":59, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":135, \"mode\":4, \"type\":170, \"percent\":100, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":100, \"layers\":[{\"type\":25, \"variation\":5, \"mode\":1, \"thickness\":4}, {\"type\":82, \"variation\":5, \"mode\":1, \"thickness\":4}], \"settleTime\":60}]}",
["Oasis v2"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"bottom\":0, \"layers\":[{\"type\":5, \"variation\":5, \"mode\":1, \"thickness\":50}, {\"minY\":15, \"width\":60, \"maxY\":20, \"veinCount\":15, \"height\":20, \"mode\":3, \"type\":0}, {\"type\":142, \"variation\":0, \"mode\":1, \"thickness\":30}, {\"type\":155, \"variation\":5, \"mode\":1, \"thickness\":50}, {\"width\":60, \"minY\":180, \"maxY\":200, \"type\":44, \"height\":10, \"mode\":3, \"veinCount\":10}, {\"width\":60, \"type\":142, \"maxY\":90, \"veinCount\":3, \"mode\":3, \"height\":120, \"minY\":90}, {\"width\":10, \"minY\":70, \"maxY\":80, \"type\":142, \"height\":30, \"mode\":3, \"veinCount\":15}, {\"width\":30, \"minY\":30, \"maxY\":60, \"type\":24, \"height\":120, \"mode\":3, \"veinCount\":2}], \"settleTime\":120}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":24, \"inLayer\":false, \"type\":119, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":5, \"inLayer\":false, \"type\":24, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":44, \"inExisting\":true, \"type\":5, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":155, \"mode\":4, \"type\":179, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":142, \"inLayer\":false, \"type\":2, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":60}, {\"bottom\":160, \"layers\":[{\"preserveProps\":false, \"oldType\":24, \"inLayer\":false, \"type\":190, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":5, \"inExisting\":true, \"type\":67, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":2, \"inLayer\":false, \"type\":68, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":true, \"oldType\":68, \"mode\":4, \"type\":22, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"type\":44, \"variation\":5, \"mode\":1, \"thickness\":10}], \"settleTime\":80}, {\"bottom\":170, \"layers\":[{\"width\":3, \"type\":25, \"maxY\":40, \"veinCount\":60, \"mode\":3, \"height\":3, \"minY\":0}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":13, \"inLayer\":false, \"type\":114, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":25, \"inExisting\":true, \"type\":0, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":22, \"inLayer\":false, \"type\":25, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":190, \"mode\":4, \"type\":190, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":67, \"inLayer\":false, \"type\":67, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":179, \"inExisting\":true, \"type\":179, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":44, \"inLayer\":false, \"type\":44, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":25, \"mode\":4, \"type\":28, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":190, \"mode\":4, \"type\":5, \"percent\":25, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":190, \"inLayer\":false, \"type\":155, \"percent\":33, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":190, \"inExisting\":true, \"type\":26, \"percent\":50, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":190, \"inLayer\":false, \"type\":113, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":5, \"inLayer\":false, \"type\":170, \"percent\":5, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":5, \"mode\":4, \"type\":188, \"percent\":5, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":5, \"inLayer\":false, \"type\":32, \"percent\":10, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":5, \"inExisting\":true, \"type\":19, \"percent\":10, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":5, \"inLayer\":false, \"type\":133, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":125, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":26, \"inExisting\":true, \"type\":5, \"percent\":15, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":26, \"inLayer\":false, \"type\":155, \"percent\":50, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":5, \"inLayer\":false, \"type\":30, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":26, \"mode\":4, \"type\":3, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":190, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":125, \"inExisting\":true, \"type\":187, \"percent\":50, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":125, \"inLayer\":false, \"type\":26, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":113, \"mode\":4, \"type\":155, \"percent\":50, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":26, \"inLayer\":false, \"type\":30, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":155, \"mode\":4, \"type\":73, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":113, \"inLayer\":false, \"type\":5, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":67, \"inExisting\":true, \"type\":116, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":25, \"inLayer\":false, \"type\":28, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":179, \"mode\":4, \"type\":5, \"percent\":40, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":179, \"inLayer\":false, \"type\":26, \"percent\":20, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":179, \"inExisting\":true, \"type\":155, \"percent\":100, \"mode\":4, \"inLayer\":false}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":5, \"inLayer\":false, \"type\":67, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":119, \"mode\":4, \"type\":67, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":44, \"inLayer\":false, \"type\":29, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":26, \"inExisting\":true, \"type\":132, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":155, \"inExisting\":true, \"type\":44, \"percent\":60, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":26, \"inLayer\":false, \"type\":44, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":44, \"inLayer\":false, \"type\":179, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":155, \"inExisting\":true, \"type\":44, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":116, \"inLayer\":false, \"type\":44, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":28, \"mode\":4, \"type\":25, \"percent\":100, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":60}, {\"bottom\":340, \"layers\":[{\"width\":50, \"minY\":0, \"maxY\":0, \"type\":13, \"height\":50, \"mode\":3, \"veinCount\":1}], \"settleTime\":0}, {\"bottom\":340, \"layers\":[{\"inLayer\":false, \"oldType\":13, \"inExisting\":true, \"type\":48, \"percent\":33, \"mode\":4, \"preserveProps\":false}, {\"inLayer\":false, \"oldType\":48, \"preserveProps\":true, \"type\":180, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":13, \"mode\":4, \"type\":180, \"percent\":100, \"inExisting\":true, \"preserveProps\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":true, \"oldType\":180, \"inLayer\":false, \"type\":171, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":0}]}",
["Hellscape v2"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"bottom\":4, \"layers\":[{\"type\":28, \"variation\":0, \"mode\":1, \"thickness\":10}, {\"type\":70, \"variation\":20, \"mode\":1, \"thickness\":346}, {\"type\":28, \"variation\":0, \"mode\":1, \"thickness\":20}, {\"width\":60, \"minY\":0, \"maxY\":20, \"type\":28, \"height\":30, \"mode\":3, \"veinCount\":15}, {\"width\":120, \"type\":28, \"maxY\":270, \"veinCount\":15, \"mode\":3, \"height\":5, \"minY\":100}, {\"width\":15, \"minY\":100, \"maxY\":270, \"type\":28, \"height\":60, \"mode\":3, \"veinCount\":12}, {\"width\":60, \"type\":70, \"maxY\":200, \"veinCount\":3, \"mode\":3, \"height\":150, \"minY\":170}, {\"minY\":170, \"veinCount\":3, \"maxY\":200, \"type\":28, \"mode\":3, \"height\":5, \"width\":300}, {\"minY\":80, \"width\":15, \"maxY\":80, \"veinCount\":3, \"height\":180, \"mode\":3, \"type\":28}, {\"width\":15, \"type\":28, \"maxY\":296, \"veinCount\":3, \"mode\":3, \"height\":180, \"minY\":296}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":28, \"mode\":4, \"type\":49, \"percent\":100, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":20}, {\"bottom\":4, \"layers\":[{\"preserveProps\":false, \"oldType\":70, \"mode\":4, \"type\":6, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":true, \"oldType\":6, \"inLayer\":false, \"type\":28, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":49, \"inLayer\":false, \"type\":22, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"thickness\":376, \"variation\":0, \"mode\":1, \"type\":22}], \"settleTime\":60}, {\"bottom\":4, \"layers\":[{\"preserveProps\":false, \"oldType\":28, \"mode\":4, \"type\":0, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":22, \"inLayer\":false, \"type\":6, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":true, \"oldType\":6, \"inExisting\":true, \"type\":28, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"type\":96, \"variation\":0, \"mode\":1, \"thickness\":300}, {\"preserveProps\":false, \"oldType\":96, \"mode\":4, \"type\":0, \"percent\":99.6, \"inExisting\":false, \"inLayer\":true}], \"settleTime\":0}, {\"layers\":[{\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":190, \"variation\":1, \"mode\":1, \"thickness\":40}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":59, \"variation\":1, \"mode\":1, \"thickness\":20}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":32, \"variation\":0, \"mode\":1, \"thickness\":1}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":190, \"variation\":1, \"mode\":1, \"thickness\":40}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":59, \"variation\":0, \"mode\":1, \"thickness\":20}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":32, \"variation\":0, \"mode\":1, \"thickness\":1}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":190, \"variation\":1, \"mode\":1, \"thickness\":40}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":59, \"variation\":0, \"mode\":1, \"thickness\":20}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":32, \"variation\":0, \"mode\":1, \"thickness\":1}, {\"width\":15, \"minY\":0, \"maxY\":300, \"type\":32, \"height\":5, \"mode\":3, \"veinCount\":15}, {\"width\":6, \"type\":144, \"maxY\":300, \"veinCount\":80, \"mode\":3, \"height\":40, \"minY\":0}], \"bottom\":50, \"addGravityToSolids\":true, \"settleTime\":0}, {\"settleTime\":120, \"bottom\":250, \"layers\":[{\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":190, \"variation\":1, \"mode\":1, \"thickness\":40}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":59, \"variation\":1, \"mode\":1, \"thickness\":20}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":32, \"variation\":0, \"mode\":1, \"thickness\":1}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":190, \"variation\":1, \"mode\":1, \"thickness\":40}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":59, \"variation\":0, \"mode\":1, \"thickness\":20}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":32, \"variation\":0, \"mode\":1, \"thickness\":1}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":190, \"variation\":1, \"mode\":1, \"thickness\":40}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":59, \"variation\":0, \"mode\":1, \"thickness\":20}, {\"type\":0, \"variation\":1, \"mode\":1, \"thickness\":5}, {\"type\":32, \"variation\":0, \"mode\":1, \"thickness\":1}, {\"minY\":0, \"veinCount\":15, \"maxY\":300, \"type\":19, \"mode\":3, \"height\":5, \"width\":15}], \"addGravityToSolids\":true}, {\"bottom\":40, \"layers\":[{\"type\":155, \"variation\":5, \"mode\":1, \"thickness\":300}, {\"preserveProps\":false, \"oldType\":155, \"inExisting\":false, \"type\":0, \"percent\":50, \"mode\":4, \"inLayer\":true}, {\"preserveProps\":false, \"oldType\":96, \"mode\":4, \"type\":0, \"percent\":100, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":40}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"mode\":4, \"type\":179, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"type\":44, \"variation\":0, \"mode\":1, \"thickness\":300}, {\"preserveProps\":false, \"oldType\":44, \"mode\":4, \"type\":73, \"percent\":33, \"inExisting\":false, \"inLayer\":true}, {\"preserveProps\":false, \"oldType\":44, \"inLayer\":true, \"type\":47, \"percent\":50, \"mode\":4, \"inExisting\":false}], \"settleTime\":60}, {\"bottom\":4, \"layers\":[{\"preserveProps\":false, \"oldType\":28, \"inExisting\":true, \"type\":0, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"type\":109, \"variation\":0, \"mode\":1, \"thickness\":3}, {\"type\":0, \"variation\":0, \"mode\":1, \"thickness\":370}, {\"type\":110, \"variation\":0, \"mode\":1, \"thickness\":3}], \"settleTime\":0}, {\"bottom\":20, \"layers\":[{\"type\":4, \"variation\":5, \"mode\":1, \"thickness\":5}, {\"type\":0, \"variation\":5, \"mode\":1, \"thickness\":300}, {\"type\":6, \"variation\":5, \"mode\":1, \"thickness\":40}], \"settleTime\":60}]}",
["'Splodeyland"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"addGravityToSolids\":true, \"bottom\":4, \"layers\":[{\"type\":0, \"variation\":5, \"mode\":1, \"thickness\":30}, {\"minY\":-10, \"veinCount\":6, \"maxY\":5, \"type\":70, \"mode\":3, \"height\":20, \"width\":120}, {\"type\":70, \"variation\":10, \"mode\":1, \"thickness\":20}, {\"width\":15, \"minY\":15, \"maxY\":20, \"type\":165, \"height\":15, \"mode\":3, \"veinCount\":15}], \"settleTime\":70}, {\"bottom\":4, \"layers\":[{\"width\":120, \"minY\":30, \"maxY\":50, \"type\":5, \"height\":120, \"mode\":3, \"veinCount\":3}, {\"minY\":-70, \"width\":20, \"maxY\":20, \"veinCount\":35, \"height\":180, \"mode\":3, \"type\":70}], \"settleTime\":0}, {\"bottom\":30, \"layers\":[{\"width\":7, \"type\":140, \"maxY\":20, \"veinCount\":1, \"mode\":3, \"height\":400, \"minY\":15}], \"settleTime\":0}, {\"settleTime\":200, \"bottom\":80, \"layers\":[{\"type\":65, \"variation\":5, \"mode\":2, \"thickness\":15}, {\"type\":41, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":69, \"variation\":35, \"mode\":2, \"thickness\":0}, {\"type\":139, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":7, \"variation\":35, \"mode\":1, \"thickness\":0}, {\"width\":80, \"minY\":15, \"maxY\":20, \"type\":8, \"height\":20, \"mode\":3, \"veinCount\":5}], \"addGravityToSolids\":true}, {\"bottom\":40, \"layers\":[{\"mode\":4, \"oldType\":5, \"type\":19, \"percent\":100, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":0}]}",
["Bombs"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"bottom\":4, \"layers\":[{\"type\":70, \"variation\":0, \"mode\":1, \"thickness\":400}, {\"width\":1, \"type\":44, \"maxY\":250, \"veinCount\":7, \"mode\":3, \"height\":1, \"minY\":0}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":44, \"type\":129, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":4, \"layers\":[{\"inLayer\":false, \"oldType\":49, \"type\":28, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"type\":106, \"variation\":0, \"mode\":1, \"thickness\":400}], \"settleTime\":0}, {\"bottom\":4, \"layers\":[{\"inLayer\":false, \"oldType\":49, \"type\":134, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":106, \"type\":39, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":4, \"layers\":[{\"inLayer\":false, \"oldType\":70, \"type\":0, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":39, \"type\":106, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":28, \"type\":28, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":134, \"type\":5, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":49, \"type\":9, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":160}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":5, \"type\":19, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":9, \"type\":144, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":173, \"type\":0, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":106, \"type\":36, \"percent\":50, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":106, \"type\":124, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"inLayer\":false, \"oldType\":28, \"type\":11, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":0, \"layers\":[{\"minY\":340, \"width\":50, \"maxY\":340, \"veinCount\":1, \"height\":50, \"mode\":3, \"type\":35}, {\"inLayer\":true, \"oldType\":35, \"type\":124, \"percent\":10, \"mode\":4}], \"settleTime\":0}]}",
["Matrix"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"bottom\":0, \"layers\":[{\"width\":120, \"type\":106, \"maxY\":400, \"veinCount\":400, \"mode\":3, \"height\":1, \"minY\":0}, {\"width\":1, \"minY\":0, \"maxY\":400, \"type\":106, \"height\":120, \"mode\":3, \"veinCount\":400}, {\"width\":70, \"minY\":0, \"maxY\":400, \"type\":56, \"height\":70, \"mode\":3, \"veinCount\":7}, {\"width\":7, \"minY\":0, \"maxY\":400, \"type\":36, \"height\":7, \"mode\":3, \"veinCount\":1000}, {\"minY\":0, \"veinCount\":1000, \"maxY\":400, \"type\":35, \"mode\":3, \"height\":7, \"width\":7}, {\"minY\":0, \"width\":1, \"maxY\":400, \"veinCount\":1000, \"height\":1, \"mode\":3, \"type\":126}, {\"width\":1, \"type\":124, \"maxY\":400, \"veinCount\":30, \"mode\":3, \"height\":1, \"minY\":0}], \"settleTime\":0}, {\"bottom\":20, \"layers\":[{\"type\":15, \"variation\":0, \"mode\":1, \"thickness\":30}, {\"type\":0, \"variation\":0, \"mode\":1, \"thickness\":120}, {\"type\":15, \"variation\":0, \"mode\":1, \"thickness\":30}, {\"type\":0, \"variation\":0, \"mode\":1, \"thickness\":120}, {\"type\":15, \"variation\":0, \"mode\":1, \"thickness\":30}], \"settleTime\":60}]}",
["Floating Islands"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"bottom\":4, \"layers\":[{\"type\":22, \"variation\":0, \"mode\":1, \"thickness\":4}, {\"type\":0, \"variation\":0, \"mode\":1, \"thickness\":100}, {\"type\":22, \"variation\":0, \"mode\":1, \"thickness\":4}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"type\":142, \"variation\":5, \"mode\":1, \"thickness\":5}, {\"type\":24, \"variation\":5, \"mode\":1, \"thickness\":30}, {\"width\":100, \"type\":113, \"maxY\":0, \"veinCount\":6, \"mode\":3, \"height\":5, \"minY\":0}, {\"width\":50, \"minY\":25, \"maxY\":35, \"type\":1, \"height\":20, \"mode\":3, \"veinCount\":6}], \"settleTime\":240}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":113, \"inExisting\":true, \"type\":190, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":142, \"inLayer\":false, \"type\":190, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":24, \"inLayer\":false, \"type\":155, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":60}, {\"bottom\":70, \"layers\":[{\"type\":2, \"variation\":5, \"mode\":1, \"thickness\":30}], \"settleTime\":160}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":22, \"mode\":4, \"type\":0, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":2, \"inLayer\":false, \"type\":0, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":111, \"inExisting\":true, \"type\":20, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":67, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":1, \"mode\":4, \"type\":170, \"percent\":100, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":80, \"layers\":[{\"type\":44, \"variation\":5, \"mode\":1, \"thickness\":100}], \"settleTime\":240}, {\"bottom\":4, \"layers\":[{\"thickness\":5, \"variation\":0, \"mode\":2, \"type\":22}, {\"thickness\":25, \"variation\":0, \"mode\":2, \"type\":0}, {\"thickness\":5, \"variation\":3, \"mode\":2, \"type\":142}, {\"thickness\":5, \"variation\":0, \"mode\":1, \"type\":190}, {\"preserveProps\":false, \"oldType\":44, \"inLayer\":false, \"type\":22, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"width\":7, \"minY\":30, \"maxY\":40, \"type\":190, \"height\":30, \"mode\":3, \"veinCount\":30}], \"settleTime\":100}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":142, \"inExisting\":true, \"type\":190, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":67, \"inLayer\":false, \"type\":155, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":170, \"mode\":4, \"type\":66, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":20, \"inLayer\":false, \"type\":181, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inExisting\":true, \"type\":5, \"percent\":25, \"mode\":4, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":133, \"percent\":33, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"mode\":4, \"type\":73, \"percent\":50, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":44, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":0}, {\"settleTime\":0, \"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":5, \"mode\":4, \"type\":155, \"percent\":50, \"inExisting\":true, \"inLayer\":true}, {\"preserveProps\":false, \"oldType\":66, \"inLayer\":true, \"type\":27, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"addGravityToSolids\":true}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":181, \"mode\":4, \"type\":20, \"percent\":100, \"inExisting\":true, \"inLayer\":true}, {\"preserveProps\":false, \"oldType\":22, \"inLayer\":true, \"type\":0, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":20, \"inLayer\":true, \"type\":114, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":0}]}",
["Planette"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"bottom\":4, \"layers\":[{\"type\":109, \"variation\":0, \"mode\":1, \"thickness\":3}, {\"type\":0, \"variation\":0, \"mode\":1, \"thickness\":370}, {\"type\":110, \"variation\":0, \"mode\":1, \"thickness\":3}], \"settleTime\":0}, {\"bottom\":0, \"layers\":[{\"minY\":0, \"width\":15, \"maxY\":400, \"veinCount\":20, \"height\":15, \"mode\":3, \"type\":177}, {\"width\":3, \"type\":2, \"maxY\":400, \"veinCount\":180, \"mode\":3, \"height\":3, \"minY\":0}], \"settleTime\":360}, {\"bottom\":4, \"layers\":[{\"preserveProps\":false, \"oldType\":177, \"inLayer\":false, \"type\":0, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":2, \"mode\":4, \"type\":154, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"minY\":0, \"veinCount\":30, \"maxY\":400, \"type\":2, \"mode\":3, \"height\":15, \"width\":15}, {\"minY\":0, \"width\":15, \"maxY\":400, \"veinCount\":30, \"height\":15, \"mode\":3, \"type\":152}, {\"width\":15, \"type\":3, \"maxY\":400, \"veinCount\":30, \"mode\":3, \"height\":15, \"minY\":0}, {\"width\":15, \"minY\":0, \"maxY\":400, \"type\":107, \"height\":15, \"mode\":3, \"veinCount\":90}], \"settleTime\":600}, {\"bottom\":4, \"layers\":[{\"preserveProps\":false, \"oldType\":152, \"inLayer\":false, \"type\":76, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":2, \"inExisting\":true, \"type\":14, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":107, \"mode\":4, \"type\":5, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":3, \"inLayer\":false, \"type\":44, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":109, \"mode\":4, \"type\":22, \"percent\":100, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":110, \"inLayer\":false, \"type\":22, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":200}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":44, \"inExisting\":true, \"type\":67, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":5, \"inLayer\":false, \"type\":155, \"percent\":100, \"inExisting\":true, \"mode\":4}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"mode\":4, \"type\":5, \"percent\":16, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":133, \"percent\":20, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":5, \"inExisting\":true, \"type\":144, \"percent\":100, \"mode\":4, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inExisting\":true, \"type\":5, \"percent\":25, \"mode\":4, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":73, \"percent\":33, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"mode\":4, \"type\":30, \"percent\":50, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":5, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":67, \"inExisting\":true, \"type\":155, \"percent\":100, \"mode\":4, \"inLayer\":false}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"preserveProps\":false, \"oldType\":76, \"inExisting\":true, \"type\":49, \"percent\":100, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":true, \"oldType\":49, \"inLayer\":false, \"type\":76, \"percent\":100, \"inExisting\":true, \"mode\":4}, {\"preserveProps\":false, \"oldType\":14, \"mode\":4, \"type\":0, \"percent\":90, \"inExisting\":true, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":155, \"inLayer\":false, \"type\":44, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"preserveProps\":false, \"oldType\":44, \"inExisting\":true, \"type\":27, \"percent\":10, \"mode\":4, \"inLayer\":false}, {\"preserveProps\":false, \"oldType\":44, \"inLayer\":false, \"type\":26, \"percent\":10, \"inExisting\":true, \"mode\":4}], \"settleTime\":0}, {\"bottom\":40, \"layers\":[{\"mode\":4, \"preserveProps\":false, \"oldType\":26, \"type\":114, \"percent\":100, \"inExisting\":true, \"inLayer\":false}], \"settleTime\":60}]}",
-- Credit to Jakav (id:2960309 with minor modifications)
["Gravity Hills"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"settleTime\":800, \"bottom\":40, \"layers\":[{\"type\":144, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":171, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":132, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":180, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":170, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":44, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":188, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":190, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":179, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":44, \"variation\":5, \"mode\":1, \"thickness\":10}, {\"type\":157, \"variation\":5, \"mode\":1, \"thickness\":30}, {\"type\":49, \"variation\":5, \"mode\":1, \"thickness\":30}], \"addGravityToSolids\":true}, {\"bottom\":0, \"layers\":[{\"type\":173, \"variation\":0, \"mode\":1, \"thickness\":100}], \"settleTime\":0}, {\"bottom\":0, \"layers\":[{\"inLayer\":false, \"oldType\":173, \"type\":37, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"inLayer\":false, \"oldType\":37, \"preserveProps\":true, \"type\":173, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":10}, {\"bottom\":0, \"layers\":[{\"inLayer\":false, \"oldType\":173, \"type\":0, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":0}]}",
-- Credit to z4dg (id:2960875)
["Islands"] = "{\"versionMinor\":1, \"versionMajor\":1, \"passes\":[{\"bottom\":40, \"layers\":[{\"minY\":15, \"width\":120, \"maxY\":20, \"veinCount\":2, \"height\":60, \"mode\":3, \"type\":5}], \"settleTime\":15}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":5, \"type\":24, \"percent\":35, \"mode\":4, \"inExisting\":true}, {\"minY\":0, \"width\":15, \"maxY\":20, \"veinCount\":15, \"height\":15, \"mode\":3, \"type\":5}, {\"type\":5, \"variation\":25, \"mode\":1, \"thickness\":2}], \"settleTime\":30}, {\"bottom\":60, \"layers\":[{\"inLayer\":false, \"oldType\":5, \"type\":24, \"percent\":25, \"mode\":4, \"inExisting\":true}, {\"inLayer\":false, \"oldType\":5, \"type\":190, \"percent\":25, \"mode\":4, \"inExisting\":true}, {\"type\":44, \"variation\":5, \"mode\":1, \"thickness\":5}], \"settleTime\":30}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":44, \"type\":5, \"percent\":25, \"mode\":4, \"inExisting\":true}, {\"inLayer\":false, \"oldType\":44, \"type\":190, \"percent\":25, \"mode\":4, \"inExisting\":true}, {\"type\":44, \"variation\":5, \"mode\":1, \"thickness\":15}], \"settleTime\":60}, {\"bottom\":30, \"layers\":[{\"type\":27, \"variation\":5, \"mode\":1, \"thickness\":5}], \"settleTime\":25}, {\"bottom\":45, \"layers\":[{\"minY\":0, \"width\":3, \"maxY\":5, \"type\":1, \"mode\":3, \"height\":1, \"veinCount\":100}], \"settleTime\":80}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":1, \"type\":114, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":1}, {\"bottom\":35, \"layers\":[{\"inLayer\":false, \"oldType\":27, \"type\":0, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"inLayer\":false, \"oldType\":20, \"type\":170, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"width\":1, \"minY\":0, \"maxY\":15, \"type\":1, \"height\":1, \"mode\":3, \"veinCount\":80}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":1, \"type\":114, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"inLayer\":false, \"oldType\":170, \"type\":180, \"percent\":25, \"mode\":4, \"inExisting\":true}], \"settleTime\":1}, {\"bottom\":23, \"layers\":[{\"inLayer\":false, \"oldType\":20, \"type\":180, \"percent\":100, \"mode\":4, \"inExisting\":true}, {\"type\":56, \"variation\":45, \"mode\":1, \"thickness\":0}], \"settleTime\":1}, {\"bottom\":25, \"layers\":[{\"type\":56, \"variation\":35, \"mode\":1, \"thickness\":0}], \"settleTime\":1}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":180, \"type\":179, \"percent\":25, \"mode\":4, \"inExisting\":true}], \"settleTime\":60}, {\"bottom\":0, \"layers\":[{\"type\":27, \"variation\":5, \"mode\":1, \"thickness\":50}], \"settleTime\":1}, {\"bottom\":65, \"layers\":[{\"minY\":0, \"width\":1, \"maxY\":20, \"veinCount\":50, \"height\":3, \"mode\":3, \"type\":1}], \"settleTime\":128}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":1, \"type\":114, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":60}, {\"bottom\":40, \"layers\":[{\"inLayer\":false, \"oldType\":20, \"type\":20, \"percent\":100, \"mode\":4, \"inExisting\":true}], \"settleTime\":1}]}",
}
local function loadSettings()
local f = io.open(SettingsPath, "r")
local loadedOptions
if f then
loadedOptions = json.parse(f:read("*all"))
f:close()
else
loadedOptions = {}
end
return loadedOptions
end
local function saveSettings(settingData)
local f = io.open(SettingsPath, "w")
f:write(json.stringify(settingData))
f:close()
end
local function initializeFileSystem()
-- Create missing directories
if not fs.exists(DataPath) then
-- If there is no data path then it's safe to assume the user has never used Territect before.
-- tpt.message_box("Notice", "Thank you for trying out the Territect beta! Please note that this is not a complete product and there may be undiscovered bugs that could cause crashes or loss of saved presets. Please report any bugs, oddities, or refinements you want to see using the 'Report Bug' option in the Territect menu.")
print("Thanks for downloading Territect! Open the Territect menu from the button on the top left.")
fs.makeDirectory(DataPath)
end
if not fs.exists(PresetPath) then
local f = io.open(PresetPath, "w")
f:write("{}")
f:close()
end
-- Initialize settings
local loadedSettings = loadSettings()
local defaultSettings = {
drawTerritectLogo = true,
showWarnings = true,
resetSimProps = true,
automaticBackups = true,
allowModdedElems = false,
backupNumber = 5,
}
for i, j in pairs(defaultSettings) do
if loadedSettings[i] == nil then
loadedSettings[i] = j
end
end
settings = loadedSettings
saveSettings(settings)
end
initializeFileSystem()
loadedPresets = {}
local selectedFolder = nil
local selectedPreset = nil
local function saveChanges()
local tableToSave = {}
for folderName,folderData in pairs(loadedPresets) do
if folderName ~= "Factory" then
tableToSave[folderName] = folderData
end
end
-- Write preset data to a temporary file to ensure data is protected and recoverable in event of a crash mid-saving
local g = io.open(TempPresetPath, "w")
g:write(json.stringify(tableToSave))
g:close()
-- while true do end -- Artificial crash for testing
local f = io.open(PresetPath, "w")
f:write(json.stringify(tableToSave))
f:close()
fs.removeFile(TempPresetPath)
end
-- Reload presets
function reloadPresets()
-- TODO: Current code does not account for possibility of corrupted data.
if fs.exists(TempPresetPath) then
local f = io.open(PresetPath, "r")
loadedPresets = json.parse(f:read("*all"))
end
local f = io.open(PresetPath, "r")
loadedPresets = json.parse(f:read("*all"))
loadedPresets["Factory"] = {}
for k,j in pairs(factoryPresets) do
if not loadedPresets["Factory"] then end
loadedPresets["Factory"][k] = j
end
end
reloadPresets()
-- Preset data embedding
local embedDeco = {
sizes = {55, 27, 11, 5, -1},
data = {
-- Colors for embedded Territect logos of various sizes.
-- TODO: Run-length encoding? This is currently responsible for a good 10% of the current file size.
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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},
},
colorPalette = {
4278190207, -- dark blue (default background color)
4278190335, -- blue
4278255360, -- green
4294967295, -- white
}
}
local function checksum(values)
local sum = 0
for i = 1, #values do
if i % 2 == 1 then
-- Weird checksum that works well enough
sum = bit.bxor(sum, (values[i] + (values[i + 1] or 0) * 0x100) * 45823) % 65536
end
end
return sum
end
function generatePresetChunks()
local presetDataClump = {
name = selectedPreset,
data = loadedPresets[selectedFolder][selectedPreset]
}
local stringData = json.stringify(presetDataClump)
-- Encode preset data in DMND particles
local dataToEncode = {}
for i = 1, #stringData do
local c = stringData:sub(i,i)
dataToEncode[i] = string.byte(c)
end
local dataChunks = {}
local chunkSize = 8 -- Number of bytes of data to be stored in each particle
local sum = checksum(dataToEncode) -- Checksum to guarantee integrity of encoded data
for i = 1, #dataToEncode do
local chunkIndex = math.floor((i - 1) / chunkSize) + 1
local partIndex = (i - 1) % chunkSize + 1
if partIndex == 1 then
dataChunks[chunkIndex] = {}
end
dataChunks[chunkIndex][partIndex] = dataToEncode[i]
end
return dataChunks, sum
end
function createEmbedParticle(x, y, ctype, life, tmp, tmp2, vtmp3, vtmp4, logoData)
if sim.pmap(x, y) then sim.partKill(sim.pmap(x, y)) end
local part = sim.partCreate(-3, x, y, elem.DEFAULT_PT_DMND)
sim.partProperty(part, "ctype", ctype)
sim.partProperty(part, "life", life)
sim.partProperty(part, "tmp", tmp)
sim.partProperty(part, "tmp2", tmp2)
sim.partProperty(part, tmp3, vtmp3)
sim.partProperty(part, tmp4, vtmp4)
if settings.drawTerritectLogo then
sim.partProperty(part, "dcolour", embedDeco.colorPalette[1])
if logoData and logoData.size < 5 then
local width = logoData.width
local rx, ry = x - logoData.originX, y - logoData.originY
if rx >= 0 and ry >= 0 and rx < width and ry < width then
sim.partProperty(part, "dcolour", embedDeco.colorPalette[embedDeco.data[logoData.size][ (rx % width) + (ry * width) + 1 ] + 1])
end
end
end
end
function embedPreset(chunks, x, y, width, height, sum)
local logoData = {
size = 1,
originX = 0,
originY = 0,
width = 0
}
while embedDeco.sizes[logoData.size] > math.min(width, height) and logoData.size < 5 do
logoData.size = logoData.size + 1
end
local dwidth = embedDeco.sizes[logoData.size]
logoData.originX, logoData.originY = x + math.floor((width - dwidth) / 2), y + math.floor((height - dwidth) / 2)
logoData.width = dwidth
-- Blank data particles
for i = 0, width - 1 do
for j = 0, height - 1 do
createEmbedParticle(x + i, y + j,
0, 0, 0, 0,
magicWord, -- "Tt" magic word used by data particles
2 * (i == 0 and 0 or 1) + 4 * (j == 0 and 0 or 1), -- Navigation indicator
logoData)
-- 2: Travel rightwards
-- 4: Travel upwards
end
end
createEmbedParticle(x, y,
sum, -- Checksum
#chunks, -- Number of chunks (particles)
width, height, -- tmp and tmp2
magicWord, -- "Tt" magic word used by data particles
1, -- Navigation indicator
logoData)
local maxj = 0
for j,k in pairs(chunks) do
createEmbedParticle(x + (j % width), y + math.floor(j / width),
(k[1] or 0) + (k[2] or 0) * 0x100,
(k[3] or 0) + (k[4] or 0) * 0x100,
(k[5] or 0) + (k[6] or 0) * 0x100,
(k[7] or 0) + (k[8] or 0) * 0x100,
magicWord, -- "Tt" magic word used by data particles
2 * (j % width == 0 and 0 or 1) + 4 * (math.floor(j / width) == 0 and 0 or 1), -- Navigation indicator
logoData)
-- 2: Travel rightwards
-- 4: Travel upwards
maxj = j + 1
end
createEmbedParticle(x + (maxj % width), y + math.floor(maxj / width),
0, 0, 0, 0,
magicWord, -- "Tt" magic word used by data particles
8 + 2 * (maxj % width == 0 and 0 or 1) + 4 * (math.floor(maxj / width) == 0 and 0 or 1), -- Navigation indicator
logoData)
-- for l = 0, width * height do
-- local dataPart = sim.partCreate(-1, x + (l % width), y + math.floor(l / width), elem.DEFAULT_PT_DMND)
-- sim.partProperty(dataPart, tmp3, magicWord) -- "Tt" magic word used by data particles
-- sim.partProperty(dataPart, tmp4, 4) -- Indicates that this is a filler particle
-- maxj = l + 1
-- end
end
local embeddingPreset
local embedData
local embedSum
local embedBoxX = 10
local embedBoxY = 10
local embedBoxWidth = 50
local embedBoxHeight = 50
local embedWindow = Window:new(1000, 0, 0 ,0)
local embedDataFits = true;
embedWindow:onDraw(function()
local particleCount = #embedData + 2
local embedSize = embedBoxWidth * embedBoxHeight
embedDataFits = particleCount <= embedSize
anyObstructingParticles = false
for i = 1, embedSize do
local cX, cY = embedBoxX + (i % embedBoxWidth), embedBoxY + math.floor(i / embedBoxHeight)
local id = sim.partID(cX, cY)
if id ~= nil then
anyObstructingParticles = true
break
end
end
local canPlace = embedDataFits
local r = embedDataFits and 0 or 255
local g = embedDataFits and 255 or 0
graphics.drawRect(embedBoxX, embedBoxY, embedBoxWidth, embedBoxHeight, 200, 200, 200)
graphics.fillRect(embedBoxX, embedBoxY, embedBoxWidth, embedBoxHeight, 0, 0, 0, 127)
graphics.fillRect(embedBoxX, embedBoxY, embedBoxWidth, math.floor(particleCount / embedBoxWidth), r, g, 0, 127)
graphics.fillRect(embedBoxX, embedBoxY + math.floor(particleCount / embedBoxWidth), particleCount % embedBoxWidth, 1, r, g, 0, 127)
local warningY = 345
if not embedDataFits then
graphics.drawText(16, warningY, "Warning: The current box size is too small to fit the preset data.", 255, 0, 0)
warningY = warningY - 15
end
if anyObstructingParticles then
graphics.drawText(16, warningY, "Warning: Particles under the box will be overwritten.", 255, 127, 0)
warningY = warningY - 15
end
graphics.drawText(16, 360, "Click to place. Scroll to adjust width (shift/ctrl for one dimension). Shift to move box precisely. Right-click to cancel.", 255, 255, 0)
end)
embedWindow:onMouseDown(function(x, y, button)
if not embedDataFits then
return
end
if button == 1 then -- Lmb
sim.takeSnapshot()
embedPreset(embedData, embedBoxX, embedBoxY, embedBoxWidth, embedBoxHeight, embedSum)
elseif button == 3 then -- Rmb
end
embeddingPreset = false
interface.closeWindow(embedWindow)
end)
local ctrlHeld = false
local shiftHeld = false
embedWindow:onMouseMove(function(x, y, dx, dy)
if shiftHeld then
embedBoxX, embedBoxY = embedBoxX + dx * 0.2, embedBoxY + dy * 0.2
else
embedBoxX, embedBoxY = sim.adjustCoords(x, y)
end
end)
embedWindow:onKeyPress(function(key, scan, r, shift, ctrl, alt) -- Detect shift or ctrl pressed
shiftHeld = scan == 225 or scan == 229
ctrlHeld = scan == 224 or scan == 228
end)
embedWindow:onKeyRelease(function(key, scan, r, shift, ctrl, alt) -- Detect shift or ctrl released
shiftHeld = scan == 225 or scan == 229
ctrlHeld = scan == 224 or scan == 228
end)
embedWindow:onMouseWheel(function(x, y, d)
if not shiftHeld then
embedBoxHeight = math.min(math.max(embedBoxHeight + d, 1), maxEmbedSize)
end
if not ctrlHeld then
embedBoxWidth = math.min(math.max(embedBoxWidth + d, 1), maxEmbedSize)
end
end)
event.register(event.tick, function()
if embeddingPreset then
interface.showWindow(embedWindow)
end
end)
-- Reading embedded preset data
local embedReading = {
foundEmbedded = false,
embedReadError = false,
errorPosition = false,
errorX = -1,
errorY = -1,
embeddedX = -1,
embeddedY = -1,
embeddedW = -1,
embeddedH = -1,
embeddedMessage,
embeddedName,
embeddedPreset,
embeddedHeaderID = -1, -- Used to prevent the same preset from being read several times on concurrent frames
warnings = {},
errorNum,
context,
}
event.register(event.tick, function()
local px, py = sim.adjustCoords(tpt.mousex, tpt.mousey)
local cursorPart = sim.pmap(px, py)
local readError
local refreshError = false
if not (cursorPart and sim.partProperty(cursorPart, tmp3) == magicWord) then
embedReading.embeddedHeaderID = -1
embedReading.foundEmbedded = false
embedReading.embeddedName = nil
embedReading.embeddedPreset = nil
return
else
embedReading.foundEmbedded = true
local guideValue = 0
local guidePart
local gx = px
local gy = py
-- Uses the information in particles' tmp4 values to navigate the head at gx, gy towards the top right header particle.
-- 1: Header particle
-- 2: Go right
-- 4: Go up
-- 8: Footer particle
local repeatLimit = 10000
repeat
guidePart = sim.pmap(gx, gy)
-- Ensure the head always stays on a data particle
if not guidePart then
readError = "Preset data ended before expected"
elseif sim.partProperty(guidePart, "type") ~= elem.DEFAULT_PT_DMND or sim.partProperty(guidePart, tmp3) ~= magicWord then
readError = "Found foreign particle while scanning preset data"
end
if readError then
embedReading.embeddedHeaderID = -1
embedReading.errorPosition = true
embedReading.errorX = gx
embedReading.errorY = gy
refreshError = true
goto embedReadingError
end
guideValue = sim.partProperty(guidePart, tmp4)
if bit.band(guideValue, 0x2) ~= 0 then
gx = gx - 1
end
if bit.band(guideValue, 0x4) ~= 0 then
gy = gy - 1
end
repeatLimit = repeatLimit - 1
until guideValue == 1 or repeatLimit == 0
if repeatLimit == 0 then
embedReading.errorPosition = false
readError = "Could not find header particle"
refreshError = true
goto embedReadingError
end
embedReading.embeddedX = gx
embedReading.embeddedY = gy
local headerPart = sim.pmap(gx, gy) -- We know this is a valid data part because of the previous steps
if embedReading.embeddedHeaderID ~= headerPart then
refreshError = true
embedReading.embeddedHeaderID = headerPart
local headerChecksum = sim.partProperty(headerPart, "ctype")
local chunkCount = sim.partProperty(headerPart, "life")
local width = sim.partProperty(headerPart, "tmp")
local height = sim.partProperty(headerPart, "tmp2")
embedReading.embeddedW = width
embedReading.embeddedH = height
local chunks = {}
-- Read data from particles
for i = 1, chunkCount do
local cx, cy = gx + (i % width), gy + math.floor(i / width)
local chunkPart = sim.pmap(cx, cy)
-- Ensure the head always stays on a data particle
if not chunkPart then
readError = "Preset data ended before expected"
elseif sim.partProperty(chunkPart, "type") ~= elem.DEFAULT_PT_DMND or sim.partProperty(chunkPart, tmp3) ~= magicWord then
readError = "Found foreign particle while scanning preset data"
end
if readError then
embedReading.errorPosition = true
embedReading.errorX = cx
embedReading.errorY = cy
goto embedReadingError
end
-- Extract text data from particle data
local bytes = {
sim.partProperty(chunkPart, "ctype"),
sim.partProperty(chunkPart, "life"),
sim.partProperty(chunkPart, "tmp"),
sim.partProperty(chunkPart, "tmp2"),
}
local chunk = {
string.char(bit.band(bytes[1], 0x00FF) / 0x0001),
string.char(bit.band(bytes[1], 0xFF00) / 0x0100),
string.char(bit.band(bytes[2], 0x00FF) / 0x0001),
string.char(bit.band(bytes[2], 0xFF00) / 0x0100),
string.char(bit.band(bytes[3], 0x00FF) / 0x0001),
string.char(bit.band(bytes[3], 0xFF00) / 0x0100),
string.char(bit.band(bytes[4], 0x00FF) / 0x0001),
string.char(bit.band(bytes[4], 0xFF00) / 0x0100),
}
table.insert(chunks, table.concat(chunk))
if i >= maxEmbedPartCt then
embedReading.errorPosition = false
readError = "Preset is above the maximum size of " .. maxEmbedPartCt .. " particles."
goto embedReadingError
end
end
-- No errors past this point are positional
embedReading.errorPosition = false
embedReading.errorX = -1
embedReading.errorY = -1
-- Convert chunks into text data
local presetText = table.concat(chunks)
-- Checksum
local checksumTable = {}
for i = 1, #presetText do
local c = presetText:sub(i,i)
checksumTable[i] = string.byte(c)
end
local sum = checksum(checksumTable) -- Checksum to guarantee integrity of encoded data
if sum ~= headerChecksum then
readError = "Checksum invalid - data may be corrupted or tampered with."
goto embedReadingError
end
-- Verify preset data contains JSON containing a valid preset
local validJson, table = pcall(json.parse, presetText)
if not validJson then
readError = "Preset data unreadable due to error in JSON formatting."
goto embedReadingError
end
if not table.data then
readError = "Preset data could not be found."
goto embedReadingError
end
embedReading.embeddedPreset = table.data
local validPresetJson, presetTable = pcall(json.parse, table.data)
if not validPresetJson then
readError = "Preset data unreadable due to error in JSON formatting."
goto embedReadingError
end
local validPreset, message, errorNum, context = verifyPresetIntegrity(presetTable)
if validPreset then
-- Hooray!
if #message > 0 and settings.showWarnings then
embedReading.embeddedMessage = "Download \"" .. table.name .. "\" Territect preset (" .. #message .. " warnings)"
else
embedReading.embeddedMessage = "Download \"" .. table.name .. "\" Territect preset"
end
embedReading.embeddedName = table.name
embedReading.warnings = message
embedReading.errorNum = nil
embedReading.context = nil
else
readError = message
embedReading.errorNum = errorNum