-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInterfaceData.h
More file actions
967 lines (803 loc) · 28.3 KB
/
Copy pathInterfaceData.h
File metadata and controls
967 lines (803 loc) · 28.3 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
#pragma once
#include <utility>
#include <vector>
#include <memory>
#include <string>
#include "CKDefines.h"
#include "CKBehavior.h"
#include "CKStateChunk.h"
#include "Geometry.h"
// Forward declarations
class InterfaceData;
/**
* @enum LinkType
* @brief Defines the types of links in behavior networks
*/
enum LinkType {
LINK_TYPE_BEHAVIOR = 1, ///< Behavior link (control flow)
LINK_TYPE_PARAMETER = 2, ///< Parameter link (data flow)
LINK_TYPE_PARAMETER_OP = 0x10002 ///< Parameter hierarchy link - used for parameter propagation through the behavior hierarchy and parameter operations
};
/**
* @enum EndpointType
* @brief Defines the types of endpoints for links
*/
enum EndpointType {
ENDPOINT_POUT_SHORTCUT = 5, ///< Parameter output link shortcut
ENDPOINT_PIN = 7, ///< Parameter input
ENDPOINT_POUT = 8, ///< Parameter output
ENDPOINT_PLOCAL = 9, ///< Local parameter
ENDPOINT_TARGET_PIN = 10, ///< Target parameter input
ENDPOINT_BIN = 12, ///< Behavior input
ENDPOINT_BOUT = 13, ///< Behavior output
ENDPOINT_START_BIN = 26 ///< "Start" behavior input
};
/**
* @enum ParameterStyle
* @brief Defines the display style for parameters
*/
enum ParameterStyle {
PARAM_STYLE_NAME = 0x200, ///< Display parameter name only
PARAM_STYLE_COLLAPSED = 0x400, ///< Parameter is closed/collapsed
PARAM_STYLE_NAMEVALUE = 0x1000, ///< Display parameter name and value
PARAM_STYLE_VALUE = 0x2000 ///< Display parameter value only
};
/**
* @enum CommentStyle
* @brief Defines the display style for comments
*/
enum CommentStyle {
COMMENT_STYLE_NORMAL = 0x0, ///< Normal comment display
COMMENT_STYLE_COLLAPSED = 0x1, ///< Comment is collapsed to icon
COMMENT_STYLE_LOCKED = 0x2, ///< Comment is locked
COMMENT_STYLE_TRANSPARENT = 0x4 ///< Comment is transparent
};
/**
* @enum ExtraDataType
* @brief Types of extra data that can be stored in interface chunks
*/
enum ExtraDataType {
EXTRA_DATA_BEHAVIOR = 1, ///< Behavior reference
EXTRA_DATA_PARAMETER = 2, ///< Parameter reference
EXTRA_DATA_CONNECTION = 3, ///< Connection between objects
EXTRA_DATA_VALUE = 4 ///< Numeric value
};
// Forward declarations for core classes
struct Header;
struct LinkEndpoint;
struct Link;
struct Operation;
struct Comment;
struct Parameter;
struct ExtraSubData;
struct ExtraData;
struct BehaviorData;
/**
* @struct InterfaceElement
* @brief Base class for all interface elements with common functionality
*/
struct InterfaceElement {
CK_ID id = 0; ///< ID of the element
InterfaceElement() = default;
explicit InterfaceElement(CK_ID elementId) : id(elementId) {}
virtual ~InterfaceElement() = default;
};
/**
* @struct Header
* @brief Represents the header of a behavior script
*/
struct Header : InterfaceElement {
float vStart = 0.0f; ///< Vertical offset where execution begins
float hStartPos = 140.0f; ///< Horizontal position of start
float vStartPos = 0.0f; ///< Vertical position of start
float hStartSize = 30.0f; ///< Horizontal size of the start region
float vStartSize = 20.0f; ///< Horizontal size of the start region
float vSize = 0.0f; ///< Vertical size of the start region
CKDWORD color = 0xC8C8C8; ///< Color of the header bar
void *snapshot = nullptr; ///< Optional bitmap snapshot
Point GetPosition() const;
void SetPosition(float h, float v);
};
/**
* @struct LinkEndpoint
* @brief Represents an endpoint of a link in the behavior tree
*/
struct LinkEndpoint : InterfaceElement {
int index = 0; ///< Index of the endpoint within its owner
EndpointType type = static_cast<EndpointType>(0); ///< Type of the endpoint
LinkEndpoint() = default;
LinkEndpoint(CK_ID endpointId, int endpointIndex, EndpointType endpointType)
: InterfaceElement(endpointId), index(endpointIndex), type(endpointType) {}
/**
* @brief Convenience constructor from raw type value
*/
LinkEndpoint(CK_ID endpointId, int endpointIndex, int endpointType)
: InterfaceElement(endpointId), index(endpointIndex), type(static_cast<EndpointType>(endpointType)) {}
/**
* @brief Checks if this endpoint is a parameter input
*/
bool IsParameterInput() const;
/**
* @brief Checks if this endpoint is a parameter output
*/
bool IsParameterOutput() const;
/**
* @brief Checks if this endpoint is a parameter output shortcut
*/
bool IsParameterShortCut() const;
/**
* @brief Checks if this endpoint is a local parameter
*/
bool IsParameterLocal() const;
/**
* @brief Checks if this endpoint is a behavior input
*/
bool IsBehaviorInput() const;
/**
* @brief Checks if this endpoint is a "start" behavior input
*/
bool IsStartBehaviorInput() const;
/**
* @brief Checks if this endpoint is a behavior output
*/
bool IsBehaviorOutput() const;
/**
* @brief Checks if this endpoint is related to parameters
*/
bool IsParameterRelated() const;
/**
* @brief Checks if this endpoint is related to behaviors
*/
bool IsBehaviorRelated() const;
/**
* @brief Checks if this endpoint is compatible with another endpoint for linking
* @param other The other endpoint to check against
* @return true if the endpoints can be connected, false otherwise
*/
bool IsCompatibleWith(const LinkEndpoint &other) const;
};
/**
* @struct Link
* @brief Represents a connection between two points in the behavior tree
*/
struct Link : InterfaceElement {
LinkType type = static_cast<LinkType>(0); ///< Type of the link
LinkEndpoint start; ///< Starting endpoint
std::vector<Point> points; ///< Control points for link routing
LinkEndpoint end; ///< Ending endpoint
/**
* @brief Default constructor
*/
Link() = default;
/**
* @brief Constructor with all fields
*/
Link(CK_ID linkId, LinkType linkType, LinkEndpoint startPoint, LinkEndpoint endPoint)
: InterfaceElement(linkId), type(linkType), start(std::move(startPoint)), end(std::move(endPoint)) {}
/**
* @brief Adds a control point to the link
*/
void AddControlPoint(const Point &point);
/**
* @brief Inserts a control point at the specified index
*/
void InsertControlPoint(int index, const Point &point);
/**
* @brief Removes a control point at the specified index
*/
void RemoveControlPoint(int index);
/**
* @brief Updates a control point at the specified index
*/
void UpdateControlPoint(int index, const Point &point);
/**
* @brief Checks if this is a behavior link
*/
bool IsBehaviorLink() const;
/**
* @brief Checks if this is a parameter link
*/
bool IsParameterLink() const;
/**
* @brief Checks if this is a parameter operation link
*/
bool IsParameterOpLink() const;
/**
* @brief Offsets all control points by the given amount
*/
void Offset(float h, float v);
/**
* @brief Scales all control points relative to a center point
*/
void Scale(float factor, const Point ¢er);
/**
* @brief Calculates the total length of the link path
*/
float GetPathLength() const;
/**
* @brief Gets a point along the path at the specified normalized distance (0-1)
*/
Point GetPointAlong(float t) const;
/**
* @brief Checks if the link passes near a point within the specified distance
*/
bool PassesNear(const Point &point, float maxDistance) const;
};
/**
* @struct Operation
* @brief Represents a parameter operation in the behavior tree
*/
struct Operation : InterfaceElement {
float hPos = 0.0f; ///< Horizontal position
float vPos = 0.0f; ///< Vertical position
Operation() = default;
explicit Operation(CK_ID opId) : InterfaceElement(opId) {}
Operation(CK_ID opId, float h, float v) : InterfaceElement(opId), hPos(h), vPos(v) {}
/**
* @brief Sets the position of the operation
*/
void SetPosition(float h, float v);
/**
* @brief Gets the position of the operation
*/
Point GetPosition() const;
};
/**
* @struct Comment
* @brief Represents a comment in the behavior tree
*/
struct Comment : InterfaceElement {
float hPos = 0.0f; ///< Horizontal position
float vPos = 0.0f; ///< Vertical position
float width = 100.0f; ///< Width of the comment
float height = 50.0f; ///< Height of the comment
std::string text; ///< Comment text content
CKDWORD styleFlags = 0; ///< Style flags
Comment() = default;
Comment(CK_ID commentId, float h, float v, float w, float h2, const std::string &commentText)
: InterfaceElement(commentId), hPos(h), vPos(v), width(w), height(h2), text(commentText) {}
/**
* @brief Gets the rectangle that encloses the comment
*/
Rect GetRect() const;
/**
* @brief Sets the rectangle that encloses the comment
*/
void SetRect(const Rect &rect);
/**
* @brief Checks if the comment is collapsed
*/
bool IsCollapsed() const;
/**
* @brief Checks if the comment is locked
*/
bool IsLocked() const;
/**
* @brief Checks if the comment is transparent
*/
bool IsTransparent() const;
/**
* @brief Sets the collapsed state
*/
void SetCollapsed(bool collapsed);
/**
* @brief Sets the locked state
*/
void SetLocked(bool locked);
/**
* @brief Sets the transparent state
*/
void SetTransparent(bool transparent);
/**
* @brief Resizes the comment to fit the text plus padding
* @param charWidth Average width of a character
* @param lineHeight Height of a line of text
* @param hPadding Horizontal padding
* @param vPadding Vertical padding
*/
void ResizeToFitText(float charWidth, float lineHeight, float hPadding = 10.0f, float vPadding = 10.0f);
};
/**
* @struct Parameter
* @brief Represents a parameter in the behavior tree
*/
struct Parameter : InterfaceElement {
int hPos = 0; ///< Horizontal grid index (col), not pixels
int vPos = 0; ///< Vertical grid index (row), not pixels
ParameterStyle style = PARAM_STYLE_NAME; ///< Display style
CK_ID sourceId = 0; ///< Source parameter ID for shortcuts
Parameter() = default;
Parameter(CK_ID paramId, ParameterStyle paramStyle) : InterfaceElement(paramId), style(paramStyle) {}
Parameter(CK_ID paramId, int h, int v, ParameterStyle paramStyle = PARAM_STYLE_NAME)
: InterfaceElement(paramId), hPos(h), vPos(v), style(paramStyle) {}
/**
* @brief Checks if this parameter is a shortcut
*/
bool IsShortcut() const;
/**
* @brief Sets the position of the parameter
*/
void SetPosition(int h, int v);
/**
* @brief Gets the position of the parameter
*/
Point GetPosition() const;
/**
* @brief Checks if the style includes a specific flag
*/
bool HasStyleFlag(ParameterStyle flag) const;
/**
* @brief Sets a specific style flag
*/
void SetStyleFlag(ParameterStyle flag, bool value);
/**
* @brief Checks if the parameter shows its name
*/
bool ShowsName() const;
/**
* @brief Checks if the parameter shows its value
*/
bool ShowsValue() const;
/**
* @brief Checks if the parameter is closed/collapsed
*/
bool IsClosed() const;
/**
* @brief Sets whether the parameter is closed/collapsed
*/
void SetClosed(bool closed);
};
/**
* @struct ExtraSubData
* @brief Represents a sub-element in the extra data section
*/
struct ExtraSubData : InterfaceElement {
int value1 = 0; ///< First value
int value2 = 0; ///< Second value
CK_ID id1 = 0; ///< First object ID
CK_ID id2 = 0; ///< Second object ID (optional)
std::vector<CKBYTE> buffer; ///< Buffer data (optional)
ExtraSubData() = default;
/**
* @brief Constructor for ID-based sub-data
*/
ExtraSubData(int val1, int val2, CK_ID objId1, CK_ID objId2 = 0)
: value1(val1), value2(val2), id1(objId1), id2(objId2) {}
/**
* @brief Constructor for buffer-based sub-data
*/
ExtraSubData(int val1, int val2, CK_ID objId1, const std::vector<CKBYTE> &data)
: value1(val1), value2(val2), id1(objId1), buffer(data) {}
};
/**
* @struct ExtraData
* @brief Represents extra data for the interface
*/
struct ExtraData : InterfaceElement {
ExtraDataType type = EXTRA_DATA_VALUE; ///< Type of extra data
CK_ID id1 = 0; ///< First object ID
CK_ID id2 = 0; ///< Second object ID (for connections)
int value = 0; ///< Value (for value type)
std::vector<ExtraSubData> subData; ///< Sub-data elements
ExtraData() = default;
/**
* @brief Constructor for behavior reference extra data
*/
explicit ExtraData(CK_ID behaviorId) : type(EXTRA_DATA_BEHAVIOR), id1(behaviorId) {}
/**
* @brief Constructor for parameter reference extra data
*/
explicit ExtraData(CK_ID parameterId, ExtraDataType extraType = EXTRA_DATA_PARAMETER)
: type(extraType), id1(parameterId) {}
/**
* @brief Constructor for connection extra data
*/
ExtraData(CK_ID sourceId, CK_ID targetId)
: type(EXTRA_DATA_CONNECTION), id1(sourceId), id2(targetId) {}
/**
* @brief Constructor for value extra data
*/
explicit ExtraData(int val) : type(EXTRA_DATA_VALUE), value(val) {}
/**
* @brief Adds a sub-data element
*/
void AddSubData(const ExtraSubData &data);
};
/**
* @class ElementObserver
* @brief Interface for observers of interface element changes
*/
class ElementObserver {
public:
virtual ~ElementObserver() = default;
/**
* @brief Called when an element is added
* @param element Pointer to the added element
*/
virtual void OnElementAdded(InterfaceElement *element) = 0;
/**
* @brief Called when an element is removed
* @param element Pointer to the removed element
*/
virtual void OnElementRemoved(InterfaceElement *element) = 0;
/**
* @brief Called when an element is modified
* @param element Pointer to the modified element
*/
virtual void OnElementModified(InterfaceElement *element) = 0;
};
/**
* @struct BehaviorData
* @brief Represents a behavior in the tree
*/
struct BehaviorData : InterfaceElement {
bool folded = false; ///< Whether the behavior is collapsed
bool isUsingTarget = false; ///< Whether the behavior has a target
bool isBehaviorGraph = false; ///< Whether this is a behavior graph
CKDWORD depth = 0; ///< Depth in the behavior hierarchy
Rect rect; ///< Size and position of the behavior
float hExpandSize = 0.0f; ///< Expanded horizontal size
float vExpandSize = 0.0f; ///< Expanded vertical size
// Links
std::vector<Link> links; ///< Links within this behavior
// Operations
std::vector<Operation> operations; ///< Operations within this behavior
// Comments
std::vector<Comment> comments; ///< Comments within this behavior
// Parameters
std::vector<Parameter> localParams; ///< Local parameters
std::vector<Parameter> sharedParams; ///< Shared parameters
// Input/Output indices for graph behaviors
std::vector<int> inwardInputs; ///< Inward-facing inputs
std::vector<int> outwardInputs; ///< Outward-facing inputs
std::vector<int> inwardOutputs; ///< Inward-facing outputs
std::vector<int> outwardOutputs; ///< Outward-facing outputs
BehaviorData() = default;
explicit BehaviorData(CK_ID behaviorId) : InterfaceElement(behaviorId) {}
/**
* @brief Adds a link to the behavior
*/
void AddLink(const Link &link);
/**
* @brief Adds an operation to the behavior
*/
void AddOperation(const Operation &op);
/**
* @brief Adds a local parameter to the behavior
*/
void AddLocalParameter(const Parameter ¶m);
/**
* @brief Adds a shared parameter to the behavior
*/
void AddSharedParameter(const Parameter ¶m);
/**
* @brief Adds a comment to the behavior
*/
void AddComment(const Comment &comment);
/**
* @brief Finds a link by ID
* @return Pointer to the link or nullptr if not found
*/
Link *FindLink(CK_ID linkId);
/**
* @brief Finds links connected to a specific object
* @param objId ID of the object to find connections for
* @return Vector of pointers to connected links
*/
std::vector<Link *> FindLinksConnectedTo(CK_ID objId);
/**
* @brief Finds an operation by ID
* @return Pointer to the operation or nullptr if not found
*/
Operation *FindOperation(CK_ID opId);
/**
* @brief Finds a local parameter by ID
* @return Pointer to the parameter or nullptr if not found
*/
Parameter *FindLocalParameter(CK_ID paramId);
/**
* @brief Finds a shared parameter by ID
* @return Pointer to the parameter or nullptr if not found
*/
Parameter *FindSharedParameter(CK_ID paramId);
/**
* @brief Finds a parameter (local or shared) by ID
* @return Pointer to the parameter or nullptr if not found
*/
Parameter *FindParameter(CK_ID paramId);
/**
* @brief Finds a comment by ID
* @return Pointer to the comment or nullptr if not found
*/
Comment *FindComment(CK_ID commentId);
/**
* @brief Finds elements at the given position
* @param position The position to check
* @param tolerance Distance tolerance for considering an element hit
* @return Vector of pointers to elements at the position
*/
std::vector<InterfaceElement *> FindElementsAt(const Point &position, float tolerance = 5.0f);
/**
* @brief Resets all data in the behavior
*/
void Reset();
/**
* @brief Gets all elements in the block
* @return Vector of pointers to all elements
*/
std::vector<InterfaceElement *> GetAllElements();
/**
* @brief Removes an element from the block
* @param element Pointer to the element to remove
* @return true if element was removed, false otherwise
*/
bool RemoveElement(InterfaceElement *element);
};
/**
* @class InterfaceData
* @brief Main container for behavior tree visual representation
*/
class InterfaceData {
public:
InterfaceData();
~InterfaceData();
//------------------------------------------------------
// Core data
//------------------------------------------------------
CKDWORD version = 0x16; ///< Interface chunk version
Header header; ///< Header of the script
BehaviorData rootBehavior; ///< Root behavior
std::vector<BehaviorData> behaviors; ///< Behavior in the tree
int behaviorCount = 0; ///< Number of behaviors
// Extra data section
int extraDataVersion = 0; ///< Version of extra data
std::vector<ExtraData> extraData; ///< Extra data entries
// Extension data
std::vector<ElementObserver *> observers; ///< Observers for change tracking
//------------------------------------------------------
// Basic Operations
//------------------------------------------------------
/**
* @brief Creates a new behavior in the interface
* @return Reference to the new behavior
*/
BehaviorData &NewBehavior();
/**
* @brief Adds a behavior to the interface
*/
void AddBehavior(BehaviorData &behavior);
/**
* @brief Removes a behavior from the interface
* @param behaviorId ID of the behavior to remove
* @return true if block was removed, false otherwise
*/
bool RemoveBehavior(CK_ID behaviorId);
/**
* @brief Finds a behavior by ID
* @return Pointer to the behavior if found, nullptr otherwise
*/
BehaviorData *FindBehavior(CK_ID id);
/**
* Finds an operation by ID
* @param id Operation ID
* @return Pointer to the operation if found, nullptr otherwise
*/
Operation *FindOperation(CK_ID id);
/**
* @brief Adds extra data to the interface
*/
void AddExtraData(const ExtraData &data);
/**
* @brief Clears all data in the interface
*/
void Clear();
//------------------------------------------------------
// Observer Pattern
//------------------------------------------------------
enum class ElementAction {
Added,
Removed,
Modified
};
/**
* @brief Adds an observer for element changes
*/
void AddObserver(ElementObserver *observer);
/**
* @brief Removes an observer
*/
void RemoveObserver(ElementObserver *observer);
/**
* @brief Notifies all observers of element changes
*/
void NotifyObservers(InterfaceElement *element, ElementAction action) const;
//------------------------------------------------------
// Advanced Querying
//------------------------------------------------------
/**
* @brief Finds all elements with the given ID
* @param id The ID to search for
* @return Vector of pointers to found elements
*/
std::vector<InterfaceElement *> FindElementsById(CK_ID id);
/**
* @brief Finds all elements at the given position
* @param position The position to check
* @param tolerance Distance tolerance for considering an element hit
* @return Vector of pointers to elements at the position
*/
std::vector<InterfaceElement *> FindElementsAt(const Point &position, float tolerance = 5.0f);
/**
* @brief Finds all links connected to the given object
* @param objId ID of the object to find connections for
* @return Vector of pointers to connected links
*/
std::vector<Link *> FindLinksConnectedTo(CK_ID objId);
/**
* @brief Gets a sub-tree below a behavior
* @param rootId ID of the root block for the sub-tree
* @return Vector of pointers to blocks in the sub-tree
*/
std::vector<BehaviorData *> GetSubTree(CK_ID rootId);
/**
* @brief Finds the parent block of a given block
* @param behaviorId ID of the block to find the parent for
* @return Pointer to the parent block or nullptr if not found
*/
BehaviorData *FindParentBehavior(CK_ID behaviorId);
/**
* @brief Finds all child blocks of a given block
* @param behaviorId ID of the block to find children for
* @return Vector of pointers to child blocks
*/
std::vector<BehaviorData *> FindChildBehaviors(CK_ID behaviorId);
/**
* @brief Checks if there's a path between two blocks
* @param startId ID of the starting block
* @param endId ID of the ending block
* @return true if there's a path, false otherwise
*/
bool HasPath(CK_ID startId, CK_ID endId);
/**
* @brief Finds a path between two blocks
* @param startId ID of the starting block
* @param endId ID of the ending block
* @return Vector of block IDs in the path, empty if no path exists
*/
std::vector<CK_ID> FindPath(CK_ID startId, CK_ID endId);
//------------------------------------------------------
// Serialization Methods
//------------------------------------------------------
/**
* @brief Loads interface data from a state chunk
* @param behavior The behavior containing the data
* @param chunk The state chunk to load from
* @return CK_OK if successful, error code otherwise
*/
CKERROR LoadFromChunk(CKBehavior *behavior, CKStateChunk *chunk);
/**
* @brief Saves interface data to a state chunk
* @param behavior The behavior to save data for
* @param chunk The state chunk to save to
* @return CK_OK if successful, error code otherwise
*/
CKERROR SaveToChunk(CKBehavior *behavior, CKStateChunk *chunk);
private:
/**
* @brief Holds context for serialization operations
*/
struct SerializationContext {
CKBehavior *behavior = nullptr;
CKStateChunk *chunk = nullptr;
bool isNotScript = false;
bool isBuildingBlock = false;
CKDWORD flags = 0;
CKDWORD version = 0x16;
CKDWORD scriptIndex = 0;
CKDWORD behaviorIndex = 0;
};
/**
* @brief Loads a behavior header from a chunk
* @param context Serialization context
* @param block The behavior to populate
* @return TRUE if successful, FALSE otherwise
*/
CKBOOL LoadBehaviorHeader(SerializationContext &context, BehaviorData &block);
/**
* @brief Loads links from a chunk
* @param context Serialization context
* @param block The behavior to populate
*/
void LoadBehaviorLinks(SerializationContext &context, BehaviorData &block);
/**
* @brief Loads operations from a chunk
* @param context Serialization context
* @param block The behavior to populate
*/
void LoadBehaviorOperations(SerializationContext &context, BehaviorData &block);
/**
* @brief Loads comments from a chunk
* @param context Serialization context
* @param block The behavior to populate
*/
void LoadBehaviorComments(SerializationContext &context, BehaviorData &block);
/**
* @brief Loads parameters from a chunk
* @param context Serialization context
* @param block The behavior to populate
*/
void LoadBehaviorParameters(SerializationContext &context, BehaviorData &block);
/**
* @brief Loads graph information from a chunk
* @param context Serialization context
* @param block The behavior to populate
*/
void LoadBehaviorGraph(SerializationContext &context, BehaviorData &block);
/**
* @brief Loads extra information from a chunk
* @param context Serialization context
*/
void LoadExtraData(SerializationContext &context);
/**
* @brief Saves a behavior header to a chunk
* @param context Serialization context
* @return TRUE if successful, FALSE otherwise
*/
CKBOOL SaveBehaviorHeader(SerializationContext &context);
/**
* @brief Saves links to a chunk
* @param context Serialization context
*/
void SaveBehaviorLinks(SerializationContext &context);
/**
* @brief Saves operations to a chunk
* @param context Serialization context
*/
void SaveBehaviorOperations(SerializationContext &context);
/**
* @brief Saves comments to a chunk
* @param context Serialization context
*/
void SaveBehaviorComments(SerializationContext &context);
/**
* @brief Saves parameters to a chunk
* @param context Serialization context
*/
void SaveBehaviorParameters(SerializationContext &context);
/**
* @brief Saves graph information to a chunk
* @param context Serialization context
*/
void SaveBehaviorGraph(SerializationContext &context);
/**
* @brief Saves extra information to a chunk
* @param context Serialization context
*/
void SaveExtraData(SerializationContext &context);
/**
* @brief Gets the appropriate behavior based on the context
* @param context Serialization context
* @return Reference to the behavior
*/
const BehaviorData &GetBehaviorForContext(const SerializationContext &context) const;
/**
* @brief Gets a modifiable reference to the appropriate behavior based on the context
* @param context Serialization context
* @return Reference to the behavior
*/
BehaviorData &GetBehaviorForContext(SerializationContext &context);
};
/**
* @brief Creates interface data from a behavior's interface chunk
* @param behavior Behavior with chunk to extract
* @param data Interface data to populate
* @return CK_OK if successful
*/
CKERROR ExtractInterfaceData(CKBehavior *behavior, InterfaceData &data);
/**
* @brief Generates an interface chunk from a behavior
* @param data Interface data to serialize
* @param behavior Behavior to generate chunk for
* @return Generated state chunk
*/
CKStateChunk *GenerateInterfaceChunk(InterfaceData &data, CKBehavior *behavior);