-
Notifications
You must be signed in to change notification settings - Fork 322
Expand file tree
/
Copy pathUndertaleGameObject.cs
More file actions
1671 lines (1577 loc) · 48.4 KB
/
UndertaleGameObject.cs
File metadata and controls
1671 lines (1577 loc) · 48.4 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
namespace UndertaleModLib.Models;
//TODO: shouldn't this be inside of the UGameObject class?
/// <summary>
/// Collision shapes an <see cref="UndertaleGameObject"/> can use.
/// </summary>
public enum CollisionShapeFlags : uint
{
/// <summary>
/// A circular collision shape.
/// </summary>
Circle = 0,
/// <summary>
/// A rectangular collision shape.
/// </summary>
Box = 1,
/// <summary>
/// A custom polygonal collision shape.
/// </summary>
Custom = 2,
}
/// <summary>
/// A game object in a data file.
/// </summary>
public class UndertaleGameObject : UndertaleNamedResource, INotifyPropertyChanged, IDisposable
{
public UndertaleResourceById<UndertaleSprite, UndertaleChunkSPRT> _sprite = new();
public UndertaleResourceById<UndertaleGameObject, UndertaleChunkOBJT> _parentId = new();
public UndertaleResourceById<UndertaleSprite, UndertaleChunkSPRT> _textureMaskId = new();
public static readonly int EventTypeCount = Enum.GetValues(typeof(EventType)).Length;
/// <summary>
/// The name of the game object.
/// </summary>
public UndertaleString Name { get; set; }
/// <summary>
/// The sprite this game object uses.
/// </summary>
public UndertaleSprite Sprite { get => _sprite.Resource; set { _sprite.Resource = value; OnPropertyChanged(); } }
/// <summary>
/// Whether the game object is visible.
/// </summary>
public bool Visible { get; set; } = true;
// TODO: This summary
public bool Managed { get; set; }
/// <summary>
/// Whether the game object is solid.
/// </summary>
public bool Solid { get; set; }
/// <summary>
/// The depth level of the game object.
/// </summary>
public int Depth { get; set; }
/// <summary>
/// Whether the game object is persistent.
/// </summary>
public bool Persistent { get; set; }
/// <summary>
/// The parent game object this is inheriting from.
/// </summary>
public UndertaleGameObject ParentId { get => _parentId.Resource; set { _parentId.Resource = value; OnPropertyChanged(); } }
/// <summary>
/// The texture mask this game object is using.
/// </summary>
public UndertaleSprite TextureMaskId { get => _textureMaskId.Resource; set { _textureMaskId.Resource = value; OnPropertyChanged(); } }
#region Physics related properties
/// <summary>
/// Whether this object uses Game Maker physics.
/// </summary>
public bool UsesPhysics { get; set; }
/// <summary>
/// Whether this game object should act as a sensor fixture.
/// </summary>
public bool IsSensor { get; set; }
/// <summary>
/// The collision shape the game object should use.
/// </summary>
public CollisionShapeFlags CollisionShape { get; set; } = CollisionShapeFlags.Circle;
/// <summary>
/// The physics density of the game object.
/// </summary>
public float Density { get; set; } = 0.5f;
/// <summary>
/// The physics restitution of the game object.
/// </summary>
public float Restitution { get; set; } = 0.1f;
/// <summary>
/// The physics collision group this game object belongs to.
/// </summary>
public uint Group { get; set; }
/// <summary>
/// The physics linear damping this game object uses.
/// </summary>
public float LinearDamping { get; set; } = 0.1f;
/// <summary>
/// The physics angular damping this game object uses.
/// </summary>
public float AngularDamping { get; set; } = 0.1f;
/// <summary>
/// The physics friction this game object uses.
/// </summary>
public float Friction { get; set; } = 0.2f;
/// <summary>
/// Whether this game object should start awake in the physics simulation.
/// </summary>
public bool Awake { get; set; }
/// <summary>
/// Whether this game object is kinematic.
/// </summary>
public bool Kinematic { get; set; }
/// <summary>
/// The vertices used for a <see cref="CollisionShape"/> of type <see cref="CollisionShapeFlags.Custom"/>.
/// </summary>
public List<UndertalePhysicsVertex> PhysicsVertices { get; set; } = new List<UndertalePhysicsVertex>();
#endregion
/// <summary>
/// All the events that this game object has.
/// </summary>
public UndertalePointerList<UndertalePointerList<Event>> Events { get; set; } = new();
/// <inheritdoc />
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Invoked whenever the effective value of any dependency property has been updated.
/// </summary>
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
/// <summary>
/// Initialized an instance of <see cref="UndertaleGameObject"/>.
/// </summary>
public UndertaleGameObject()
{
Events.SetCapacity(EventTypeCount);
for (int i = 0; i < EventTypeCount; i++)
Events.InternalAdd(new UndertalePointerList<Event>());
}
/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
{
writer.WriteUndertaleString(Name);
writer.WriteUndertaleObject(_sprite);
writer.Write(Visible);
if (writer.undertaleData.IsVersionAtLeast(2022, 5))
writer.Write(Managed);
writer.Write(Solid);
writer.Write(Depth);
writer.Write(Persistent);
writer.WriteUndertaleObject(_parentId);
writer.WriteUndertaleObject(_textureMaskId);
writer.Write(UsesPhysics);
writer.Write(IsSensor);
writer.Write((uint)CollisionShape);
writer.Write(Density);
writer.Write(Restitution);
writer.Write(Group);
writer.Write(LinearDamping);
writer.Write(AngularDamping);
writer.Write(PhysicsVertices.Count); // possible (now confirmed) meaning: https://github.com/WarlockD/GMdsam/blob/26aefe3e90a7a7a1891cb83f468079546f32b4b7/GMdsam/GameMaker/ChunkTypes.cs#L553
writer.Write(Friction);
writer.Write(Awake);
writer.Write(Kinematic);
// Need to write these manually because the count is unfortunately separated
foreach (UndertalePhysicsVertex v in PhysicsVertices)
{
v.Serialize(writer);
}
writer.WriteUndertaleObject(Events);
}
/// <inheritdoc />
public void Unserialize(UndertaleReader reader)
{
Name = reader.ReadUndertaleString();
_sprite = reader.ReadUndertaleObject<UndertaleResourceById<UndertaleSprite, UndertaleChunkSPRT>>();
Visible = reader.ReadBoolean();
if (reader.undertaleData.IsVersionAtLeast(2022, 5))
Managed = reader.ReadBoolean();
Solid = reader.ReadBoolean();
Depth = reader.ReadInt32();
Persistent = reader.ReadBoolean();
_parentId = reader.ReadUndertaleObject<UndertaleResourceById<UndertaleGameObject, UndertaleChunkOBJT>>();
_textureMaskId = reader.ReadUndertaleObject<UndertaleResourceById<UndertaleSprite, UndertaleChunkSPRT>>();
UsesPhysics = reader.ReadBoolean();
IsSensor = reader.ReadBoolean();
CollisionShape = (CollisionShapeFlags)reader.ReadUInt32();
Density = reader.ReadSingle();
Restitution = reader.ReadSingle();
Group = reader.ReadUInt32();
LinearDamping = reader.ReadSingle();
AngularDamping = reader.ReadSingle();
int physicsShapeVertexCount = reader.ReadInt32();
Friction = reader.ReadSingle();
Awake = reader.ReadBoolean();
Kinematic = reader.ReadBoolean();
// Needs to be done manually because count is separated
PhysicsVertices.Capacity = physicsShapeVertexCount;
for (int i = 0; i < physicsShapeVertexCount; i++)
{
UndertalePhysicsVertex v = new UndertalePhysicsVertex();
v.Unserialize(reader);
PhysicsVertices.Add(v);
}
Events = reader.ReadUndertaleObject<UndertalePointerList<UndertalePointerList<Event>>>();
}
/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static uint UnserializeChildObjectCount(UndertaleReader reader)
{
uint count = 0;
if (reader.undertaleData.IsVersionAtLeast(2022, 5))
reader.Position += 64 + 4; // + "Managed"
else
reader.Position += 64;
int physicsShapeVertexCount = reader.ReadInt32();
reader.Position += 12 + (uint)physicsShapeVertexCount * UndertalePhysicsVertex.ChildObjectsSize;
count += 3 + 1 + UndertalePointerList<UndertalePointerList<Event>>.UnserializeChildObjectCount(reader);
return count;
}
#region EventHandlerFor() overloads
// TODO: Add documentation for these methods.
// These methods are used by scripts for getting a code entry for a certain event of the game object.
public UndertaleCode EventHandlerFor(EventType type, uint subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist)
{
Event subtypeObj = Events[(int)type].FirstOrDefault(x => x.EventSubtype == subtype);
if (subtypeObj == null)
Events[(int)type].Add(subtypeObj = new Event() { EventSubtype = subtype });
EventAction action = subtypeObj.Actions.FirstOrDefault();
if (action == null)
{
subtypeObj.Actions.Add(action = new EventAction());
action.ActionName = strg.MakeString("");
}
UndertaleCode code = action.CodeId;
if (code == null)
{
var name = strg.MakeString("gml_Object_" + Name.Content + "_" + type + "_" + subtype);
code = new UndertaleCode()
{
Name = name,
LocalsCount = 1
};
action.CodeId = code;
codelist.Add(code);
UndertaleCodeLocals.LocalVar argsLocal = new UndertaleCodeLocals.LocalVar();
argsLocal.Name = strg.MakeString("arguments");
argsLocal.Index = 0;
var locals = new UndertaleCodeLocals()
{
Name = name
};
locals.Locals.Add(argsLocal);
localslist.Add(locals);
}
return code;
}
public UndertaleCode EventHandlerFor(EventType type, UndertaleData data)
{
return EventHandlerFor(type, data.Strings, data.Code, data.CodeLocals);
}
public UndertaleCode EventHandlerFor(EventType type, uint subtype, UndertaleData data)
{
return EventHandlerFor(type, subtype, data.Strings, data.Code, data.CodeLocals);
}
public UndertaleCode EventHandlerFor(EventType type, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist)
{
return EventHandlerFor(type, 0u, strg, codelist, localslist);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeKey subtype, UndertaleData data)
{
return EventHandlerFor(type, subtype, data.Strings, data.Code, data.CodeLocals);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeKey subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist)
{
if (type != EventType.Keyboard && type != EventType.KeyPress && type != EventType.KeyRelease)
throw new InvalidOperationException();
return EventHandlerFor(type, (uint)subtype, strg, codelist, localslist);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeStep subtype, UndertaleData data)
{
return EventHandlerFor(type, subtype, data.Strings, data.Code, data.CodeLocals);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeStep subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist)
{
if (type != EventType.Step)
throw new InvalidOperationException();
return EventHandlerFor(type, (uint)subtype, strg, codelist, localslist);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeMouse subtype, UndertaleData data)
{
return EventHandlerFor(type, subtype, data.Strings, data.Code, data.CodeLocals);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeMouse subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist)
{
if (type != EventType.Mouse)
throw new InvalidOperationException();
return EventHandlerFor(type, (uint)subtype, strg, codelist, localslist);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeOther subtype, UndertaleData data)
{
return EventHandlerFor(type, subtype, data.Strings, data.Code, data.CodeLocals);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeOther subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist)
{
if (type != EventType.Other)
throw new InvalidOperationException();
return EventHandlerFor(type, (uint)subtype, strg, codelist, localslist);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeDraw subtype, UndertaleData data)
{
return EventHandlerFor(type, subtype, data.Strings, data.Code, data.CodeLocals);
}
public UndertaleCode EventHandlerFor(EventType type, EventSubtypeDraw subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist)
{
if (type != EventType.Draw)
throw new InvalidOperationException();
return EventHandlerFor(type, (uint)subtype, strg, codelist, localslist);
}
#endregion
/// <inheritdoc />
public override string ToString()
{
return Name?.Content + " (" + GetType().Name + ")";
}
/// <inheritdoc/>
public void Dispose()
{
GC.SuppressFinalize(this);
_sprite.Dispose();
_parentId.Dispose();
_textureMaskId.Dispose();
PhysicsVertices = new();
foreach (var ev in Events)
{
foreach (var subEv in ev)
subEv?.Dispose();
}
Name = null;
Events = new();
}
/// <summary>
/// Generic events that an <see cref="UndertaleGameObject"/> uses.
/// </summary>
[PropertyChanged.AddINotifyPropertyChangedInterface]
public class Event : UndertaleObject, IDisposable
{
/// <summary>
/// The subtype of this event.
/// </summary>
/// <remarks>Game Maker suffixes the action names with this id.</remarks>
public uint EventSubtype { get; set; }
/// <summary>
/// The available actions that will be performed for this event.
/// </summary>
/// <remarks>This seems to always have 1 entry, it would need testing if maybe the games using drag-and-drop code are different</remarks>
public UndertalePointerList<EventAction> Actions { get; set; } = new UndertalePointerList<EventAction>();
//TODO: not used, condense. Also UMT specific.
public EventSubtypeKey EventSubtypeKey
{
get => (EventSubtypeKey)EventSubtype;
set => EventSubtype = (uint)value;
}
public EventSubtypeStep EventSubtypeStep
{
get => (EventSubtypeStep)EventSubtype;
set => EventSubtype = (uint)value;
}
public EventSubtypeMouse EventSubtypeMouse
{
get => (EventSubtypeMouse)EventSubtype;
set => EventSubtype = (uint)value;
}
public EventSubtypeOther EventSubtypeOther
{
get => (EventSubtypeOther)EventSubtype;
set => EventSubtype = (uint)value;
}
public EventSubtypeDraw EventSubtypeDraw
{
get => (EventSubtypeDraw)EventSubtype;
set => EventSubtype = (uint)value;
}
public EventSubtypeGesture EventSubtypeGesture
{
get => (EventSubtypeGesture)EventSubtype;
set => EventSubtype = (uint)value;
}
/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
{
writer.Write(EventSubtype);
writer.WriteUndertaleObject(Actions);
}
/// <inheritdoc />
public void Unserialize(UndertaleReader reader)
{
EventSubtype = reader.ReadUInt32();
Actions = reader.ReadUndertaleObject<UndertalePointerList<EventAction>>();
}
/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static uint UnserializeChildObjectCount(UndertaleReader reader)
{
reader.Position += 4; // "EventSubtype"
return 1 + UndertalePointerList<EventAction>.UnserializeChildObjectCount(reader);
}
/// <inheritdoc/>
public void Dispose()
{
GC.SuppressFinalize(this);
foreach (EventAction action in Actions)
action?.Dispose();
Actions = new();
}
}
/// <summary>
/// An action in an event.
/// </summary>
public class EventAction : UndertaleObject, INotifyPropertyChanged, IDisposable,
IStaticChildObjectsSize, IStaticChildObjCount
{
/// <inheritdoc cref="IStaticChildObjCount.ChildObjectCount" />
public static readonly uint ChildObjectCount = 1;
/// <inheritdoc cref="IStaticChildObjectsSize.ChildObjectsSize" />
public static readonly uint ChildObjectsSize = 56;
// All the unknown values seem to be provided for compatibility only - in older versions of GM:S they stored the drag and drop blocks,
// but newer versions compile them down to GML bytecode anyway
// Possible meaning of values: https://github.com/WarlockD/GMdsam/blob/26aefe3e90a7a7a1891cb83f468079546f32b4b7/GMdsam/GameMaker/ChunkTypes.cs#L466
// Note from the future: these aren't always these values...
public uint LibID { get; set; } // always 1
public uint ID { get; set; } // always 603
public uint Kind { get; set; } // always 7
public bool UseRelative { get; set; } // always 0
public bool IsQuestion { get; set; } // always 0
public bool UseApplyTo { get; set; } // always 1
public uint ExeType { get; set; } // always 2
public UndertaleString ActionName { get; set; } // always ""
private UndertaleResourceById<UndertaleCode, UndertaleChunkCODE> _codeId = new UndertaleResourceById<UndertaleCode, UndertaleChunkCODE>();
/// <summary>
/// The code entry that gets executed.
/// </summary>
public UndertaleCode CodeId { get => _codeId.Resource; set { _codeId.Resource = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CodeId))); } }
public uint ArgumentCount { get; set; } // always 1
public int Who { get; set; } // always -1
public bool Relative { get; set; } // always 0
public bool IsNot { get; set; } // always 0
public uint UnknownAlwaysZero { get; set; } // always 0
/// <inheritdoc />
public event PropertyChangedEventHandler PropertyChanged;
/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
{
writer.Write(LibID);
writer.Write(ID);
writer.Write(Kind);
writer.Write(UseRelative);
writer.Write(IsQuestion);
writer.Write(UseApplyTo);
writer.Write(ExeType);
writer.WriteUndertaleString(ActionName);
writer.WriteUndertaleObject(_codeId);
writer.Write(ArgumentCount);
writer.Write(Who);
writer.Write(Relative);
writer.Write(IsNot);
writer.Write(UnknownAlwaysZero);
}
/// <inheritdoc />
public void Unserialize(UndertaleReader reader)
{
LibID = reader.ReadUInt32();
ID = reader.ReadUInt32();
Kind = reader.ReadUInt32();
UseRelative = reader.ReadBoolean();
IsQuestion = reader.ReadBoolean();
UseApplyTo = reader.ReadBoolean();
ExeType = reader.ReadUInt32();
ActionName = reader.ReadUndertaleString();
_codeId = reader.ReadUndertaleObject<UndertaleResourceById<UndertaleCode, UndertaleChunkCODE>>();
ArgumentCount = reader.ReadUInt32();
Who = reader.ReadInt32();
Relative = reader.ReadBoolean();
IsNot = reader.ReadBoolean();
UnknownAlwaysZero = reader.ReadUInt32();
}
/// <inheritdoc/>
public void Dispose()
{
GC.SuppressFinalize(this);
_codeId.Dispose();
ActionName = null;
}
}
/// <summary>
/// Class representing a physics vertex used for a <see cref="CollisionShape"/> of type <see cref="CollisionShapeFlags.Custom"/>.
/// </summary>
[PropertyChanged.AddINotifyPropertyChangedInterface]
public class UndertalePhysicsVertex : UndertaleObject, IStaticChildObjectsSize
{
/// <inheritdoc cref="IStaticChildObjectsSize.ChildObjectsSize" />
public static readonly uint ChildObjectsSize = 8;
/// <summary>
/// The x position of the vertex.
/// </summary>
public float X { get; set; }
/// <summary>
/// The y position of the vertex.
/// </summary>
public float Y { get; set; }
/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
{
writer.Write(X);
writer.Write(Y);
}
/// <inheritdoc />
public void Unserialize(UndertaleReader reader)
{
X = reader.ReadSingle();
Y = reader.ReadSingle();
}
}
}
/// <summary>
/// The types an <see cref="UndertaleGameObject.Event"/> from an <see cref="UndertaleGameObject"/> can be.
/// </summary>
/// <remarks>Note, that subtypes exist as well.</remarks>
public enum EventType : uint
{
/// <summary>
/// A creation event type. Has no subtypes, it's always 0
/// </summary>
Create = 0,
/// <summary>
/// A destroy event type. Has no subtypes, it's always 0.
/// </summary>
Destroy = 1,
/// <summary>
/// An alarm event type. The subtype is 0-11, depending on the alarm id.
/// </summary>
Alarm = 2,
/// <summary>
/// A step event type. The subtype is <see cref="EventSubtypeStep"/>.
/// </summary>
Step = 3, // subtype is EventSubtypeStep
/// <summary>
/// A collision event type. The subtype is the other <see cref="UndertaleGameObject"/>'s id.
/// </summary>
Collision = 4,
/// <summary>
/// A key down event type. The subtype is the key id, see <see cref="EventSubtypeKey"/>.
/// </summary>
Keyboard = 5,
/// <summary>
/// A mouse event type. The subtype is <see cref="EventSubtypeMouse"/>.
/// </summary>
Mouse = 6, // subtype is EventSubtypeMouse
/// <summary>
/// A miscellaneous event type. The subtype is <see cref="EventSubtypeOther"/>.
/// </summary>
Other = 7,
/// <summary>
/// A draw event type. The subtype is <see cref="EventSubtypeDraw"/>.
/// </summary>
Draw = 8,
/// <summary>
/// A key pressed event type. The subtype is the key id, see <see cref="EventSubtypeKey"/>.
/// </summary>
KeyPress = 9,
/// <summary>
/// A key released event type. The subtype is the key id, see <see cref="EventSubtypeKey"/>.
/// </summary>
KeyRelease = 10,
/// <summary>
/// A trigger event type. Only used in Pre- Game Maker: Studio.
/// </summary>
Trigger = 11, // no subtypes, always 0
/// <summary>
/// A cleanup event type. Has no subtypes, always 0.
/// </summary>
CleanUp = 12,
/// <summary>
/// A gesture event type. The subtype is <see cref="EventSubtypeGesture"/>.
/// </summary>
Gesture = 13,
/// <summary>
/// A pre-create event type. Unknown subtype. TODO?
/// </summary>
PreCreate = 14
}
/// <summary>
/// The subtypes for <see cref="EventType.Step"/>.
/// </summary>
public enum EventSubtypeStep : uint
{
/// <summary>
/// Normal step event.
/// </summary>
Step = 0,
/// <summary>
/// The begin step event.
/// </summary>
BeginStep = 1,
/// <summary>
/// The end step event.
/// </summary>
EndStep = 2,
}
/// <summary>
/// The subtypes for <see cref="EventType.Draw"/>.
/// </summary>
public enum EventSubtypeDraw : uint
{
/// <summary>
/// The draw event.
/// </summary>
Draw = 0,
/// <summary>
/// The draw GUI event.
/// </summary>
DrawGUI = 64,
/// <summary>
/// The resize event.
/// </summary>
Resize = 65,
/// <summary>
/// The draw begin event.
/// </summary>
DrawBegin = 72,
/// <summary>
/// The draw end event.
/// </summary>
DrawEnd = 73,
/// <summary>
/// The draw GUI begin event.
/// </summary>
DrawGUIBegin = 74,
/// <summary>
/// The draw GUI end event.
/// </summary>
DrawGUIEnd = 75,
/// <summary>
/// The pre-draw event.
/// </summary>
PreDraw = 76,
/// <summary>
/// The post-draw event.
/// </summary>
PostDraw = 77,
}
/// <summary>
/// The subtypes for <see cref="EventType.Keyboard"/>, <see cref="EventType.KeyPress"/> and <see cref="EventType.KeyRelease"/>.
/// </summary>
public enum EventSubtypeKey : uint
{
// if doesn't match any of the below, then it's probably just chr(value)
/// <summary>
/// Keycode representing no key.
/// </summary>
vk_nokey = 0,
/// <summary>
/// Keycode representing that any key.
/// </summary>
vk_anykey = 1,
/// <summary>
/// Keycode representing Backspace.
/// </summary>
vk_backspace = 8,
/// <summary>
/// Keycode representing Tab.
/// </summary>
vk_tab = 9,
/// <summary>
/// Keycode representing Return.
/// </summary>
vk_return = 13,
/// <summary>
/// Keycode representing Enter.
/// </summary>
vk_enter = 13,
/// <summary>
/// Keycode representing any Shift key.
/// </summary>
vk_shift = 16,
/// <summary>
/// Keycode representing any Control key.
/// </summary>
vk_control = 17,
/// <summary>
/// Keycode representing any Alt key.
/// </summary>
vk_alt = 18,
/// <summary>
/// Keycode representing the Pause key.
/// </summary>
vk_pause = 19,
/// <summary>
/// Keycode representing the Escape key.
/// </summary>
vk_escape = 27,
/// <summary>
/// Keycode representing the Space key.
/// </summary>
vk_space = 32,
/// <summary>
/// Keycode representing PageUp.
/// </summary>
vk_pageup = 33,
/// <summary>
/// Keycode representing PageDown.
/// </summary>
vk_pagedown = 34,
/// <summary>
/// Keycode representing the End key.
/// </summary>
vk_end = 35,
/// <summary>
/// Keycode representing the Home key.
/// </summary>
vk_home = 36,
/// <summary>
/// Keycode representing the left arrow key.
/// </summary>
vk_left = 37,
/// <summary>
/// Keycode representing the up arrow key.
/// </summary>
vk_up = 38,
/// <summary>
/// Keycode representing the right arrow key.
/// </summary>
vk_right = 39,
/// <summary>
/// Keycode representing the down arrow key.
/// </summary>
vk_down = 40,
/// <summary>
/// Keycode representing the PrintScreen key.
/// </summary>
vk_printscreen = 44,
/// <summary>
/// Keycode representing the Insert key.
/// </summary>
vk_insert = 45,
/// <summary>
/// Keycode representing the Delete key.
/// </summary>
vk_delete = 46,
/// <summary>
/// Keycode representing the 0 key.
/// </summary>
Digit0 = 48,
/// <summary>
/// Keycode representing the 1 key.
/// </summary>
Digit1 = 49,
/// <summary>
/// Keycode representing the 2 key.
/// </summary>
Digit2 = 50,
/// <summary>
/// Keycode representing the 3 key.
/// </summary>
Digit3 = 51,
/// <summary>
/// Keycode representing the 4 key.
/// </summary>
Digit4 = 52,
/// <summary>
/// Keycode representing the 5 key.
/// </summary>
Digit5 = 53,
/// <summary>
/// Keycode representing the 6 key.
/// </summary>
Digit6 = 54,
/// <summary>
/// Keycode representing the 7 key.
/// </summary>
Digit7 = 55,
/// <summary>
/// Keycode representing the 8 key.
/// </summary>
Digit8 = 56,
/// <summary>
/// Keycode representing the 9 key.
/// </summary>
Digit9 = 57,
/// <summary>
/// Keycode representing the A key.
/// </summary>
A = 65,
/// <summary>
/// Keycode representing the B key.
/// </summary>
B = 66,
/// <summary>
/// Keycode representing the C key.
/// </summary>
C = 67,
/// <summary>
/// Keycode representing the D key.
/// </summary>
D = 68,
/// <summary>
/// Keycode representing the E key.
/// </summary>
E = 69,
/// <summary>
/// Keycode representing the F key.
/// </summary>
F = 70,
/// <summary>
/// Keycode representing the G key.
/// </summary>
G = 71,
/// <summary>
/// Keycode representing the H key.
/// </summary>
H = 72,
/// <summary>
/// Keycode representing the I key.
/// </summary>
I = 73,
/// <summary>
/// Keycode representing the J key.
/// </summary>
J = 74,
/// <summary>
/// Keycode representing the K key.
/// </summary>
K = 75,
/// <summary>
/// Keycode representing the L key.
/// </summary>
L = 76,
/// <summary>
/// Keycode representing the M key.
/// </summary>
M = 77,
/// <summary>
/// Keycode representing the N key.
/// </summary>
N = 78,
/// <summary>
/// Keycode representing the O key.
/// </summary>
O = 79,
/// <summary>
/// Keycode representing the P key.
/// </summary>
P = 80,
/// <summary>
/// Keycode representing the Q key.
/// </summary>
Q = 81,
/// <summary>
/// Keycode representing the R key.
/// </summary>
R = 82,
/// <summary>
/// Keycode representing the S key.
/// </summary>
S = 83,
/// <summary>
/// Keycode representing the T key.
/// </summary>
T = 84,
/// <summary>
/// Keycode representing the U key.
/// </summary>
U = 85,
/// <summary>
/// Keycode representing the V key.
/// </summary>
V = 86,
/// <summary>
/// Keycode representing the W key.
/// </summary>
W = 87,
/// <summary>
/// Keycode representing the X key.
/// </summary>
X = 88,
/// <summary>
/// Keycode representing the Y key.
/// </summary>
Y = 89,
/// <summary>
/// Keycode representing the Z key.
/// </summary>
Z = 90,
/// <summary>
/// Keycode representing the 0 key on the numeric keypad.
/// </summary>
vk_numpad0 = 96,
/// <summary>
/// Keycode representing the 1 key on the numeric keypad.
/// </summary>
vk_numpad1 = 97,
/// <summary>
/// Keycode representing the 2 key on the numeric keypad.
/// </summary>
vk_numpad2 = 98,
/// <summary>
/// Keycode representing the 3 key on the numeric keypad.
/// </summary>
vk_numpad3 = 99,
/// <summary>