Skip to content

Commit

Permalink
Fix: GffStruct.dup not duplicating inner objects
Browse files Browse the repository at this point in the history
  • Loading branch information
CromFr committed Jan 8, 2021
1 parent d97aa88 commit 847807d
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion source/nwn/gff.d
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ struct GffLocString{
this.strings = strings;
}

/// Duplicate GffLocString content
GffLocString dup() const {
string[int32_t] newStrings;
foreach(k, v ; strings)
newStrings[k] = v;
return GffLocString(strref, newStrings);
}

/// Get the string value without attempting to resolve strref using TLKs
string toString() const {
if(strings.length > 0){
Expand Down Expand Up @@ -377,7 +385,26 @@ struct GffStruct {

/// Duplicate GffStruct content
GffStruct dup() const {
return GffStruct(this.children.dup(), this.id);
auto dup_children = children.dup();
foreach(ref GffValue c ; dup_children){
switch(c.type) {
case GffType.Struct:
c = GffValue(c.get!GffStruct.dup());
break;
case GffType.List:
c = GffValue(c.get!GffList.dup());
break;
case GffType.LocString:
c = GffValue(c.get!GffLocString.dup());
break;
case GffType.Void:
c = GffValue(c.get!GffVoid.dup());
break;
default:
break;
}
}
return GffStruct(dup_children, this.id);
}


Expand Down

0 comments on commit 847807d

Please sign in to comment.