-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLdtkJson.py
More file actions
2633 lines (2246 loc) · 116 KB
/
LdtkJson.py
File metadata and controls
2633 lines (2246 loc) · 116 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
from enum import Enum
from dataclasses import dataclass
from typing import Any, List, Optional, Dict, TypeVar, Type, Callable, cast
T = TypeVar("T")
EnumT = TypeVar("EnumT", bound=Enum)
def from_str(x: Any) -> str:
assert isinstance(x, str)
return x
def to_enum(c: Type[EnumT], x: Any) -> EnumT:
assert isinstance(x, c)
return x.value
def from_list(f: Callable[[Any], T], x: Any) -> List[T]:
assert isinstance(x, list)
return [f(y) for y in x]
def from_bool(x: Any) -> bool:
assert isinstance(x, bool)
return x
def from_float(x: Any) -> float:
assert isinstance(x, (float, int)) and not isinstance(x, bool)
return float(x)
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_none(x: Any) -> Any:
assert x is None
return x
def from_union(fs, x):
for f in fs:
try:
return f(x)
except:
pass
assert False
def to_float(x: Any) -> float:
assert isinstance(x, (int, float))
return x
def to_class(c: Type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
def from_dict(f: Callable[[Any], T], x: Any) -> Dict[str, T]:
assert isinstance(x, dict)
return { k: f(v) for (k, v) in x.items() }
class When(Enum):
"""Possible values: `Manual`, `AfterLoad`, `BeforeSave`, `AfterSave`"""
AFTER_LOAD = "AfterLoad"
AFTER_SAVE = "AfterSave"
BEFORE_SAVE = "BeforeSave"
MANUAL = "Manual"
@dataclass
class LdtkCustomCommand:
command: str
when: When
"""Possible values: `Manual`, `AfterLoad`, `BeforeSave`, `AfterSave`"""
@staticmethod
def from_dict(obj: Any) -> 'LdtkCustomCommand':
assert isinstance(obj, dict)
command = from_str(obj.get("command"))
when = When(obj.get("when"))
return LdtkCustomCommand(command, when)
def to_dict(self) -> dict:
result: dict = {}
result["command"] = from_str(self.command)
result["when"] = to_enum(When, self.when)
return result
class AllowedRefs(Enum):
"""Possible values: `Any`, `OnlySame`, `OnlyTags`, `OnlySpecificEntity`"""
ANY = "Any"
ONLY_SAME = "OnlySame"
ONLY_SPECIFIC_ENTITY = "OnlySpecificEntity"
ONLY_TAGS = "OnlyTags"
class EditorDisplayMode(Enum):
"""Possible values: `Hidden`, `ValueOnly`, `NameAndValue`, `EntityTile`, `LevelTile`,
`Points`, `PointStar`, `PointPath`, `PointPathLoop`, `RadiusPx`, `RadiusGrid`,
`ArrayCountWithLabel`, `ArrayCountNoLabel`, `RefLinkBetweenPivots`,
`RefLinkBetweenCenters`
"""
ARRAY_COUNT_NO_LABEL = "ArrayCountNoLabel"
ARRAY_COUNT_WITH_LABEL = "ArrayCountWithLabel"
ENTITY_TILE = "EntityTile"
HIDDEN = "Hidden"
LEVEL_TILE = "LevelTile"
NAME_AND_VALUE = "NameAndValue"
POINTS = "Points"
POINT_PATH = "PointPath"
POINT_PATH_LOOP = "PointPathLoop"
POINT_STAR = "PointStar"
RADIUS_GRID = "RadiusGrid"
RADIUS_PX = "RadiusPx"
REF_LINK_BETWEEN_CENTERS = "RefLinkBetweenCenters"
REF_LINK_BETWEEN_PIVOTS = "RefLinkBetweenPivots"
VALUE_ONLY = "ValueOnly"
class EditorDisplayPos(Enum):
"""Possible values: `Above`, `Center`, `Beneath`"""
ABOVE = "Above"
BENEATH = "Beneath"
CENTER = "Center"
class EditorLinkStyle(Enum):
"""Possible values: `ZigZag`, `StraightArrow`, `CurvedArrow`, `ArrowsLine`, `DashedLine`"""
ARROWS_LINE = "ArrowsLine"
CURVED_ARROW = "CurvedArrow"
DASHED_LINE = "DashedLine"
STRAIGHT_ARROW = "StraightArrow"
ZIG_ZAG = "ZigZag"
class TextLanguageMode(Enum):
LANG_C = "LangC"
LANG_HAXE = "LangHaxe"
LANG_JS = "LangJS"
LANG_JSON = "LangJson"
LANG_LOG = "LangLog"
LANG_LUA = "LangLua"
LANG_MARKDOWN = "LangMarkdown"
LANG_PYTHON = "LangPython"
LANG_RUBY = "LangRuby"
LANG_XML = "LangXml"
@dataclass
class FieldDefinition:
"""This section is mostly only intended for the LDtk editor app itself. You can safely
ignore it.
"""
type: str
"""Human readable value type. Possible values: `Int, Float, String, Bool, Color,
ExternEnum.XXX, LocalEnum.XXX, Point, FilePath`.<br/> If the field is an array, this
field will look like `Array<...>` (eg. `Array<Int>`, `Array<Point>` etc.)<br/> NOTE: if
you enable the advanced option **Use Multilines type**, you will have "*Multilines*"
instead of "*String*" when relevant.
"""
allowed_refs: AllowedRefs
"""Possible values: `Any`, `OnlySame`, `OnlyTags`, `OnlySpecificEntity`"""
allowed_ref_tags: List[str]
allow_out_of_level_ref: bool
auto_chain_ref: bool
can_be_null: bool
"""TRUE if the value can be null. For arrays, TRUE means it can contain null values
(exception: array of Points can't have null values).
"""
editor_always_show: bool
editor_cut_long_values: bool
editor_display_mode: EditorDisplayMode
"""Possible values: `Hidden`, `ValueOnly`, `NameAndValue`, `EntityTile`, `LevelTile`,
`Points`, `PointStar`, `PointPath`, `PointPathLoop`, `RadiusPx`, `RadiusGrid`,
`ArrayCountWithLabel`, `ArrayCountNoLabel`, `RefLinkBetweenPivots`,
`RefLinkBetweenCenters`
"""
editor_display_pos: EditorDisplayPos
"""Possible values: `Above`, `Center`, `Beneath`"""
editor_display_scale: float
editor_link_style: EditorLinkStyle
"""Possible values: `ZigZag`, `StraightArrow`, `CurvedArrow`, `ArrowsLine`, `DashedLine`"""
editor_show_in_world: bool
export_to_toc: bool
"""If TRUE, the field value will be exported to the `toc` project JSON field. Only applies
to Entity fields.
"""
identifier: str
"""User defined unique identifier"""
is_array: bool
"""TRUE if the value is an array of multiple values"""
searchable: bool
"""If enabled, this field will be searchable through LDtk command palette"""
symmetrical_ref: bool
field_definition_type: str
"""Internal enum representing the possible field types. Possible values: F_Int, F_Float,
F_String, F_Text, F_Bool, F_Color, F_Enum(...), F_Point, F_Path, F_EntityRef, F_Tile
"""
uid: int
"""Unique Int identifier"""
use_for_smart_color: bool
"""If TRUE, the color associated with this field will override the Entity or Level default
color in the editor UI. For Enum fields, this would be the color associated to their
values.
"""
accept_file_types: Optional[List[str]] = None
"""Optional list of accepted file extensions for FilePath value type. Includes the dot:
`.ext`
"""
allowed_refs_entity_uid: Optional[int] = None
array_max_length: Optional[int] = None
"""Array max length"""
array_min_length: Optional[int] = None
"""Array min length"""
default_override: Any = None
"""Default value if selected value is null or invalid."""
doc: Optional[str] = None
"""User defined documentation for this field to provide help/tips to level designers about
accepted values.
"""
editor_display_color: Optional[str] = None
editor_text_prefix: Optional[str] = None
editor_text_suffix: Optional[str] = None
max: Optional[float] = None
"""Max limit for value, if applicable"""
min: Optional[float] = None
"""Min limit for value, if applicable"""
regex: Optional[str] = None
"""Optional regular expression that needs to be matched to accept values. Expected format:
`/some_reg_ex/g`, with optional "i" flag.
"""
text_language_mode: Optional[TextLanguageMode] = None
"""Possible values: <`null`>, `LangPython`, `LangRuby`, `LangJS`, `LangLua`, `LangC`,
`LangHaxe`, `LangMarkdown`, `LangJson`, `LangXml`, `LangLog`
"""
tileset_uid: Optional[int] = None
"""UID of the tileset used for a Tile"""
@staticmethod
def from_dict(obj: Any) -> 'FieldDefinition':
assert isinstance(obj, dict)
type = from_str(obj.get("__type"))
allowed_refs = AllowedRefs(obj.get("allowedRefs"))
allowed_ref_tags = from_list(from_str, obj.get("allowedRefTags"))
allow_out_of_level_ref = from_bool(obj.get("allowOutOfLevelRef"))
auto_chain_ref = from_bool(obj.get("autoChainRef"))
can_be_null = from_bool(obj.get("canBeNull"))
editor_always_show = from_bool(obj.get("editorAlwaysShow"))
editor_cut_long_values = from_bool(obj.get("editorCutLongValues"))
editor_display_mode = EditorDisplayMode(obj.get("editorDisplayMode"))
editor_display_pos = EditorDisplayPos(obj.get("editorDisplayPos"))
editor_display_scale = from_float(obj.get("editorDisplayScale"))
editor_link_style = EditorLinkStyle(obj.get("editorLinkStyle"))
editor_show_in_world = from_bool(obj.get("editorShowInWorld"))
export_to_toc = from_bool(obj.get("exportToToc"))
identifier = from_str(obj.get("identifier"))
is_array = from_bool(obj.get("isArray"))
searchable = from_bool(obj.get("searchable"))
symmetrical_ref = from_bool(obj.get("symmetricalRef"))
field_definition_type = from_str(obj.get("type"))
uid = from_int(obj.get("uid"))
use_for_smart_color = from_bool(obj.get("useForSmartColor"))
accept_file_types = from_union([from_none, lambda x: from_list(from_str, x)], obj.get("acceptFileTypes"))
allowed_refs_entity_uid = from_union([from_none, from_int], obj.get("allowedRefsEntityUid"))
array_max_length = from_union([from_none, from_int], obj.get("arrayMaxLength"))
array_min_length = from_union([from_none, from_int], obj.get("arrayMinLength"))
default_override = obj.get("defaultOverride")
doc = from_union([from_none, from_str], obj.get("doc"))
editor_display_color = from_union([from_none, from_str], obj.get("editorDisplayColor"))
editor_text_prefix = from_union([from_none, from_str], obj.get("editorTextPrefix"))
editor_text_suffix = from_union([from_none, from_str], obj.get("editorTextSuffix"))
max = from_union([from_none, from_float], obj.get("max"))
min = from_union([from_none, from_float], obj.get("min"))
regex = from_union([from_none, from_str], obj.get("regex"))
text_language_mode = from_union([from_none, TextLanguageMode], obj.get("textLanguageMode"))
tileset_uid = from_union([from_none, from_int], obj.get("tilesetUid"))
return FieldDefinition(type, allowed_refs, allowed_ref_tags, allow_out_of_level_ref, auto_chain_ref, can_be_null, editor_always_show, editor_cut_long_values, editor_display_mode, editor_display_pos, editor_display_scale, editor_link_style, editor_show_in_world, export_to_toc, identifier, is_array, searchable, symmetrical_ref, field_definition_type, uid, use_for_smart_color, accept_file_types, allowed_refs_entity_uid, array_max_length, array_min_length, default_override, doc, editor_display_color, editor_text_prefix, editor_text_suffix, max, min, regex, text_language_mode, tileset_uid)
def to_dict(self) -> dict:
result: dict = {}
result["__type"] = from_str(self.type)
result["allowedRefs"] = to_enum(AllowedRefs, self.allowed_refs)
result["allowedRefTags"] = from_list(from_str, self.allowed_ref_tags)
result["allowOutOfLevelRef"] = from_bool(self.allow_out_of_level_ref)
result["autoChainRef"] = from_bool(self.auto_chain_ref)
result["canBeNull"] = from_bool(self.can_be_null)
result["editorAlwaysShow"] = from_bool(self.editor_always_show)
result["editorCutLongValues"] = from_bool(self.editor_cut_long_values)
result["editorDisplayMode"] = to_enum(EditorDisplayMode, self.editor_display_mode)
result["editorDisplayPos"] = to_enum(EditorDisplayPos, self.editor_display_pos)
result["editorDisplayScale"] = to_float(self.editor_display_scale)
result["editorLinkStyle"] = to_enum(EditorLinkStyle, self.editor_link_style)
result["editorShowInWorld"] = from_bool(self.editor_show_in_world)
result["exportToToc"] = from_bool(self.export_to_toc)
result["identifier"] = from_str(self.identifier)
result["isArray"] = from_bool(self.is_array)
result["searchable"] = from_bool(self.searchable)
result["symmetricalRef"] = from_bool(self.symmetrical_ref)
result["type"] = from_str(self.field_definition_type)
result["uid"] = from_int(self.uid)
result["useForSmartColor"] = from_bool(self.use_for_smart_color)
if self.accept_file_types is not None:
result["acceptFileTypes"] = from_union([from_none, lambda x: from_list(from_str, x)], self.accept_file_types)
if self.allowed_refs_entity_uid is not None:
result["allowedRefsEntityUid"] = from_union([from_none, from_int], self.allowed_refs_entity_uid)
if self.array_max_length is not None:
result["arrayMaxLength"] = from_union([from_none, from_int], self.array_max_length)
if self.array_min_length is not None:
result["arrayMinLength"] = from_union([from_none, from_int], self.array_min_length)
if self.default_override is not None:
result["defaultOverride"] = self.default_override
if self.doc is not None:
result["doc"] = from_union([from_none, from_str], self.doc)
if self.editor_display_color is not None:
result["editorDisplayColor"] = from_union([from_none, from_str], self.editor_display_color)
if self.editor_text_prefix is not None:
result["editorTextPrefix"] = from_union([from_none, from_str], self.editor_text_prefix)
if self.editor_text_suffix is not None:
result["editorTextSuffix"] = from_union([from_none, from_str], self.editor_text_suffix)
if self.max is not None:
result["max"] = from_union([from_none, to_float], self.max)
if self.min is not None:
result["min"] = from_union([from_none, to_float], self.min)
if self.regex is not None:
result["regex"] = from_union([from_none, from_str], self.regex)
if self.text_language_mode is not None:
result["textLanguageMode"] = from_union([from_none, lambda x: to_enum(TextLanguageMode, x)], self.text_language_mode)
if self.tileset_uid is not None:
result["tilesetUid"] = from_union([from_none, from_int], self.tileset_uid)
return result
class LimitBehavior(Enum):
"""Possible values: `DiscardOldOnes`, `PreventAdding`, `MoveLastOne`"""
DISCARD_OLD_ONES = "DiscardOldOnes"
MOVE_LAST_ONE = "MoveLastOne"
PREVENT_ADDING = "PreventAdding"
class LimitScope(Enum):
"""If TRUE, the maxCount is a "per world" limit, if FALSE, it's a "per level". Possible
values: `PerLayer`, `PerLevel`, `PerWorld`
"""
PER_LAYER = "PerLayer"
PER_LEVEL = "PerLevel"
PER_WORLD = "PerWorld"
class RenderMode(Enum):
"""Possible values: `Rectangle`, `Ellipse`, `Tile`, `Cross`"""
CROSS = "Cross"
ELLIPSE = "Ellipse"
RECTANGLE = "Rectangle"
TILE = "Tile"
@dataclass
class TilesetRectangle:
"""This object represents a custom sub rectangle in a Tileset image."""
h: int
"""Height in pixels"""
tileset_uid: int
"""UID of the tileset"""
w: int
"""Width in pixels"""
x: int
"""X pixels coordinate of the top-left corner in the Tileset image"""
y: int
"""Y pixels coordinate of the top-left corner in the Tileset image"""
@staticmethod
def from_dict(obj: Any) -> 'TilesetRectangle':
assert isinstance(obj, dict)
h = from_int(obj.get("h"))
tileset_uid = from_int(obj.get("tilesetUid"))
w = from_int(obj.get("w"))
x = from_int(obj.get("x"))
y = from_int(obj.get("y"))
return TilesetRectangle(h, tileset_uid, w, x, y)
def to_dict(self) -> dict:
result: dict = {}
result["h"] = from_int(self.h)
result["tilesetUid"] = from_int(self.tileset_uid)
result["w"] = from_int(self.w)
result["x"] = from_int(self.x)
result["y"] = from_int(self.y)
return result
class TileRenderMode(Enum):
"""An enum describing how the the Entity tile is rendered inside the Entity bounds. Possible
values: `Cover`, `FitInside`, `Repeat`, `Stretch`, `FullSizeCropped`,
`FullSizeUncropped`, `NineSlice`
"""
COVER = "Cover"
FIT_INSIDE = "FitInside"
FULL_SIZE_CROPPED = "FullSizeCropped"
FULL_SIZE_UNCROPPED = "FullSizeUncropped"
NINE_SLICE = "NineSlice"
REPEAT = "Repeat"
STRETCH = "Stretch"
@dataclass
class EntityDefinition:
allow_out_of_bounds: bool
"""If enabled, this entity is allowed to stay outside of the current level bounds"""
color: str
"""Base entity color"""
export_to_toc: bool
"""If enabled, all instances of this entity will be listed in the project "Table of content"
object.
"""
field_defs: List[FieldDefinition]
"""Array of field definitions"""
fill_opacity: float
height: int
"""Pixel height"""
hollow: bool
identifier: str
"""User defined unique identifier"""
keep_aspect_ratio: bool
"""Only applies to entities resizable on both X/Y. If TRUE, the entity instance width/height
will keep the same aspect ratio as the definition.
"""
limit_behavior: LimitBehavior
"""Possible values: `DiscardOldOnes`, `PreventAdding`, `MoveLastOne`"""
limit_scope: LimitScope
"""If TRUE, the maxCount is a "per world" limit, if FALSE, it's a "per level". Possible
values: `PerLayer`, `PerLevel`, `PerWorld`
"""
line_opacity: float
max_count: int
"""Max instances count"""
nine_slice_borders: List[int]
"""An array of 4 dimensions for the up/right/down/left borders (in this order) when using
9-slice mode for `tileRenderMode`.<br/> If the tileRenderMode is not NineSlice, then
this array is empty.<br/> See: https://en.wikipedia.org/wiki/9-slice_scaling
"""
pivot_x: float
"""Pivot X coordinate (from 0 to 1.0)"""
pivot_y: float
"""Pivot Y coordinate (from 0 to 1.0)"""
render_mode: RenderMode
"""Possible values: `Rectangle`, `Ellipse`, `Tile`, `Cross`"""
resizable_x: bool
"""If TRUE, the entity instances will be resizable horizontally"""
resizable_y: bool
"""If TRUE, the entity instances will be resizable vertically"""
show_name: bool
"""Display entity name in editor"""
tags: List[str]
"""An array of strings that classifies this entity"""
tile_opacity: float
tile_render_mode: TileRenderMode
"""An enum describing how the the Entity tile is rendered inside the Entity bounds. Possible
values: `Cover`, `FitInside`, `Repeat`, `Stretch`, `FullSizeCropped`,
`FullSizeUncropped`, `NineSlice`
"""
uid: int
"""Unique Int identifier"""
width: int
"""Pixel width"""
doc: Optional[str] = None
"""User defined documentation for this element to provide help/tips to level designers."""
max_height: Optional[int] = None
"""Max pixel height (only applies if the entity is resizable on Y)"""
max_width: Optional[int] = None
"""Max pixel width (only applies if the entity is resizable on X)"""
min_height: Optional[int] = None
"""Min pixel height (only applies if the entity is resizable on Y)"""
min_width: Optional[int] = None
"""Min pixel width (only applies if the entity is resizable on X)"""
tile_id: Optional[int] = None
"""**WARNING**: this deprecated value is no longer exported since version 1.2.0 Replaced
by: `tileRect`
"""
tile_rect: Optional[TilesetRectangle] = None
"""An object representing a rectangle from an existing Tileset"""
tileset_id: Optional[int] = None
"""Tileset ID used for optional tile display"""
ui_tile_rect: Optional[TilesetRectangle] = None
"""This tile overrides the one defined in `tileRect` in the UI"""
@staticmethod
def from_dict(obj: Any) -> 'EntityDefinition':
assert isinstance(obj, dict)
allow_out_of_bounds = from_bool(obj.get("allowOutOfBounds"))
color = from_str(obj.get("color"))
export_to_toc = from_bool(obj.get("exportToToc"))
field_defs = from_list(FieldDefinition.from_dict, obj.get("fieldDefs"))
fill_opacity = from_float(obj.get("fillOpacity"))
height = from_int(obj.get("height"))
hollow = from_bool(obj.get("hollow"))
identifier = from_str(obj.get("identifier"))
keep_aspect_ratio = from_bool(obj.get("keepAspectRatio"))
limit_behavior = LimitBehavior(obj.get("limitBehavior"))
limit_scope = LimitScope(obj.get("limitScope"))
line_opacity = from_float(obj.get("lineOpacity"))
max_count = from_int(obj.get("maxCount"))
nine_slice_borders = from_list(from_int, obj.get("nineSliceBorders"))
pivot_x = from_float(obj.get("pivotX"))
pivot_y = from_float(obj.get("pivotY"))
render_mode = RenderMode(obj.get("renderMode"))
resizable_x = from_bool(obj.get("resizableX"))
resizable_y = from_bool(obj.get("resizableY"))
show_name = from_bool(obj.get("showName"))
tags = from_list(from_str, obj.get("tags"))
tile_opacity = from_float(obj.get("tileOpacity"))
tile_render_mode = TileRenderMode(obj.get("tileRenderMode"))
uid = from_int(obj.get("uid"))
width = from_int(obj.get("width"))
doc = from_union([from_none, from_str], obj.get("doc"))
max_height = from_union([from_none, from_int], obj.get("maxHeight"))
max_width = from_union([from_none, from_int], obj.get("maxWidth"))
min_height = from_union([from_none, from_int], obj.get("minHeight"))
min_width = from_union([from_none, from_int], obj.get("minWidth"))
tile_id = from_union([from_none, from_int], obj.get("tileId"))
tile_rect = from_union([from_none, TilesetRectangle.from_dict], obj.get("tileRect"))
tileset_id = from_union([from_none, from_int], obj.get("tilesetId"))
ui_tile_rect = from_union([from_none, TilesetRectangle.from_dict], obj.get("uiTileRect"))
return EntityDefinition(allow_out_of_bounds, color, export_to_toc, field_defs, fill_opacity, height, hollow, identifier, keep_aspect_ratio, limit_behavior, limit_scope, line_opacity, max_count, nine_slice_borders, pivot_x, pivot_y, render_mode, resizable_x, resizable_y, show_name, tags, tile_opacity, tile_render_mode, uid, width, doc, max_height, max_width, min_height, min_width, tile_id, tile_rect, tileset_id, ui_tile_rect)
def to_dict(self) -> dict:
result: dict = {}
result["allowOutOfBounds"] = from_bool(self.allow_out_of_bounds)
result["color"] = from_str(self.color)
result["exportToToc"] = from_bool(self.export_to_toc)
result["fieldDefs"] = from_list(lambda x: to_class(FieldDefinition, x), self.field_defs)
result["fillOpacity"] = to_float(self.fill_opacity)
result["height"] = from_int(self.height)
result["hollow"] = from_bool(self.hollow)
result["identifier"] = from_str(self.identifier)
result["keepAspectRatio"] = from_bool(self.keep_aspect_ratio)
result["limitBehavior"] = to_enum(LimitBehavior, self.limit_behavior)
result["limitScope"] = to_enum(LimitScope, self.limit_scope)
result["lineOpacity"] = to_float(self.line_opacity)
result["maxCount"] = from_int(self.max_count)
result["nineSliceBorders"] = from_list(from_int, self.nine_slice_borders)
result["pivotX"] = to_float(self.pivot_x)
result["pivotY"] = to_float(self.pivot_y)
result["renderMode"] = to_enum(RenderMode, self.render_mode)
result["resizableX"] = from_bool(self.resizable_x)
result["resizableY"] = from_bool(self.resizable_y)
result["showName"] = from_bool(self.show_name)
result["tags"] = from_list(from_str, self.tags)
result["tileOpacity"] = to_float(self.tile_opacity)
result["tileRenderMode"] = to_enum(TileRenderMode, self.tile_render_mode)
result["uid"] = from_int(self.uid)
result["width"] = from_int(self.width)
if self.doc is not None:
result["doc"] = from_union([from_none, from_str], self.doc)
if self.max_height is not None:
result["maxHeight"] = from_union([from_none, from_int], self.max_height)
if self.max_width is not None:
result["maxWidth"] = from_union([from_none, from_int], self.max_width)
if self.min_height is not None:
result["minHeight"] = from_union([from_none, from_int], self.min_height)
if self.min_width is not None:
result["minWidth"] = from_union([from_none, from_int], self.min_width)
if self.tile_id is not None:
result["tileId"] = from_union([from_none, from_int], self.tile_id)
if self.tile_rect is not None:
result["tileRect"] = from_union([from_none, lambda x: to_class(TilesetRectangle, x)], self.tile_rect)
if self.tileset_id is not None:
result["tilesetId"] = from_union([from_none, from_int], self.tileset_id)
if self.ui_tile_rect is not None:
result["uiTileRect"] = from_union([from_none, lambda x: to_class(TilesetRectangle, x)], self.ui_tile_rect)
return result
@dataclass
class EnumValueDefinition:
color: int
"""Optional color"""
id: str
"""Enum value"""
tile_src_rect: Optional[List[int]] = None
"""**WARNING**: this deprecated value is no longer exported since version 1.4.0 Replaced
by: `tileRect`
"""
tile_id: Optional[int] = None
"""**WARNING**: this deprecated value is no longer exported since version 1.4.0 Replaced
by: `tileRect`
"""
tile_rect: Optional[TilesetRectangle] = None
"""Optional tileset rectangle to represents this value"""
@staticmethod
def from_dict(obj: Any) -> 'EnumValueDefinition':
assert isinstance(obj, dict)
color = from_int(obj.get("color"))
id = from_str(obj.get("id"))
tile_src_rect = from_union([from_none, lambda x: from_list(from_int, x)], obj.get("__tileSrcRect"))
tile_id = from_union([from_none, from_int], obj.get("tileId"))
tile_rect = from_union([from_none, TilesetRectangle.from_dict], obj.get("tileRect"))
return EnumValueDefinition(color, id, tile_src_rect, tile_id, tile_rect)
def to_dict(self) -> dict:
result: dict = {}
result["color"] = from_int(self.color)
result["id"] = from_str(self.id)
if self.tile_src_rect is not None:
result["__tileSrcRect"] = from_union([from_none, lambda x: from_list(from_int, x)], self.tile_src_rect)
if self.tile_id is not None:
result["tileId"] = from_union([from_none, from_int], self.tile_id)
if self.tile_rect is not None:
result["tileRect"] = from_union([from_none, lambda x: to_class(TilesetRectangle, x)], self.tile_rect)
return result
@dataclass
class EnumDefinition:
identifier: str
"""User defined unique identifier"""
tags: List[str]
"""An array of user-defined tags to organize the Enums"""
uid: int
"""Unique Int identifier"""
values: List[EnumValueDefinition]
"""All possible enum values, with their optional Tile infos."""
external_file_checksum: Optional[str] = None
external_rel_path: Optional[str] = None
"""Relative path to the external file providing this Enum"""
icon_tileset_uid: Optional[int] = None
"""Tileset UID if provided"""
@staticmethod
def from_dict(obj: Any) -> 'EnumDefinition':
assert isinstance(obj, dict)
identifier = from_str(obj.get("identifier"))
tags = from_list(from_str, obj.get("tags"))
uid = from_int(obj.get("uid"))
values = from_list(EnumValueDefinition.from_dict, obj.get("values"))
external_file_checksum = from_union([from_none, from_str], obj.get("externalFileChecksum"))
external_rel_path = from_union([from_none, from_str], obj.get("externalRelPath"))
icon_tileset_uid = from_union([from_none, from_int], obj.get("iconTilesetUid"))
return EnumDefinition(identifier, tags, uid, values, external_file_checksum, external_rel_path, icon_tileset_uid)
def to_dict(self) -> dict:
result: dict = {}
result["identifier"] = from_str(self.identifier)
result["tags"] = from_list(from_str, self.tags)
result["uid"] = from_int(self.uid)
result["values"] = from_list(lambda x: to_class(EnumValueDefinition, x), self.values)
if self.external_file_checksum is not None:
result["externalFileChecksum"] = from_union([from_none, from_str], self.external_file_checksum)
if self.external_rel_path is not None:
result["externalRelPath"] = from_union([from_none, from_str], self.external_rel_path)
if self.icon_tileset_uid is not None:
result["iconTilesetUid"] = from_union([from_none, from_int], self.icon_tileset_uid)
return result
class Checker(Enum):
"""Checker mode Possible values: `None`, `Horizontal`, `Vertical`"""
HORIZONTAL = "Horizontal"
NONE = "None"
VERTICAL = "Vertical"
class TileMode(Enum):
"""Defines how tileIds array is used Possible values: `Single`, `Stamp`"""
SINGLE = "Single"
STAMP = "Stamp"
@dataclass
class AutoLayerRuleDefinition:
"""This complex section isn't meant to be used by game devs at all, as these rules are
completely resolved internally by the editor before any saving. You should just ignore
this part.
"""
active: bool
"""If FALSE, the rule effect isn't applied, and no tiles are generated."""
alpha: float
break_on_match: bool
"""When TRUE, the rule will prevent other rules to be applied in the same cell if it matches
(TRUE by default).
"""
chance: float
"""Chances for this rule to be applied (0 to 1)"""
checker: Checker
"""Checker mode Possible values: `None`, `Horizontal`, `Vertical`"""
flip_x: bool
"""If TRUE, allow rule to be matched by flipping its pattern horizontally"""
flip_y: bool
"""If TRUE, allow rule to be matched by flipping its pattern vertically"""
invalidated: bool
"""If TRUE, then the rule should be re-evaluated by the editor at one point"""
pattern: List[int]
"""Rule pattern (size x size)"""
perlin_active: bool
"""If TRUE, enable Perlin filtering to only apply rule on specific random area"""
perlin_octaves: float
perlin_scale: float
perlin_seed: float
pivot_x: float
"""X pivot of a tile stamp (0-1)"""
pivot_y: float
"""Y pivot of a tile stamp (0-1)"""
size: int
"""Pattern width & height. Should only be 1,3,5 or 7."""
tile_mode: TileMode
"""Defines how tileIds array is used Possible values: `Single`, `Stamp`"""
tile_random_x_max: int
"""Max random offset for X tile pos"""
tile_random_x_min: int
"""Min random offset for X tile pos"""
tile_random_y_max: int
"""Max random offset for Y tile pos"""
tile_random_y_min: int
"""Min random offset for Y tile pos"""
tile_rects_ids: List[List[int]]
"""Array containing all the possible tile IDs rectangles (picked randomly)."""
tile_x_offset: int
"""Tile X offset"""
tile_y_offset: int
"""Tile Y offset"""
uid: int
"""Unique Int identifier"""
x_modulo: int
"""X cell coord modulo"""
x_offset: int
"""X cell start offset"""
y_modulo: int
"""Y cell coord modulo"""
y_offset: int
"""Y cell start offset"""
out_of_bounds_value: Optional[int] = None
"""Default IntGrid value when checking cells outside of level bounds"""
tile_ids: Optional[List[int]] = None
"""**WARNING**: this deprecated value is no longer exported since version 1.5.0 Replaced
by: `tileRectsIds`
"""
@staticmethod
def from_dict(obj: Any) -> 'AutoLayerRuleDefinition':
assert isinstance(obj, dict)
active = from_bool(obj.get("active"))
alpha = from_float(obj.get("alpha"))
break_on_match = from_bool(obj.get("breakOnMatch"))
chance = from_float(obj.get("chance"))
checker = Checker(obj.get("checker"))
flip_x = from_bool(obj.get("flipX"))
flip_y = from_bool(obj.get("flipY"))
invalidated = from_bool(obj.get("invalidated"))
pattern = from_list(from_int, obj.get("pattern"))
perlin_active = from_bool(obj.get("perlinActive"))
perlin_octaves = from_float(obj.get("perlinOctaves"))
perlin_scale = from_float(obj.get("perlinScale"))
perlin_seed = from_float(obj.get("perlinSeed"))
pivot_x = from_float(obj.get("pivotX"))
pivot_y = from_float(obj.get("pivotY"))
size = from_int(obj.get("size"))
tile_mode = TileMode(obj.get("tileMode"))
tile_random_x_max = from_int(obj.get("tileRandomXMax"))
tile_random_x_min = from_int(obj.get("tileRandomXMin"))
tile_random_y_max = from_int(obj.get("tileRandomYMax"))
tile_random_y_min = from_int(obj.get("tileRandomYMin"))
tile_rects_ids = from_list(lambda x: from_list(from_int, x), obj.get("tileRectsIds"))
tile_x_offset = from_int(obj.get("tileXOffset"))
tile_y_offset = from_int(obj.get("tileYOffset"))
uid = from_int(obj.get("uid"))
x_modulo = from_int(obj.get("xModulo"))
x_offset = from_int(obj.get("xOffset"))
y_modulo = from_int(obj.get("yModulo"))
y_offset = from_int(obj.get("yOffset"))
out_of_bounds_value = from_union([from_none, from_int], obj.get("outOfBoundsValue"))
tile_ids = from_union([from_none, lambda x: from_list(from_int, x)], obj.get("tileIds"))
return AutoLayerRuleDefinition(active, alpha, break_on_match, chance, checker, flip_x, flip_y, invalidated, pattern, perlin_active, perlin_octaves, perlin_scale, perlin_seed, pivot_x, pivot_y, size, tile_mode, tile_random_x_max, tile_random_x_min, tile_random_y_max, tile_random_y_min, tile_rects_ids, tile_x_offset, tile_y_offset, uid, x_modulo, x_offset, y_modulo, y_offset, out_of_bounds_value, tile_ids)
def to_dict(self) -> dict:
result: dict = {}
result["active"] = from_bool(self.active)
result["alpha"] = to_float(self.alpha)
result["breakOnMatch"] = from_bool(self.break_on_match)
result["chance"] = to_float(self.chance)
result["checker"] = to_enum(Checker, self.checker)
result["flipX"] = from_bool(self.flip_x)
result["flipY"] = from_bool(self.flip_y)
result["invalidated"] = from_bool(self.invalidated)
result["pattern"] = from_list(from_int, self.pattern)
result["perlinActive"] = from_bool(self.perlin_active)
result["perlinOctaves"] = to_float(self.perlin_octaves)
result["perlinScale"] = to_float(self.perlin_scale)
result["perlinSeed"] = to_float(self.perlin_seed)
result["pivotX"] = to_float(self.pivot_x)
result["pivotY"] = to_float(self.pivot_y)
result["size"] = from_int(self.size)
result["tileMode"] = to_enum(TileMode, self.tile_mode)
result["tileRandomXMax"] = from_int(self.tile_random_x_max)
result["tileRandomXMin"] = from_int(self.tile_random_x_min)
result["tileRandomYMax"] = from_int(self.tile_random_y_max)
result["tileRandomYMin"] = from_int(self.tile_random_y_min)
result["tileRectsIds"] = from_list(lambda x: from_list(from_int, x), self.tile_rects_ids)
result["tileXOffset"] = from_int(self.tile_x_offset)
result["tileYOffset"] = from_int(self.tile_y_offset)
result["uid"] = from_int(self.uid)
result["xModulo"] = from_int(self.x_modulo)
result["xOffset"] = from_int(self.x_offset)
result["yModulo"] = from_int(self.y_modulo)
result["yOffset"] = from_int(self.y_offset)
if self.out_of_bounds_value is not None:
result["outOfBoundsValue"] = from_union([from_none, from_int], self.out_of_bounds_value)
if self.tile_ids is not None:
result["tileIds"] = from_union([from_none, lambda x: from_list(from_int, x)], self.tile_ids)
return result
@dataclass
class AutoLayerRuleGroup:
active: bool
biome_requirement_mode: int
is_optional: bool
name: str
required_biome_values: List[str]
rules: List[AutoLayerRuleDefinition]
uid: int
uses_wizard: bool
collapsed: Optional[bool] = None
"""*This field was removed in 1.0.0 and should no longer be used.*"""
color: Optional[str] = None
icon: Optional[TilesetRectangle] = None
@staticmethod
def from_dict(obj: Any) -> 'AutoLayerRuleGroup':
assert isinstance(obj, dict)
active = from_bool(obj.get("active"))
biome_requirement_mode = from_int(obj.get("biomeRequirementMode"))
is_optional = from_bool(obj.get("isOptional"))
name = from_str(obj.get("name"))
required_biome_values = from_list(from_str, obj.get("requiredBiomeValues"))
rules = from_list(AutoLayerRuleDefinition.from_dict, obj.get("rules"))
uid = from_int(obj.get("uid"))
uses_wizard = from_bool(obj.get("usesWizard"))
collapsed = from_union([from_none, from_bool], obj.get("collapsed"))
color = from_union([from_none, from_str], obj.get("color"))
icon = from_union([from_none, TilesetRectangle.from_dict], obj.get("icon"))
return AutoLayerRuleGroup(active, biome_requirement_mode, is_optional, name, required_biome_values, rules, uid, uses_wizard, collapsed, color, icon)
def to_dict(self) -> dict:
result: dict = {}
result["active"] = from_bool(self.active)
result["biomeRequirementMode"] = from_int(self.biome_requirement_mode)
result["isOptional"] = from_bool(self.is_optional)
result["name"] = from_str(self.name)
result["requiredBiomeValues"] = from_list(from_str, self.required_biome_values)
result["rules"] = from_list(lambda x: to_class(AutoLayerRuleDefinition, x), self.rules)
result["uid"] = from_int(self.uid)
result["usesWizard"] = from_bool(self.uses_wizard)
if self.collapsed is not None:
result["collapsed"] = from_union([from_none, from_bool], self.collapsed)
if self.color is not None:
result["color"] = from_union([from_none, from_str], self.color)
if self.icon is not None:
result["icon"] = from_union([from_none, lambda x: to_class(TilesetRectangle, x)], self.icon)
return result
@dataclass
class IntGridValueDefinition:
"""IntGrid value definition"""
color: str
group_uid: int
"""Parent group identifier (0 if none)"""
value: int
"""The IntGrid value itself"""
identifier: Optional[str] = None
"""User defined unique identifier"""
tile: Optional[TilesetRectangle] = None
@staticmethod
def from_dict(obj: Any) -> 'IntGridValueDefinition':
assert isinstance(obj, dict)
color = from_str(obj.get("color"))
group_uid = from_int(obj.get("groupUid"))
value = from_int(obj.get("value"))
identifier = from_union([from_none, from_str], obj.get("identifier"))
tile = from_union([from_none, TilesetRectangle.from_dict], obj.get("tile"))
return IntGridValueDefinition(color, group_uid, value, identifier, tile)
def to_dict(self) -> dict:
result: dict = {}
result["color"] = from_str(self.color)
result["groupUid"] = from_int(self.group_uid)
result["value"] = from_int(self.value)
if self.identifier is not None:
result["identifier"] = from_union([from_none, from_str], self.identifier)
if self.tile is not None:
result["tile"] = from_union([from_none, lambda x: to_class(TilesetRectangle, x)], self.tile)
return result
@dataclass
class IntGridValueGroupDefinition:
"""IntGrid value group definition"""
uid: int
"""Group unique ID"""
color: Optional[str] = None
"""User defined color"""
identifier: Optional[str] = None
"""User defined string identifier"""