Skip to content

Commit 67e5871

Browse files
committed
Make (Partial)PrefabList.IdOffset property
1 parent b91646f commit 67e5871

File tree

2 files changed

+62
-22
lines changed

2 files changed

+62
-22
lines changed

FancadeLoaderLib/Partial/PartialPrefabList.cs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ namespace FancadeLoaderLib.Partial;
2424
/// </remarks>
2525
public partial class PartialPrefabList : ICloneable
2626
{
27-
/// <summary>
28-
/// The id offset of this list, <see cref="RawGame.CurrentNumbStockPrefabs"/> by default.
29-
/// </summary>
30-
public ushort IdOffset = RawGame.CurrentNumbStockPrefabs;
31-
3227
internal readonly Dictionary<ushort, PartialPrefab> _prefabs;
3328
internal readonly List<PartialPrefabSegment> _segments;
3429

30+
private ushort _idOffset = RawGame.CurrentNumbStockPrefabs;
31+
3532
public PartialPrefabList()
3633
{
3734
_prefabs = [];
@@ -56,7 +53,7 @@ public PartialPrefabList(IEnumerable<PartialPrefab> prefabs)
5653

5754
_segments = [.. SegmentsFromPrefabs(_prefabs)];
5855

59-
IdOffset = _prefabs.Min(item => item.Key);
56+
_idOffset = _prefabs.Min(item => item.Key);
6057
}
6158

6259
public PartialPrefabList(PartialPrefabList other, bool deepCopy)
@@ -75,10 +72,36 @@ public PartialPrefabList(PartialPrefabList other, bool deepCopy)
7572
}
7673
}
7774

78-
private PartialPrefabList(Dictionary<ushort, PartialPrefab> dict)
75+
private PartialPrefabList(Dictionary<ushort, PartialPrefab> dict, ushort idOffset)
7976
{
8077
_prefabs = dict;
8178
_segments = [.. SegmentsFromPrefabs(_prefabs)];
79+
_idOffset = idOffset;
80+
}
81+
82+
/// <summary>
83+
/// Gets or sets the id offset of this list, <see cref="RawGame.CurrentNumbStockPrefabs"/> by default.
84+
/// Specifies the lowest prefab id.
85+
/// </summary>
86+
/// <value>Id offset of this list.</value>
87+
public ushort IdOffset
88+
{
89+
get => _idOffset;
90+
set
91+
{
92+
if (value < _idOffset)
93+
{
94+
_idOffset = 0;
95+
DecreaseAfter(0, (ushort)(_idOffset - value));
96+
_idOffset = value;
97+
}
98+
else if (value > _idOffset)
99+
{
100+
_idOffset = 0;
101+
IncreaseAfter(0, (ushort)(value - _idOffset));
102+
_idOffset = value;
103+
}
104+
}
82105
}
83106

84107
public int PrefabCount => _prefabs.Count;
@@ -131,10 +154,7 @@ public static PartialPrefabList Load(FcBinaryReader reader)
131154
}
132155
}
133156

134-
return new PartialPrefabList(prefabs)
135-
{
136-
IdOffset = idOffset,
137-
};
157+
return new PartialPrefabList(prefabs, idOffset);
138158
}
139159

140160
public void Save(FcBinaryWriter writer)

FancadeLoaderLib/PrefabList.cs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ namespace FancadeLoaderLib;
2222
/// </remarks>
2323
public class PrefabList : ICloneable
2424
{
25-
/// <summary>
26-
/// The id offset of this list, <see cref="RawGame.CurrentNumbStockPrefabs"/> by default.
27-
/// </summary>
28-
public ushort IdOffset = RawGame.CurrentNumbStockPrefabs;
29-
3025
internal readonly Dictionary<ushort, Prefab> _prefabs;
3126
internal readonly List<PrefabSegment> _segments;
3227

28+
private ushort _idOffset = RawGame.CurrentNumbStockPrefabs;
29+
3330
public PrefabList()
3431
{
3532
_prefabs = [];
@@ -54,7 +51,7 @@ public PrefabList(IEnumerable<Prefab> prefabs)
5451

5552
_segments = [.. SegmentsFromPrefabs(_prefabs)];
5653

57-
IdOffset = _prefabs.Min(item => item.Key);
54+
_idOffset = _prefabs.Min(item => item.Key);
5855
}
5956

6057
public PrefabList(PrefabList other, bool deepCopy)
@@ -73,10 +70,36 @@ public PrefabList(PrefabList other, bool deepCopy)
7370
}
7471
}
7572

76-
private PrefabList(Dictionary<ushort, Prefab> dict)
73+
private PrefabList(Dictionary<ushort, Prefab> dict, ushort idOffset)
7774
{
7875
_prefabs = dict;
7976
_segments = [.. SegmentsFromPrefabs(_prefabs)];
77+
_idOffset = idOffset;
78+
}
79+
80+
/// <summary>
81+
/// Gets or sets the id offset of this list, <see cref="RawGame.CurrentNumbStockPrefabs"/> by default.
82+
/// Specifies the lowest prefab id.
83+
/// </summary>
84+
/// <value>Id offset of this list.</value>
85+
public ushort IdOffset
86+
{
87+
get => _idOffset;
88+
set
89+
{
90+
if (value < _idOffset)
91+
{
92+
_idOffset = 0;
93+
DecreaseAfter(0, (ushort)(_idOffset - value));
94+
_idOffset = value;
95+
}
96+
else if (value > _idOffset)
97+
{
98+
_idOffset = 0;
99+
IncreaseAfter(0, (ushort)(value - _idOffset));
100+
_idOffset = value;
101+
}
102+
}
80103
}
81104

82105
public int PrefabCount => _prefabs.Count;
@@ -129,10 +152,7 @@ public static PrefabList Load(FcBinaryReader reader)
129152
}
130153
}
131154

132-
return new PrefabList(prefabs)
133-
{
134-
IdOffset = idOffset,
135-
};
155+
return new PrefabList(prefabs, idOffset);
136156
}
137157

138158
public void Save(FcBinaryWriter writer)

0 commit comments

Comments
 (0)