This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add content type code generator.
- Loading branch information
1 parent
a454f1c
commit 69184dc
Showing
11 changed files
with
1,492 additions
and
1,363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Lumina.Excel.GeneratedSheets; | ||
|
||
namespace RotationSolver.GameData; | ||
internal class ContentTypeGetter(Lumina.GameData gameData) | ||
: ExcelRowGetter<ContentType>(gameData) | ||
{ | ||
protected override bool AddToList(ContentType item) | ||
{ | ||
if (string.IsNullOrEmpty(item.Name.RawString)) return false; | ||
return true; | ||
} | ||
|
||
protected override string ToCode(ContentType item) | ||
{ | ||
var name = item.Name.RawString.ToPascalCase(); | ||
return $""" | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
{name} = {item.RowId}, | ||
"""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Lumina.Excel; | ||
|
||
namespace RotationSolver.GameData; | ||
internal abstract class ExcelRowGetter<T>(Lumina.GameData gameData) where T :ExcelRow | ||
{ | ||
protected abstract bool AddToList(T item); | ||
protected abstract string ToCode(T item); | ||
|
||
protected virtual void BeforeCreating() { } | ||
|
||
public string GetCode() | ||
{ | ||
var items = gameData.GetExcelSheet<T>(); | ||
|
||
if (items == null) return string.Empty; | ||
BeforeCreating(); | ||
return string.Join("\n", items.Where(AddToList).Select(ToCode)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Lumina.Excel.GeneratedSheets; | ||
|
||
namespace RotationSolver.GameData; | ||
internal class StatusGetter(Lumina.GameData gameData) | ||
: ExcelRowGetter<Status>(gameData) | ||
{ | ||
private readonly List<string> _addedNames = []; | ||
|
||
protected override void BeforeCreating() | ||
{ | ||
_addedNames.Clear(); | ||
base.BeforeCreating(); | ||
} | ||
|
||
protected override bool AddToList(Status item) | ||
{ | ||
if (item.ClassJobCategory.Row == 0) return false; | ||
var name = item.Name.RawString; | ||
if (string.IsNullOrEmpty(name)) return false; | ||
if (!name.All(char.IsAscii)) return false; | ||
return true; | ||
} | ||
|
||
protected override string ToCode(Status item) | ||
{ | ||
var name = item.Name.RawString.ToPascalCase(); | ||
if (_addedNames.Contains(name)) | ||
{ | ||
name += "_" + item.RowId.ToString(); | ||
} | ||
else | ||
{ | ||
_addedNames.Add(name); | ||
} | ||
|
||
return $""" | ||
/// <summary> | ||
/// {item.Description.RawString.OnlyAscii().Replace("\n", "\n/// ")} | ||
/// </summary> | ||
{name} = {item.RowId}, | ||
"""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace RotationSolver.GameData; | ||
internal static partial class Util | ||
{ | ||
public static string OnlyAscii(this string input) => new string(input.Where(char.IsAscii).ToArray()); | ||
|
||
public static string ToPascalCase(this string input) | ||
{ | ||
var pascalCase = InvalidCharsRgx().Replace(WhiteSpace().Replace(input, "_"), string.Empty) | ||
.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries) | ||
.Select(w => StartWithLowerCaseChar().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); | ||
} | ||
|
||
[GeneratedRegex("[^_a-zA-Z0-9]")] | ||
private static partial Regex InvalidCharsRgx(); | ||
[GeneratedRegex("(?<=\\s)")] | ||
private static partial Regex WhiteSpace(); | ||
[GeneratedRegex("^[a-z]")] | ||
private static partial Regex StartWithLowerCaseChar(); | ||
[GeneratedRegex("(?<=[A-Z])[A-Z0-9]+$")] | ||
private static partial Regex FirstCharFollowedByUpperCasesOnly(); | ||
[GeneratedRegex("(?<=[0-9])[a-z]")] | ||
private static partial Regex LowerCaseNextToNumber(); | ||
[GeneratedRegex("(?<=[A-Z])[A-Z]+?((?=[A-Z][a-z])|(?=[0-9]))")] | ||
private static partial Regex UpperCaseInside(); | ||
} |
Oops, something went wrong.