Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit 4bdbfb6

Browse files
committed
Fixed modded object group indentifier
* related to https://bugs.vcmi.eu/view.php?id=2850
1 parent eeeedce commit 4bdbfb6

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

editor_utils.pas

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ TStringCompare = class
5353
function NormalizeResourceName(const AName: string): string;
5454
function NormalizeKeyWord(const AValue: string): string;
5555

56+
function NormalizeIndentifier(const AValue: AnsiString): AnsiString;
57+
5658
function StripScope(const AIdentifier: string): string;
5759

5860
procedure GenerateDefaultVisitableFrom(ADest: TStrings; AGroup: UInt8; Atyp: Tobj);
@@ -62,7 +64,8 @@ TStringCompare = class
6264

6365
function DecodeFullIdentifier(const ASource: AnsiString; out AMetaclass: TMetaclass; out AScope: AnsiString; out AIdentifier: AnsiString): Boolean;
6466
function EncodeFullIdentifier(AMetaclass: AnsiString; AScope: AnsiString; AIdentifier: AnsiString): AnsiString;
65-
function EncodeFullIdentifier(AScope: AnsiString; AIdentifier: AnsiString): AnsiString;
67+
68+
function EncodeIdentifier(AScope: AnsiString; AIdentifier: AnsiString): AnsiString;
6669

6770
function CompareStringProxy(const s1,s2: string): integer;
6871

@@ -150,6 +153,25 @@ function NormalizeKeyWord(const AValue: string): string;
150153
result := UTF8LowerCase(UTF8Trim(AValue));
151154
end;
152155

156+
function NormalizeIndentifier(const AValue: AnsiString): AnsiString;
157+
var
158+
id_only: AnsiString;
159+
mod_id, mod_id2: String;
160+
begin
161+
id_only := AValue;
162+
163+
mod_id := ExtractModID2(id_only);
164+
165+
mod_id2 := mod_id;
166+
167+
while mod_id2 <> '' do
168+
begin
169+
mod_id2 := ExtractModID2(id_only);
170+
end;
171+
172+
Result := EncodeIdentifier(mod_id, id_only);
173+
end;
174+
153175
function StripScope(const AIdentifier: string): string;
154176
var
155177
colon_position: SizeInt;
@@ -310,7 +332,7 @@ function EncodeFullIdentifier(AMetaclass: AnsiString; AScope: AnsiString; AIdent
310332
end;
311333
end;
312334

313-
function EncodeFullIdentifier(AScope: AnsiString; AIdentifier: AnsiString): AnsiString;
335+
function EncodeIdentifier(AScope: AnsiString; AIdentifier: AnsiString): AnsiString;
314336
begin
315337
if AScope = '' then
316338
begin

map.pas

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ TMapObject = class (TNamedCollectionItem, IMapObject, ISerializeSpecial)
452452
FMapObjectGroup: TMapObjectGroup;
453453
FMapObjectType: TMapObjectType;
454454

455+
FGroupID: AnsiString;
456+
FTypeID: AnsiString;
457+
455458
FModUsage: TModUsage;
456459
FPosition: TPosition;
457460
FLastFrame: Integer;
@@ -2209,15 +2212,15 @@ function TMapObject.GetSubtype: AnsiString;
22092212
if Assigned(FMapObjectType) then
22102213
Result := FMapObjectType.Identifier
22112214
else
2212-
Result := '';
2215+
Result := FTypeID;
22132216
end;
22142217

22152218
function TMapObject.GetType: AnsiString;
22162219
begin
22172220
if Assigned(FMapObjectGroup) then
22182221
Result := FMapObjectGroup.Identifier
22192222
else
2220-
Result := '';
2223+
Result := FGroupID;
22212224
end;
22222225

22232226
function TMapObject.GetX: integer;
@@ -2362,10 +2365,12 @@ procedure TMapObject.SetSubtype(AValue: AnsiString);
23622365

23632366
if old_subtype=AValue then Exit;
23642367

2365-
NotifyReferenced(old_subtype,AValue);
2368+
FTypeID:=NormalizeIndentifier(AValue);
2369+
2370+
NotifyReferenced(old_subtype,FTypeID);
23662371

23672372
if Assigned(FMapObjectGroup) then
2368-
FMapObjectType := FMapObjectGroup.Types.FindItem(AValue)
2373+
FMapObjectType := FMapObjectGroup.Types.FindItem(FTypeID)
23692374
else
23702375
FMapObjectType := nil;
23712376

@@ -2380,9 +2385,11 @@ procedure TMapObject.SetType(AValue: AnsiString);
23802385

23812386
if old_type=AValue then Exit;
23822387

2383-
NotifyReferenced(old_type,AValue);
2388+
FGroupID := NormalizeIndentifier(AValue);
2389+
2390+
NotifyReferenced(old_type,FGroupID);
23842391

2385-
FMapObjectGroup := GetMap.ObjectsManager.MapObjectGroups.FindItem(AValue);
2392+
FMapObjectGroup := GetMap.ObjectsManager.MapObjectGroups.FindItem(FGroupID);
23862393
FMapObjectType := nil; //???
23872394

23882395
RecreateOptions;

map_objects.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ function TObjectsManager.FormatObjectName(AType, ASubtype: AnsiString): TLocaliz
917917

918918
end;
919919

920-
Result := Format('%s:%s',[group_name, tp_name]);
920+
Result := Format('%s::%s',[group_name, tp_name]);
921921
end;
922922

923923
function TObjectsManager.TypToId(Typ, SubType: uint32): TLegacyTemplateId;

object_options.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ procedure TPandorasOptions.BeforeSerialize(Sender: TObject);
21452145

21462146
if DecodeFullIdentifier(r.Identifier, metaclass, scope, ident) then
21472147
begin
2148-
full_ident := EncodeFullIdentifier(scope,ident);
2148+
full_ident := EncodeIdentifier(scope,ident);
21492149

21502150
case metaclass of
21512151
TMetaclass.artifact:

vcmi_json.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ TJSONObjectHelper = class helper for TJSONObject
208208
implementation
209209

210210
uses
211-
LazLoggerBase, editor_consts, rttiutils, types;
211+
LazLoggerBase, editor_consts, editor_utils, rttiutils, types;
212212

213213
var
214214
rexp_oid: TRegExpr;
@@ -777,7 +777,7 @@ procedure TVCMIJSONDestreamer.CollectionObjCallback(const AName: TJSONStringType
777777
end
778778
else if {new_item.UseMeta and} (item is TVCMIJsonArray) then
779779
begin
780-
meta := TVCMIJsonObject(Item).Meta;
780+
meta := TVCMIJsonArray(Item).Meta;
781781
new_item.Meta:=Meta;
782782
end
783783
else
@@ -787,11 +787,11 @@ procedure TVCMIJSONDestreamer.CollectionObjCallback(const AName: TJSONStringType
787787

788788
if new_item.UseMeta and (meta <> '') then
789789
begin
790-
new_item.Identifier := Meta + ':' + AName;
790+
new_item.Identifier := NormalizeIndentifier(EncodeIdentifier(Meta, AName));
791791
end
792792
else
793793
begin
794-
new_item.Identifier := AName;
794+
new_item.Identifier := NormalizeIndentifier(AName);
795795
end;
796796

797797
DestreamCollectionItem(ACollection, Item, new_item);

0 commit comments

Comments
 (0)