Skip to content

Commit

Permalink
Merge pull request #469 from ffxivcode/Vector3-Culture-Fix
Browse files Browse the repository at this point in the history
Fix for Vector3 Parsing for Other Cultures
  • Loading branch information
Herculezz55 authored Sep 18, 2024
2 parents 25f4baa + d39840f commit e8595d5
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 23 deletions.
14 changes: 8 additions & 6 deletions AutoDuty/Data/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public static string ToCustomString(this List<string> strings, string delimiter
return outString;
}

public static string ToCustomString(this PathAction pathAction) =>$"{(pathAction.Tag.EqualsAny(ActionTag.None, ActionTag.Treasure, ActionTag.Revival) ? "" : $"{pathAction.Tag.ToCustomString()}|")}{pathAction.Name}|{pathAction.Position.ToCustomString()}{(pathAction.Arguments.All(x => x.IsNullOrEmpty()) ? "" : $"|{pathAction.Arguments.ToCustomString()}")}{(pathAction.Note.IsNullOrEmpty() ? "" : $"|{pathAction.Note}")}";
public static string ToCustomString(this PathAction pathAction) =>$"{(pathAction.Tag.EqualsAny(ActionTag.None, ActionTag.Treasure, ActionTag.Revival) ? "" : $"{pathAction.Tag.ToCustomString()}|")}{pathAction.Name}|{pathAction.Position.ToCustomString()}{(pathAction.Arguments.All(x => x.IsNullOrEmpty()) ? "" : $"|{pathAction.Arguments.ToCustomString()}")}{(pathAction.Note.IsNullOrEmpty() ? "" : $"|{pathAction.Note}")}";

public static string ToCustomString(this Vector3 vector3) => $"{vector3.X:F2}, {vector3.Y:F2}, {vector3.Z:F2}";
public static string ToCustomString(this Vector3 vector3) => vector3.ToString("F2", CultureInfo.InvariantCulture).Trim('<', '>');

public static List<string> ToConditional(this string conditionalString)
{
Expand Down Expand Up @@ -91,15 +91,17 @@ public static List<string> ToConditional(this string conditionalString)
}


public static bool TryToGetVector3(this string vector3String, out Vector3 vector3)
public static bool TryGetVector3(this string vector3String, out Vector3 vector3)
{
vector3 = Vector3.Zero;
var splitString = vector3String.Replace(" ", string.Empty).Replace("<", string.Empty).Replace(">", string.Empty).Split(',');
var cul = CultureInfo.InvariantCulture;
var strcomp = StringComparison.InvariantCulture;
var splitString = vector3String.Replace(" ", string.Empty, strcomp).Replace("<", string.Empty, strcomp).Replace(">", string.Empty, strcomp).Split(",");

if (splitString.Length < 3) return false;

vector3 = new(float.Parse(splitString[0], CultureInfo.InvariantCulture), float.Parse(splitString[1], CultureInfo.InvariantCulture), float.Parse(splitString[2], CultureInfo.InvariantCulture));
vector3 = new(float.Parse(splitString[0], cul), float.Parse(splitString[1], cul), float.Parse(splitString[2], cul));

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion AutoDuty/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static void OnStart()
try
{
int i = 0;
var files = Plugin.AssemblyDirectoryInfo.EnumerateFiles("*.json", SearchOption.TopDirectoryOnly).Where(s => s.Name.StartsWith('('));
var files = Plugin.AssemblyDirectoryInfo.EnumerateFiles("*.json", SearchOption.AllDirectories).Where(s => s.Name.StartsWith('('));

foreach (var file in files)
{
Expand Down
1 change: 0 additions & 1 deletion AutoDuty/IPC/IPCProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AutoDuty.Helpers;
using AutoDuty.Windows;
using ECommons.EzIpcManager;
#nullable disable

Expand Down
2 changes: 1 addition & 1 deletion AutoDuty/Managers/ActionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public unsafe void ConditionAction(PathAction action)
{
case "GetDistanceToPlayer":
if (conditionArray.Length < 4) return;
if (!conditionArray[1].TryToGetVector3(out var vector3)) return;
if (!conditionArray[1].TryGetVector3(out var vector3)) return;
if (!float.TryParse(conditionArray[3], out var distance)) return;
if (!(operatorValue = conditionArray[2]).EqualsAny(operation.Keys)) return;
var getDistance = GetDistanceToPlayer(vector3);
Expand Down
10 changes: 3 additions & 7 deletions AutoDuty/Managers/ContentPathsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public PathFile PathFile
{
var action = x.Split('|');
var name = action[0];
action[1].TryToGetVector3(out var v3);
var vector3 = action[1].TryGetVector3(out var v3) ? v3 : Vector3.Zero;
var argument = action[2];
var tag = ActionTag.None;

Expand Down Expand Up @@ -208,11 +208,7 @@ public PathFile PathFile
var pathAction = new PathAction { Tag = tag, Name = action[0] };
if (action.Length > 1)
{
var position = action[1].Replace(" ", string.Empty).Split(",");

pathAction.Position = new(float.Parse(position[0]), float.Parse(position[1]), float.Parse(position[2]));


pathAction.Position = action[1].TryGetVector3(out var vector3) ? vector3 : Vector3.Zero;
if (action.Length == 3)
{
var argument = string.Empty;
Expand Down Expand Up @@ -262,7 +258,7 @@ public PathFile PathFile

pathFile = JsonSerializer.Deserialize<PathFile>(json, BuildTab.jsonSerializerOptions);
pathFile?.Actions.Select((Value, Index) => (Value, Index)).Each(x => x.Value.Arguments = [arguments[x.Index]]);
pathFile.Actions.Each(x =>
pathFile?.Actions.Each(x =>
{
var tag = ActionTag.None;

Expand Down
7 changes: 1 addition & 6 deletions AutoDuty/Windows/BuildTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using ImGuiNET;
using System.Text.Json;
using System;
using static AutoDuty.AutoDuty;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
Expand Down Expand Up @@ -502,11 +501,7 @@ private static void AddAction()
_action.Name = _actionText;
_action.Arguments = [.. _argumentsString.Split(",", StringSplitOptions.TrimEntries)];
_action.Tag = _actionTag;
var position = _positionText.Replace(" ", string.Empty).Split(",");
if (!_comment && position.Length == 3 && float.TryParse(position[0], out var p1) && float.TryParse(position[1], out var p2) && float.TryParse(position[2], out var p3))
_action.Position = new(p1, p2, p3);
else
_action.Position = Vector3.Zero;
_action.Position = !_comment && _positionText.TryGetVector3(out var position) ? position : Vector3.Zero;
_action.Note = _comment && !_note.StartsWith("<--") && !_note.EndsWith("-->") ? $"<-- {_note} -->" : _note;
if (_buildListSelected == -1)
{
Expand Down
2 changes: 1 addition & 1 deletion ECommons
Submodule ECommons updated 29 files
+19 −0 ECommons/Automation/Chat.cs
+7 −1 ECommons/Automation/NeoTaskManager/TaskManager.cs
+104 −0 ECommons/Automation/NeoTaskManager/Tasks/NeoTasks.cs
+2 −3 ECommons/DalamudServices/Svc.cs
+1 −1 ECommons/ECommons.csproj
+236 −0 ECommons/ExcelServices/ExcelCombos.cs
+1 −1 ECommons/Funding/PatreonBanner.cs
+8 −0 ECommons/GameFunctions/NameplateKind.cs
+0 −1 ECommons/GameFunctions/ObjectFunctions.cs
+30 −4 ECommons/GameHelpers/Player.cs
+72 −1 ECommons/GenericHelpers.cs
+135 −27 ECommons/ImGuiMethods/ImGuiEx/ImGuiEx.cs
+0 −25 ECommons/ImGuiMethods/PopupWindow.cs
+80 −13 ECommons/Reflection/DalamudReflector.cs
+18 −0 ECommons/SimpleGui/EzConfigGui.cs
+51 −0 ECommons/SimpleGui/PopupWindow.cs
+26 −6 ECommons/UIHelpers/AddonMasterImplementations/!AddonMasterBase.cs
+18 −0 ECommons/UIHelpers/AddonMasterImplementations/AirShipExplorationResult.cs
+33 −0 ECommons/UIHelpers/AddonMasterImplementations/CollectablesShop.cs
+16 −0 ECommons/UIHelpers/AddonMasterImplementations/CompanyCraftSupply.cs
+1 −1 ECommons/UIHelpers/AddonMasterImplementations/ContextMenu.cs
+27 −0 ECommons/UIHelpers/AddonMasterImplementations/DifficultySelectYesNo.cs
+24 −11 ECommons/UIHelpers/AddonMasterImplementations/Gathering.cs
+1 −0 ECommons/UIHelpers/AddonMasterImplementations/JournalDetail.cs
+5 −2 ECommons/UIHelpers/AddonMasterImplementations/LookingForGroup.cs
+13 −13 ECommons/UIHelpers/AddonMasterImplementations/LookingForGroupCondition.cs
+24 −0 ECommons/UIHelpers/AddonMasterImplementations/LookingForGroupDetail.cs
+2 −0 ECommons/UIHelpers/AddonMasterImplementations/Request.cs
+2 −2 ECommons/UIHelpers/AddonMasterImplementations/SalvageDialog.cs

0 comments on commit e8595d5

Please sign in to comment.