Skip to content

Commit ddd317f

Browse files
- Added "fallbackpackagename" to all resouirce data types
- constructor/loading and refactor work in LuaCsSetup.cs - Configuration system work.
1 parent ccd3692 commit ddd317f

File tree

27 files changed

+427
-124
lines changed

27 files changed

+427
-124
lines changed

Barotrauma/BarotraumaClient/ClientSource/LuaCs/Configuration/DisplayableData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ public record DisplayableData : IDisplayableData
66
{
77
public string InternalName { get; init; }
88
public ContentPackage OwnerPackage { get; init; }
9+
public string FallbackPackageName { get; init; }
910
public string DisplayName { get; init; }
1011
public string DisplayModName { get; init; }
1112
public string DisplayCategory { get; init; }
1213
public string Tooltip { get; init; }
1314
public string ImageIcon { get; init; }
1415
public Point IconResolution { get; init; }
1516
public bool ShowWhenNotLoaded { get; init; }
17+
public string Description { get; init; }
1618
}

Barotrauma/BarotraumaClient/ClientSource/LuaCs/Configuration/IDisplayables.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public interface IDisplayableData : IDataInfo
3737
/// Whether to show the entry in the menu when not loaded.
3838
/// </summary>
3939
bool ShowWhenNotLoaded { get; }
40+
/// <summary>
41+
/// What does this setting do?
42+
/// </summary>
43+
string Description { get; }
4044
}
4145

4246
public interface IDisplayableInitialize
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Barotrauma.Networking;
2+
3+
namespace Barotrauma.LuaCs.Services.Compatibility;
4+
5+
internal partial interface ILuaCsNetworking : ILuaCsShim
6+
{
7+
public void NetMessageReceived(IReadMessage netMessage, ServerPacketHeader header, Client client = null);
8+
}

Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/IConfigService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ namespace Barotrauma.LuaCs.Services;
99
public partial interface IConfigService
1010
{
1111
/*
12-
* Immediate mode, does not have displayable functionality
12+
* Immediate mode
1313
*/
14-
IConfigEntry<T> AddConfigEntry<T>(IDisplayableData data,
14+
FluentResults.Result<IConfigEntry<T>> AddConfigEntry<T>(IDisplayableData data,
1515
T defaultValue,
1616
NetSync syncMode = NetSync.None,
1717
ClientPermissions permissions = ClientPermissions.None,
1818
Func<T, bool> valueChangePredicate = null,
1919
Action<IConfigEntry<T>> onValueChanged = null) where T : IConvertible, IEquatable<T>;
2020

21-
IConfigList AddConfigList(IDisplayableData data,
21+
FluentResults.Result<IConfigList> AddConfigList(IDisplayableData data,
2222
int defaultIndex, IReadOnlyList<string> values,
2323
NetSync syncMode = NetSync.None,
2424
ClientPermissions permissions = ClientPermissions.None,
2525
Func<IConfigList, int, bool> valueChangePredicate = null,
2626
Action<IConfigList, int> onValueChanged = null);
2727

28-
IConfigRangeEntry<T> AddConfigRangeEntry<T>(IDisplayableData data,
28+
FluentResults.Result<IConfigRangeEntry<T>> AddConfigRangeEntry<T>(IDisplayableData data,
2929
T defaultValue, T minValue, T maxValue,
3030
Func<IConfigRangeEntry<T>, int> getStepCount,
3131
NetSync syncMode = NetSync.None,

Barotrauma/BarotraumaClient/ClientSource/Networking/GameClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ private void ReadDataMessage(IReadMessage inc)
586586
{
587587
ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte();
588588

589-
GameMain.LuaCs.Networking.NetMessageReceived(inc, header);
589+
GameMain.LuaCs.NetworkingService.NetMessageReceived(inc, header);
590590

591591
if (roundInitStatus == RoundInitStatus.WaitingForStartGameFinalize
592592
&& header is not (

Barotrauma/BarotraumaServer/ServerSource/GameMain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public CoroutineHandle ShowLoading(IEnumerable<CoroutineStatus> loader, bool wai
444444
public void Exit()
445445
{
446446
ShouldRun = false;
447-
GameMain.LuaCs.Stop();
447+
GameMain.LuaCs.Dispose();
448448
}
449449
}
450450
}

Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ public Item(Rectangle newRect, ItemPrefab itemPrefab, Submarine submarine, bool
13131313
if (Components.Any(ic => ic is Wire) && Components.All(ic => ic is Wire || ic is Holdable)) { isWire = true; }
13141314
if (HasTag(Barotrauma.Tags.LogicItem)) { isLogic = true; }
13151315

1316-
GameMain.LuaCs.Hook.Call("item.created", this);
1316+
GameMain.LuaCs.Hook.Call<Item>("item.created", this);
13171317

13181318
ApplyStatusEffects(ActionType.OnSpawn, 1.0f);
13191319

@@ -4491,7 +4491,7 @@ public override void ShallowRemove()
44914491
body = null;
44924492
}
44934493

4494-
GameMain.LuaCs.Hook.Call("item.removed", this);
4494+
GameMain.LuaCs.Hook.Call<Item>("item.removed", this);
44954495
}
44964496

44974497
public override void Remove()
@@ -4577,7 +4577,7 @@ public override void Remove()
45774577

45784578
RemoveProjSpecific();
45794579

4580-
GameMain.LuaCs.Hook.Call("item.removed", this);
4580+
GameMain.LuaCs.Hook.Call<Item>("item.removed", this);
45814581
}
45824582

45834583
private void RemoveFromLists()

Barotrauma/BarotraumaShared/SharedSource/LuaCs/Configuration/IConfigEntry.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public interface IConfigEntry<T> : IConfigBase, INetVar where T : IConvertible,
99
bool TrySetValue(T value);
1010
bool IsAssignable(T value);
1111
void Initialize(IVarId id, T defaultValue);
12+
13+
1214
}

Barotrauma/BarotraumaShared/SharedSource/LuaCs/Data/DataInterfaceDefinitions.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public partial record ModConfigInfo : IModConfigInfo
3131
public record AssemblyResourceInfo : IAssemblyResourceInfo
3232
{
3333
public ContentPackage OwnerPackage { get; init; }
34+
public string FallbackPackageName { get; init; }
3435
public string FriendlyName { get; init; }
3536
public bool IsScript { get; init; }
3637
public string InternalName { get; init; }
@@ -49,7 +50,7 @@ public record DependencyInfo : IPackageDependencyInfo
4950
public string InternalName { get; init; }
5051
public ContentPackage OwnerPackage { get; init; }
5152
public string FolderPath { get; init; }
52-
public string PackageName { get; init; }
53+
public string FallbackPackageName { get; init; }
5354
public ulong SteamWorkshopId { get; init; }
5455
public ContentPackage DependencyPackage { get; init; }
5556
public bool IsMissing { get; init; }
@@ -63,15 +64,19 @@ public override int GetHashCode()
6364
return DependencyPackage.GetHashCode();
6465
if (SteamWorkshopId != 0)
6566
return SteamWorkshopId.GetHashCode();
66-
if (!PackageName.IsNullOrWhiteSpace() && !FolderPath.IsNullOrWhiteSpace())
67-
return string.Concat(PackageName, FolderPath).GetHashCode();
67+
if (!FallbackPackageName.IsNullOrWhiteSpace() && !FolderPath.IsNullOrWhiteSpace())
68+
return string.Concat(FallbackPackageName, FolderPath).GetHashCode();
6869
if (!InternalName.IsNullOrWhiteSpace() && !FolderPath.IsNullOrWhiteSpace())
6970
return string.Concat(InternalName, FolderPath).GetHashCode();
7071

7172
return base.GetHashCode();
7273
}
7374

74-
public bool Equals(IPackageDependencyInfo x, IPackageDependencyInfo y)
75+
bool IEqualityComparer<IPackageDependencyInfo>.Equals(IPackageDependencyInfo x, IPackageDependencyInfo y) => DependencyInfo.Equals(x, y);
76+
77+
public static bool operator ==(IPackageDependencyInfo x, DependencyInfo y) => y?.Equals(x) ?? false;
78+
public static bool operator !=(IPackageDependencyInfo x, DependencyInfo y) => y?.Equals(x) ?? false;
79+
public static bool Equals(IPackageDependencyInfo x, IPackageDependencyInfo y)
7580
{
7681
if (x is null)
7782
return false;
@@ -91,21 +96,27 @@ public bool Equals(IPackageDependencyInfo x, IPackageDependencyInfo y)
9196
if (!x.FolderPath.IsNullOrWhiteSpace() != !y.FolderPath.IsNullOrWhiteSpace())
9297
return false;
9398

94-
if (!x.PackageName.IsNullOrWhiteSpace()
95-
&& !y.PackageName.IsNullOrWhiteSpace()
96-
&& y.PackageName == x.PackageName)
99+
if (!x.FallbackPackageName.IsNullOrWhiteSpace()
100+
&& !y.FallbackPackageName.IsNullOrWhiteSpace()
101+
&& y.FallbackPackageName == x.FallbackPackageName)
97102
return true;
98103

99104
if (x.SteamWorkshopId != 0 && y.SteamWorkshopId == x.SteamWorkshopId)
100105
return true;
101106

102107
return false;
103108
}
104-
109+
110+
/// <summary>
111+
/// Returns the hash code unique for the package reference.
112+
/// </summary>
113+
/// <param name="obj"></param>
114+
/// <returns></returns>
115+
/// <remarks>The hash should only be collision-free when referring to different packages.</remarks>
105116
public int GetHashCode(IPackageDependencyInfo obj)
106117
{
107118
int hashCode = Seed;
108-
hashCode = ApplyHashString(hashCode, obj.PackageName);
119+
hashCode = ApplyHashString(hashCode, obj.FallbackPackageName);
109120
hashCode = ApplyHashString(hashCode, obj.InternalName);
110121
if (obj.SteamWorkshopId > 0)
111122
hashCode ^= (int)obj.SteamWorkshopId;
@@ -118,8 +129,8 @@ int ApplyHashString(int currentValue, string str)
118129
if (str is null || str.Length < 1)
119130
return currentValue;
120131
byte[] b = Encoding.UTF8.GetBytes(str);
121-
foreach (var b1 in b)
122-
currentValue ^= b1;
132+
for (int i = 0; i < Math.Min(24, b.Length-1); i++)
133+
currentValue ^= b[i];
123134
return currentValue;
124135
}
125136
catch
@@ -138,6 +149,7 @@ public record LocalizationResourceInfo : ILocalizationResourceInfo
138149
{
139150
public string InternalName { get; init; }
140151
public ContentPackage OwnerPackage { get; init; }
152+
public string FallbackPackageName { get; init; }
141153
public CultureInfo TargetCulture { get; init; }
142154
public Platform SupportedPlatforms { get; init; }
143155
public Target SupportedTargets { get; init; }
@@ -151,6 +163,7 @@ public record LocalizationResourceInfo : ILocalizationResourceInfo
151163
public readonly struct LuaScriptResourceInfo : ILuaResourceInfo
152164
{
153165
public ContentPackage OwnerPackage { get; init; }
166+
public string FallbackPackageName { get; init; }
154167
public Platform SupportedPlatforms { get; init; }
155168
public Target SupportedTargets { get; init; }
156169
public int LoadPriority { get; init; }
Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
using System;
2+
using Barotrauma.LuaCs.Networking;
23
using Barotrauma.Networking;
34

45
namespace Barotrauma.LuaCs.Data;
56

67
// TODO: Finish
78
public partial interface IConfigInfo : IDataInfo
89
{
9-
ConfigDataType Type { get; }
10+
/// <summary>
11+
/// Specifies the data type this should be initialized to (ie. string, int, vector, etc.)
12+
/// Custom types can be registered by mods.
13+
/// </summary>
14+
string DataType { get; }
1015
string DefaultValue { get; }
16+
string StoredValue { get; }
1117
ClientPermissions RequiredPermissions { get; }
12-
}
13-
14-
public enum ConfigDataType
15-
{
16-
Boolean,
17-
Int32,
18-
Int64,
19-
Single,
20-
Double,
21-
String,
22-
Color,
23-
Vector2,
24-
Vector3,
25-
List,
26-
RangeInt32,
27-
RangeSingle,
28-
ControlInput
18+
/// <summary>
19+
/// Whether a value can be changed at runtime.
20+
/// </summary>
21+
bool IsReadOnly { get; }
22+
NetSync NetSync { get; }
2923
}

0 commit comments

Comments
 (0)