Skip to content

Commit

Permalink
Use json for config and future kvs saving
Browse files Browse the repository at this point in the history
  • Loading branch information
carmineos committed Feb 23, 2020
1 parent 52f4f2f commit d0419c1
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 109 deletions.
9 changes: 8 additions & 1 deletion VStancer.Client/VStancer.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@
</PropertyGroup>

<ItemGroup>

<PackageReference Include="CitizenFX.Core.Client">
<Version>1.0.2104</Version>
<ExcludeAssets>runtime</ExcludeAssets>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="MenuAPI.FiveM" Version="3.0.4" />

<PackageReference Include="Newtonsoft.Json" Version="12.0.2" ExcludeAssets="Compile" GeneratePathProperty="true" />
<Reference Include="Newtonsoft.Json">
<HintPath>$(PkgNewtonsoft_Json)\lib\portable-net40+sl5+win8+wp8+wpa81\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="&#xD;&#xA; if '$(CI)' == '' ( &#xD;&#xA; call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(TargetPath)&quot;&#xD;&#xA; call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(SolutionDir)\dist\config.xml&quot;&#xD;&#xA; call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(SolutionDir)\dist\fxmanifest.lua&quot;&#xD;&#xA; call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(TargetDir)\MenuAPI.dll&quot;)&#xD;&#xA; " />
<Exec Command="if '$(CI)' == '' ( &#xD;&#xA;call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(TargetPath)&quot;&#xD;&#xA;call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(SolutionDir)\dist\config.json&quot;&#xD;&#xA;call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(SolutionDir)\dist\fxmanifest.lua&quot;&#xD;&#xA;call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(TargetDir)\MenuAPI.dll&quot;&#xD;&#xA;call &quot;$(SolutionDir)postbuild.bat&quot; &quot;$(TargetDir)\Newtonsoft.Json.dll&quot;)" />
</Target>

</Project>
87 changes: 5 additions & 82 deletions VStancer.Client/VStancerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class VStancerConfig
public long Timer { get; set; }
public int ToggleMenuControl { get; set; }
public float FloatStep { get; set; }
public WheelLimits FrontLimits { get; set; }
public WheelLimits RearLimits { get; set; }
public NodeLimits FrontLimits { get; set; }
public NodeLimits RearLimits { get; set; }

public VStancerConfig()
{
Expand All @@ -28,89 +28,12 @@ public VStancerConfig()
Timer = 1000;
ToggleMenuControl = 167;
FloatStep = 0.01f;
FrontLimits = new WheelLimits { PositionX = 0.25f, RotationY = 0.20f };
RearLimits = new WheelLimits { PositionX = 0.25f, RotationY = 0.20f };
}

public void LoadXml(string xml)
{
string txt = Helpers.RemoveByteOrderMarks(xml);

XmlDocument doc = new XmlDocument();
doc.LoadXml(txt);

var rootNode = doc[nameof(VStancerConfig)];

foreach (XmlNode node in rootNode?.ChildNodes)
{
if (node.NodeType != XmlNodeType.Element)
continue;

if (node.Name == nameof(Debug) && bool.TryParse(node.InnerText, out bool debugValue))
Debug = debugValue;

else if (node.Name == nameof(ExposeCommand) && bool.TryParse(node.InnerText, out bool exposeCommandValue))
ExposeCommand = exposeCommandValue;

else if (node.Name == nameof(ExposeEvent) && bool.TryParse(node.InnerText, out bool exposeEventValue))
ExposeEvent = exposeEventValue;

else if (node.Name == nameof(ScriptRange) && float.TryParse(node.InnerText, out float scriptRangeValue))
ScriptRange = scriptRangeValue;

else if (node.Name == nameof(Timer) && long.TryParse(node.InnerText, out long timerValue))
Timer = timerValue;

else if (node.Name == nameof(ToggleMenuControl) && int.TryParse(node.InnerText, out int toggleMenuControlValue))
ToggleMenuControl = toggleMenuControlValue;

else if (node.Name == nameof(FloatStep) && float.TryParse(node.InnerText, out float floatStepValue))
FloatStep = floatStepValue;

else if (node.Name == nameof(FrontLimits))
{
var frontLimits = new WheelLimits();

foreach (XmlNode child in node.ChildNodes)
{
if (node.NodeType != XmlNodeType.Element)
continue;

if (child.Name == nameof(WheelLimits.PositionX) && float.TryParse(child.InnerText, out float positionXValue))
frontLimits.PositionX = positionXValue;

if (child.Name == nameof(WheelLimits.RotationY) && float.TryParse(child.InnerText, out float rotationYValue))
frontLimits.RotationY = rotationYValue;

FrontLimits = frontLimits;
}
}

else if (node.Name == nameof(RearLimits))
{
var rearLimits = new WheelLimits();

foreach (XmlNode child in node.ChildNodes)
{
if (node.NodeType == XmlNodeType.Comment)
continue;

if (child.Name == nameof(WheelLimits.PositionX) && float.TryParse(child.InnerText, out float positionXValue))
rearLimits.PositionX = positionXValue;

if (child.Name == nameof(WheelLimits.RotationY) && float.TryParse(child.InnerText, out float rotationYValue))
rearLimits.RotationY = rotationYValue;

RearLimits = rearLimits;
}
}

else continue;
}
FrontLimits = new NodeLimits { PositionX = 0.25f, RotationY = 0.20f };
RearLimits = new NodeLimits { PositionX = 0.25f, RotationY = 0.20f };
}
}

public struct WheelLimits
public struct NodeLimits
{
public float PositionX { get; set; }
public float RotationY { get; set; }
Expand Down
9 changes: 6 additions & 3 deletions VStancer.Client/VStancerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CitizenFX.Core;
using CitizenFX.Core.UI;
using static CitizenFX.Core.Native.API;
using Newtonsoft.Json;

namespace Vstancer.Client
{
Expand Down Expand Up @@ -790,21 +791,23 @@ private bool HasDecorators(int entity)
/// Loads the config file containing all the customizable properties
/// </summary>
/// <param name="filename">The name of the file</param>
private void LoadConfig(string filename = "config.xml")
private void LoadConfig(string filename = "config.json")
{
VStancerConfig config = new VStancerConfig();
VStancerConfig config = null;
try
{
string strings = LoadResourceFile(ResourceName, filename);

config.LoadXml(strings);
config = JsonConvert.DeserializeObject<VStancerConfig>(strings);

Debug.WriteLine($"{ScriptName}: Loaded config from {filename}");
}
catch (Exception e)
{
Debug.WriteLine($"{ScriptName}: Impossible to load {filename}", e.Message);
Debug.WriteLine(e.StackTrace);

config = new VStancerConfig();
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion VStancer.Client/VStancerPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ public struct VStancerNode
{
//public Vector3 Position { get; set; }
//public Vector3 Rotation { get; set; }
//public Vector3 Scale { get; set; }
public float PositionX { get; set; }
public float RotationY { get; set; }
//public Vector3 Scale { get; set; }
}
}
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ install:
- ps: if ($env:APPVEYOR_REPO_TAG -ne $True){ $env:TAG_NUMBER = $env:TAG_NUMBER + "." + $env:APPVEYOR_BUILD_NUMBER } else { $env:TAG_NUMBER = $env:TAG_NUMBER + "." + 0 }

version: 1.0.{build}
image: Visual Studio 2017
image: Visual Studio 2019
configuration: Release

dotnet_csproj:
Expand All @@ -22,14 +22,14 @@ build:
project: fivem-vstancer.sln

before_build:
- cmd: git submodule update --init --recursive
- nuget restore

after_build:
- cmd: md %APPVEYOR_BUILD_FOLDER%\dist\vstancer
- cmd: move /Y %APPVEYOR_BUILD_FOLDER%\dist\*.* %APPVEYOR_BUILD_FOLDER%\dist\vstancer
- cmd: move /Y %APPVEYOR_BUILD_FOLDER%\VStancer.Client\bin\%CONFIGURATION%\net452\VStancer.Client.net.dll %APPVEYOR_BUILD_FOLDER%\dist\vstancer
- cmd: move /Y %APPVEYOR_BUILD_FOLDER%\VStancer.Client\bin\%CONFIGURATION%\net452\MenuAPI.dll %APPVEYOR_BUILD_FOLDER%\dist\vstancer
- cmd: move /Y %APPVEYOR_BUILD_FOLDER%\VStancer.Client\bin\%CONFIGURATION%\net452\Newtonsoft.Json.dll %APPVEYOR_BUILD_FOLDER%\dist\vstancer
- 7z a vstancer-v%TAG_NUMBER%.zip %APPVEYOR_BUILD_FOLDER%\dist\*

artifacts:
Expand Down
17 changes: 17 additions & 0 deletions dist/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Debug": false,
"ExposeCommand": false,
"ExposeEvent": false,
"ScriptRange": 150.0,
"Timer": 1000,
"ToggleMenuControl": 167,
"FloatStep": 0.01,
"FrontLimits": {
"PositionX": 0.25,
"RotationY": 0.2
},
"RearLimits": {
"PositionX": 0.25,
"RotationY": 0.2
}
}
18 changes: 0 additions & 18 deletions dist/config.xml

This file was deleted.

3 changes: 2 additions & 1 deletion dist/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ games { 'gta5' }
files {
--'@MenuAPI/MenuAPI.dll',
'MenuAPI.dll',
'config.xml'
'Newtonsoft.Json.dll',
'config.json'
}

client_scripts {
Expand Down
2 changes: 1 addition & 1 deletion fivem-vstancer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VStancer.Client", "VStancer
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{886C4B07-F58C-4E89-A80F-849679435A18}"
ProjectSection(SolutionItems) = preProject
dist\config.xml = dist\config.xml
dist\config.json = dist\config.json
dist\fxmanifest.lua = dist\fxmanifest.lua
LICENSE = LICENSE
postbuild.bat = postbuild.bat
Expand Down

0 comments on commit d0419c1

Please sign in to comment.