Skip to content

Commit 06013a5

Browse files
handle UserDefinedPin
add some null checks for subCategoryObject
1 parent b0974e0 commit 06013a5

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/controls/utils/color-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export enum StructClass {
1313
export class ColorUtils {
1414

1515
public static getPinColor(pin: PinProperty): string {
16-
return this.getPinColorByCategory(pin.category, pin.subCategoryObject.class);
16+
return this.getPinColorByCategory(pin.category, pin.subCategoryObject?.class);
1717
}
1818

1919
public static getPinColorByCategory(category: PinCategory, subCategoryObject?: string): string {

src/parser/node-parsers/generic-node.parser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class GenericNodeParser extends NodeParser {
8484
[key: string]: () => CustomPropertyParser
8585
} = {
8686
"Pin": () => new PinPropertyParser(),
87+
"UserDefinedPin": () => new PinPropertyParser(),
8788
}
8889

8990
constructor() {
@@ -162,7 +163,8 @@ export class GenericNodeParser extends NodeParser {
162163
data.node.customProperties.push(property);
163164

164165
if (property instanceof PinProperty) {
165-
if ((property as PinProperty).subCategoryObject.class === StructClass.LatentActionInfo) {
166+
const pinProp = property as PinProperty;
167+
if (pinProp.subCategoryObject && pinProp.subCategoryObject.class === StructClass.LatentActionInfo) {
166168
data.node.latent = true;
167169
}
168170
}

src/parser/pin-property.parser.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export class PinPropertyParser implements CustomPropertyParser {
2525
"PinName": (p: PinProperty, value: string) => { p.name = prettifyText(BlueprintParserUtils.parseString(value)); },
2626
"PinFriendlyName": (p: PinProperty, value: string) => { p.friendlyName = prettifyText(PinPropertyParser.parsePinFriendlyName(value)); },
2727
"PinType.PinCategory": (p: PinProperty, value: string) => { p.category = PinPropertyParser.parsePinCategory(value); },
28+
"PinType": (p: PinProperty, value: string) => {
29+
// UserDefinedPin format: PinType=(PinCategory="bool")
30+
const categoryMatch = value.match(/PinCategory="([^"]+)"/);
31+
if (categoryMatch) {
32+
p.category = PinPropertyParser.parsePinCategory(`"${categoryMatch[1]}"`);
33+
}
34+
},
2835
"Direction": (p: PinProperty, value: string) => { p.direction = PinPropertyParser.parseDirection(value); },
2936
"DesiredPinDirection": (p: PinProperty, value: string) => { p.direction = PinPropertyParser.parseDirection(value); },
3037
"PinToolTip": (p: PinProperty, value: string) => { p.toolTip = BlueprintParserUtils.parseString(value); },
@@ -271,9 +278,11 @@ export class PinPropertyParser implements CustomPropertyParser {
271278
case PinCategory.bool:
272279
return { control: CheckBoxControl, data: (BlueprintParserUtils.parseString(value).toLowerCase() === "true") };
273280
case PinCategory.struct:
274-
return this.parseDefaultValueStruct(p.subCategoryObject.class, value);
281+
if (p.subCategoryObject && p.subCategoryObject.class) {
282+
return this.parseDefaultValueStruct(p.subCategoryObject.class, value);
283+
}
275284
case PinCategory.byte:
276-
if (p.subCategoryObject.type === "Enum") {
285+
if (p.subCategoryObject && p.subCategoryObject.type === "Enum") {
277286
return { control: TextBoxControl, data: BlueprintParserUtils.parseEnumValue(p.subCategoryObject.class, value) };
278287
} else {
279288
return { control: TextBoxControl, data: BlueprintParserUtils.parseString(value) };
@@ -366,13 +375,15 @@ export class PinPropertyParser implements CustomPropertyParser {
366375
p.defaultValue = " ";
367376
p.defaultValueControlClass = TextBoxControl;
368377
case PinCategory.struct:
369-
switch (p.subCategoryObject.class) {
370-
case StructClass.VECTOR2D:
371-
p.defaultValue = [
372-
{ key: 'X', value: '0.0' },
373-
{ key: 'Y', value: '0.0' }];
374-
p.defaultValueControlClass = StructBoxControl;
375-
break;
378+
if (p.subCategoryObject && p.subCategoryObject.class) {
379+
switch (p.subCategoryObject.class) {
380+
case StructClass.VECTOR2D:
381+
p.defaultValue = [
382+
{ key: 'X', value: '0.0' },
383+
{ key: 'Y', value: '0.0' }];
384+
p.defaultValueControlClass = StructBoxControl;
385+
break;
386+
}
376387
}
377388
break;
378389
}

0 commit comments

Comments
 (0)