Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat: add code generator!
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jan 19, 2024
1 parent c97be9e commit a454f1c
Show file tree
Hide file tree
Showing 18 changed files with 14,462 additions and 157 deletions.
36 changes: 30 additions & 6 deletions DefaultRotations/DefaultRotations.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>full</DebugType>
<PropertyGroup>
<DalamudLibPath>$(AppData)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\RotationSolver.Basic\RotationSolver.Basic.csproj" />
</ItemGroup>
<ItemGroup>

<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(DalamudLibPath)ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGuiScene">
<HintPath>$(DalamudLibPath)ImGuiScene.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina">
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(DalamudLibPath)Lumina.Excel.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(DalamudLibPath)Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Using Include="Dalamud.Game.ClientState.JobGauge.Enums" />
<Using Include="Dalamud.Game.ClientState.Objects.Types" />
<Using Include="Dalamud.Interface" />
Expand Down
34 changes: 0 additions & 34 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,8 @@
<Platforms>AnyCPU</Platforms>
<LangVersion>latest</LangVersion>

<DalamudLibPath>$(AppData)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(DalamudLibPath)ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGuiScene">
<HintPath>$(DalamudLibPath)ImGuiScene.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina">
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(DalamudLibPath)Lumina.Excel.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(DalamudLibPath)Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>

<Using Include="Dalamud.Game.ClientState.JobGauge.Enums" />
<Using Include="Dalamud.Interface" />
<Using Include="ImGuiNET" />
<Using Include="Newtonsoft.Json" />
<Using Include="System.Numerics" />
<Using Include="System.Reflection" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion ECommons
Submodule ECommons updated 126 files
41 changes: 0 additions & 41 deletions RotationSolver.Basic/Actions/Actions.cd

This file was deleted.

10 changes: 5 additions & 5 deletions RotationSolver.Basic/Actions/BaseAction_ActionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace RotationSolver.Basic.Actions;

public partial class BaseAction
{
internal static readonly uint[] ActionsNoNeedCasting = new uint[]
{
internal static readonly uint[] ActionsNoNeedCasting =
[
5,
(uint)ActionID.PvP_PowerfulShot,
(uint)ActionID.PvP_BlastCharge,
};
];
/// <summary>
/// The user set heal ratio.
/// </summary>
Expand Down Expand Up @@ -99,7 +99,7 @@ public unsafe virtual bool CanUse(out IAction act, CanUseOption option = CanUseO
var mustUse = option.HasFlag(CanUseOption.MustUse);

Target = player;
AffectedTargets = Array.Empty<BattleChara>();
AffectedTargets = [];

if (AutoHealCheck && IsFriendly)
{
Expand Down Expand Up @@ -200,7 +200,7 @@ private bool CheckForCombo()

var comboActions = _action.ActionCombo?.Row != 0
? new ActionID[] { (ActionID)_action.ActionCombo.Row }
: Array.Empty<ActionID>();
: [];
if (ComboIds != null) comboActions = comboActions.Union(ComboIds).ToArray();

if (comboActions.Length > 0)
Expand Down
44 changes: 37 additions & 7 deletions RotationSolver.Basic/RotationSolver.Basic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,38 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<EnforceCodeStyleInBuild>False</EnforceCodeStyleInBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>full</DebugType>
<DalamudLibPath>$(AppData)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(DalamudLibPath)ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGuiScene">
<HintPath>$(DalamudLibPath)ImGuiScene.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina">
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(DalamudLibPath)Lumina.Excel.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(DalamudLibPath)Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>

<Using Include="System.ComponentModel" />
<Using Include="Dalamud.Game.ClientState.JobGauge.Types" />

Expand All @@ -34,11 +58,17 @@
<Using Include="RotationSolver.Basic.Helpers" />
<Using Include="RotationSolver.Basic.Rotations" />
<Using Include="RotationSolver.Basic.Rotations.Basic" />

<Using Include="Dalamud.Game.ClientState.JobGauge.Enums" />
<Using Include="Dalamud.Interface" />
<Using Include="ImGuiNET" />
<Using Include="Newtonsoft.Json" />

<ProjectReference Include="..\ECommons\ECommons\ECommons.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>

<ProjectReference Include="..\RotationSolver.SourceGenerators\RotationSolver.SourceGenerators.csproj" OutputItemType="Analyzer"/>

<None Include="..\COPYING.LESSER">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
Expand Down
81 changes: 81 additions & 0 deletions RotationSolver.GameData/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// See https://aka.ms/new-console-template for more information
using Lumina;
using Lumina.Excel.GeneratedSheets;
using System.Resources.NetStandard;
using System.Text.RegularExpressions;

var gameData = new GameData("C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack", new LuminaOptions
{
LoadMultithreaded = true,
CacheFileResources = true,
PanicOnSheetChecksumMismatch = false,
DefaultExcelLanguage = Lumina.Data.Language.English,
});

var statuses = gameData.GetExcelSheet<Status>();

if (statuses == null) return;

Dictionary<string, byte> _count = [];
var status =string.Join("\n", statuses.Where(UseStatus).Select(StatusString));

var dirInfo = new DirectoryInfo(typeof(Program).Assembly.Location);
dirInfo = dirInfo.Parent!.Parent!.Parent!.Parent!.Parent!;

using var res = new ResXResourceWriter(dirInfo.FullName + "\\RotationSolver.SourceGenerators\\Properties\\Resources.resx");

res.AddResource("StatusId", status);
res.Generate();

Console.WriteLine(status);

static bool UseStatus(Status status)
{
if (status.ClassJobCategory.Row == 0) return false;
var name = status.Name.RawString;
if (string.IsNullOrEmpty(name)) return false;
if (!name.All(char.IsAscii)) return false;
return true;
}

string StatusString(Status status)
{
var name = ConvertToPascalCase(status.Name.RawString);
if (_count.ContainsKey(name))
{
name += "_" + (++_count[name]).ToString();
}
else
{
_count[name] = 1;
}

var desc = new string(status.Description.RawString.Where(char.IsAscii).ToArray());

return $"""
/// <summary>
/// {desc.Replace("\n", "\n/// ")}
/// </summary>
{name} = {status.RowId},
""";
}


static string ConvertToPascalCase(string input)
{
Regex invalidCharsRgx = new(@"[^_a-zA-Z0-9]");
Regex whiteSpace = new(@"(?<=\s)");
Regex startsWithLowerCaseChar = new("^[a-z]");
Regex firstCharFollowedByUpperCasesOnly = new("(?<=[A-Z])[A-Z0-9]+$");
Regex lowerCaseNextToNumber = new("(?<=[0-9])[a-z]");
Regex upperCaseInside = new("(?<=[A-Z])[A-Z]+?((?=[A-Z][a-z])|(?=[0-9]))");

var pascalCase = invalidCharsRgx.Replace(whiteSpace.Replace(input, "_"), string.Empty)
.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries)
.Select(w => startsWithLowerCaseChar.Replace(w, m => m.Value.ToUpper()))
.Select(w => firstCharFollowedByUpperCasesOnly.Replace(w, m => m.Value.ToLower()))
.Select(w => lowerCaseNextToNumber.Replace(w, m => m.Value.ToUpper()))
.Select(w => upperCaseInside.Replace(w, m => m.Value.ToLower()));

return string.Concat(pascalCase);
}
14 changes: 14 additions & 0 deletions RotationSolver.GameData/RotationSolver.GameData.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lumina.Excel" Version="6.5.2" />
<PackageReference Include="ResXResourceReader.NetStandard" Version="1.2.0" />
</ItemGroup>
</Project>
Loading

0 comments on commit a454f1c

Please sign in to comment.