aboutsummaryrefslogtreecommitdiff
path: root/core/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'core/bindings')
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/ControllerData.cs23
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameArchiveData.cs21
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameData.cs23
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/IRawData.cs6
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/IRustData.cs13
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/ControlMessage.cs25
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/GameMessage.cs18
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Player.cs42
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs23
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs21
-rw-r--r--core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Example/Program.cs14
11 files changed, 187 insertions, 42 deletions
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/ControllerData.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/ControllerData.cs
index c2d6391..ca4478e 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/ControllerData.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/ControllerData.cs
@@ -2,18 +2,31 @@ using NoGamepads_Sharp;
namespace NoGamepads_Core.Data;
-public class ControllerData : IRawData<FfiControllerData>
+public class ControllerData : IRustDataBorrow<FfiControllerData>, IRustDataUse<FfiControllerData>
{
- private readonly FfiControllerData _ffi;
+ private readonly FfiControllerData? _ffi;
+ private bool _used;
public ControllerData(Player player)
{
_ffi = nogamepads_data.ControllerDataNew();
- nogamepads_data.ControllerDataBindPlayer(_ffi, player.GetRawData());
+ nogamepads_data.ControllerDataBindPlayer(_ffi, player.Use());
}
-
- public FfiControllerData GetRawData()
+
+ public FfiControllerData? Borrow()
{
return _ffi;
}
+
+ public bool IsUsed()
+ {
+ return _used;
+ }
+
+ public FfiControllerData? Use()
+ {
+ var temp = IsUsed() ? null : _ffi;
+ _used = true;
+ return temp;
+ }
} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameArchiveData.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameArchiveData.cs
index 85b37ac..18d54fd 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameArchiveData.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameArchiveData.cs
@@ -2,17 +2,30 @@ using NoGamepads_Sharp;
namespace NoGamepads_Core.Data;
-public class GameArchiveData : IRawData<FfiGameRuntimeArchive>
+public class GameArchiveData : IRustDataBorrow<FfiGameRuntimeArchive>, IRustDataUse<FfiGameRuntimeArchive>
{
- private readonly FfiGameRuntimeArchive _ffi = nogamepads_data.GameArchiveDataNew();
+ private readonly FfiGameRuntimeArchive? _ffi = nogamepads_data.GameArchiveDataNew();
+ private bool _used;
public void AddBannedPlayer(Player player)
{
- nogamepads_data.GameArchiveDataAddBanPlayer(_ffi, player.GetRawData());
+ nogamepads_data.GameArchiveDataAddBanPlayer(_ffi, player.Use());
}
- public FfiGameRuntimeArchive GetRawData()
+ public FfiGameRuntimeArchive? Borrow()
{
return _ffi;
}
+
+ public bool IsUsed()
+ {
+ return _used;
+ }
+
+ public FfiGameRuntimeArchive? Use()
+ {
+ var temp = IsUsed() ? null : _ffi;
+ _used = true;
+ return temp;
+ }
} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameData.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameData.cs
index 480636b..25828a9 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameData.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/GameData.cs
@@ -2,9 +2,10 @@ using NoGamepads_Sharp;
namespace NoGamepads_Core.Data;
-public class GameData : IRawData<FfiGameData>
+public class GameData : IRustDataBorrow<FfiGameData>, IRustDataUse<FfiGameData>
{
- private readonly FfiGameData _ffi = nogamepads_data.GameDataNew();
+ private readonly FfiGameData? _ffi = nogamepads_data.GameDataNew();
+ private bool _used;
public string Name
{
@@ -23,11 +24,23 @@ public class GameData : IRawData<FfiGameData>
public void LoadArchive(GameArchiveData gameArchiveData)
{
- nogamepads_data.GameDataLoadArchive(_ffi, gameArchiveData.GetRawData());
+ nogamepads_data.GameDataLoadArchive(_ffi, gameArchiveData.Use());
}
-
- public FfiGameData GetRawData()
+
+ public FfiGameData? Borrow()
{
return _ffi;
}
+
+ public bool IsUsed()
+ {
+ return _used;
+ }
+
+ public FfiGameData? Use()
+ {
+ var temp = IsUsed() ? null : _ffi;
+ _used = true;
+ return temp;
+ }
} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/IRawData.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/IRawData.cs
deleted file mode 100644
index a0e72ea..0000000
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/IRawData.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace NoGamepads_Core.Data;
-
-public interface IRawData<T>
-{
- T GetRawData();
-} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/IRustData.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/IRustData.cs
new file mode 100644
index 0000000..30a58fc
--- /dev/null
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/IRustData.cs
@@ -0,0 +1,13 @@
+namespace NoGamepads_Core.Data;
+
+public interface IRustDataBorrow<out T>
+{
+ T? Borrow();
+}
+
+public interface IRustDataUse<out T>
+{
+ bool IsUsed();
+
+ T? Use();
+} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/ControlMessage.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/ControlMessage.cs
index fb41612..d1f64cf 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/ControlMessage.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/ControlMessage.cs
@@ -155,4 +155,29 @@ public struct ControlMessage
}
return Error();
}
+
+ public override string ToString()
+ {
+ switch (_tag)
+ {
+ case Tag.Message:
+ return _content;
+ case Tag.Pressed:
+ return $"btn_{_key}: PRESSED";
+ case Tag.Released:
+ return $"btn_{_key}: RELEASED";
+ case Tag.Axis:
+ return $"ax_{_key}: {_x}";
+ case Tag.Direction:
+ return $"dir_{_key}: ({_x}, {_y})";
+ case Tag.Exit:
+ return "exit";
+ case Tag.Error:
+ return "error";
+ case Tag.End:
+ return "end (xD)";
+ }
+
+ return "unknown";
+ }
} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/GameMessage.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/GameMessage.cs
index 427c674..b29c2c5 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/GameMessage.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Message/GameMessage.cs
@@ -101,4 +101,22 @@ public struct GameMessage
}
return Error();
}
+
+ public override string ToString()
+ {
+ switch (_tag)
+ {
+ case Tag.EventTrigger:
+ return $"event: {_key}";
+ case Tag.Message:
+ return _content;
+ case Tag.LetExit:
+ return $"exit: {_exitReason.ToString()}";
+ case Tag.Error:
+ return "error";
+ case Tag.End:
+ return "end";
+ }
+ return "unknown";
+ }
} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Player.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Player.cs
index 55280d1..3ad5d7f 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Player.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/Player.cs
@@ -2,9 +2,10 @@ using NoGamepads_Sharp;
namespace NoGamepads_Core.Data;
-public class Player : IRawData<FfiPlayer>
+public class Player : IRustDataBorrow<FfiPlayer>, IRustDataUse<FfiPlayer>
{
- private readonly FfiPlayer _ffi;
+ private readonly FfiPlayer? _ffi;
+ private bool _used;
public Player(string account, string password)
{
@@ -17,8 +18,8 @@ public class Player : IRawData<FfiPlayer>
{
unsafe
{
- var get = _ffi.Customize;
- return get == null ? "" : PtrStringConverter.ToString(get.Nickname);
+ var get = _ffi?.Customize;
+ return get == null || IsUsed() ? "" : PtrStringConverter.ToString(get.Nickname);
}
}
@@ -31,7 +32,8 @@ public class Player : IRawData<FfiPlayer>
{
unsafe
{
- return PtrStringConverter.ToString(_ffi.Account.Id);
+ var get = _ffi?.Account;
+ return get == null || IsUsed() ? "" : PtrStringConverter.ToString(get.Id);
}
}
}
@@ -42,8 +44,8 @@ public class Player : IRawData<FfiPlayer>
{
unsafe
{
- var get = _ffi.Account.PlayerHash;
- return PtrStringConverter.ToString(get);
+ var get = _ffi?.Account;
+ return get == null || IsUsed() ? "" : PtrStringConverter.ToString(get.PlayerHash);
}
}
}
@@ -73,21 +75,39 @@ public class Player : IRawData<FfiPlayer>
private int GetHue()
{
- return _ffi.Customize?.ColorHue ?? 0;
+ if (IsUsed())
+ return 0;
+ return _ffi?.Customize?.ColorHue ?? 0;
}
private float GetValue()
{
- return (float) (_ffi.Customize?.ColorValue ?? 1f);
+ if (IsUsed())
+ return 1f;
+ return (float) (_ffi?.Customize?.ColorValue ?? 1f);
}
private float GetSaturation()
{
- return (float) (_ffi.Customize?.ColorSaturation ?? 1f);
+ if (IsUsed())
+ return 1f;
+ return (float) (_ffi?.Customize?.ColorSaturation ?? 1f);
}
- public FfiPlayer GetRawData()
+ public FfiPlayer? Borrow()
{
return _ffi;
}
+
+ public bool IsUsed()
+ {
+ return _used;
+ }
+
+ public FfiPlayer? Use()
+ {
+ var temp = IsUsed() ? null : _ffi;
+ _used = true;
+ return temp;
+ }
} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs
index 0716c04..5a2a30a 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs
@@ -4,13 +4,14 @@ using NoGamepads_Sharp;
namespace NoGamepads_Core.Runtime;
-public class ControllerRuntime : IRawData<FfiControllerRuntime>
+public class ControllerRuntime : IRustDataBorrow<FfiControllerRuntime>, IRustDataUse<FfiControllerRuntime>
{
- private readonly FfiControllerRuntime _ffi;
+ private readonly FfiControllerRuntime? _ffi;
+ private bool _used;
public ControllerRuntime(ControllerData data)
{
- _ffi = nogamepads_data.ControllerDataBuildRuntime(data.GetRawData());
+ _ffi = nogamepads_data.ControllerDataBuildRuntime(data.Borrow());
}
public void Close()
@@ -53,9 +54,21 @@ public class ControllerRuntime : IRawData<FfiControllerRuntime>
var result = nogamepads_data.ControllerRuntimePop(_ffi);
return result == null ? GameMessage.Error() : GameMessage.From(result);
}
-
- public FfiControllerRuntime GetRawData()
+
+ public FfiControllerRuntime? Borrow()
{
return _ffi;
}
+
+ public bool IsUsed()
+ {
+ return _used;
+ }
+
+ public FfiControllerRuntime? Use()
+ {
+ var temp = IsUsed() ? null : _ffi;
+ _used = true;
+ return temp;
+ }
} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs
index 9ba5e14..7211581 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs
@@ -3,17 +3,30 @@ using NoGamepads_Sharp;
namespace NoGamepads_Core.Runtime;
-public class GameRuntime : IRawData<FfiGameRuntime>
+public class GameRuntime : IRustDataBorrow<FfiGameRuntime>, IRustDataUse<FfiGameRuntime>
{
- private readonly FfiGameRuntime _ffi;
+ private readonly FfiGameRuntime? _ffi;
+ private bool _used;
public GameRuntime(GameData data)
{
- _ffi = nogamepads_data.GameDataBuildRuntime(data.GetRawData());
+ _ffi = nogamepads_data.GameDataBuildRuntime(data.Borrow());
}
- public FfiGameRuntime GetRawData()
+ public FfiGameRuntime? Borrow()
{
return _ffi;
}
+
+ public bool IsUsed()
+ {
+ return _used;
+ }
+
+ public FfiGameRuntime? Use()
+ {
+ var temp = IsUsed() ? null : _ffi;
+ _used = true;
+ return temp;
+ }
} \ No newline at end of file
diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Example/Program.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Example/Program.cs
index 11b0d76..166526d 100644
--- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Example/Program.cs
+++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Example/Program.cs
@@ -1,5 +1,6 @@
using NoGamepads_Core.Data;
using NoGamepads_Core.Runtime;
+using NoGamepads_Sharp;
namespace NoGamepads_Example;
@@ -8,7 +9,7 @@ internal class Program
public static void Main(string[] args)
{
Player player = new Player("CatilGrass", "Unknown Password");
-
+
player.Hue = 200;
ControllerData data = new ControllerData(player);
@@ -16,8 +17,17 @@ internal class Program
ControllerRuntime runtime = new ControllerRuntime(data);
runtime.SendTextMessage("Hello World! ");
+
Console.WriteLine(player.Hue + "!");
- // Console.WriteLine(player.Hash);
+ Console.WriteLine(player.Hash);
+
+ var ffi = runtime.Use();
+ if (ffi != null)
+ {
+ nogamepads_data.EnableLogger(2);
+ var client = nogamepads_data.TcpClientBuild(ffi);
+ nogamepads_data.TcpClientConnect(client);
+ }
}
} \ No newline at end of file