mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-06-01 04:53:29 -05:00
support hex numbers in table length
This commit is contained in:
parent
cd78b16f69
commit
19c0d05030
|
|
@ -24,6 +24,12 @@ namespace HavenSoft.HexManiac.Core {
|
|||
return value;
|
||||
}
|
||||
|
||||
public static bool TryParseInt(this string str, out int result) {
|
||||
if (str.StartsWith("0x") && int.TryParse(str.Substring(2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out result)) return true;
|
||||
if (int.TryParse(str, out result)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// allows writing 5.Range() instead of Enumerable.Range(0, 5)
|
||||
public static IEnumerable<int> Range(this int count) => Enumerable.Range(0, count);
|
||||
|
||||
|
|
|
|||
|
|
@ -511,7 +511,7 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
|
|||
ParentOffset = ParentOffset.Default;
|
||||
ElementCount = Math.Max(1, elementCount); // if the user said there's a format here, then there is, even if the format it wrong.
|
||||
FormatString += ElementCount;
|
||||
} else if (int.TryParse(length, out int result)) {
|
||||
} else if (length.TryParseInt(out int result)) {
|
||||
// fixed length is easy
|
||||
LengthFromAnchor = string.Empty;
|
||||
ParentOffset = ParentOffset.Default;
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
|
|||
public IEnumerable<string> GetOptions(IDataModel model) => GetOptions(model, EnumName);
|
||||
|
||||
public static IEnumerable<string> GetOptions(IDataModel model, string enumName) {
|
||||
if (int.TryParse(enumName, out var result)) return result.Range().Select(i => i.ToString());
|
||||
if (enumName.TryParseInt(out var result)) return result.Range().Select(i => i.ToString());
|
||||
IEnumerable<string> options = model.GetOptions(enumName);
|
||||
|
||||
// we _need_ options for the table tool
|
||||
|
|
|
|||
|
|
@ -1126,6 +1126,20 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
Assert.Equal("0, 0,", FileSystem.CopyText.value.Trim());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TableWithHexLength_Parse_NoError() {
|
||||
ViewPort.Edit("^table[a:: b::]0x10 ");
|
||||
Assert.Equal(8 * 16, Model.GetNextRun(0).Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TableWithHexEnum_Parse_NoErrors() {
|
||||
ViewPort.Edit("^table[a::0x10 b::]10 ");
|
||||
var table = Model.GetTable("table");
|
||||
var seg = (ArrayRunEnumSegment)table.ElementContent[0];
|
||||
Assert.Equal(16, seg.GetOptions(Model).Count());
|
||||
}
|
||||
|
||||
private void ArrangeTrainerPokemonTeamData(byte structType, byte pokemonCount, int trainerCount) {
|
||||
CreateTextTable(HardcodeTablesModel.PokemonNameTable, 0x180, "ABCDEFGHIJKLMNOP".Select(c => c.ToString()).ToArray());
|
||||
CreateTextTable(HardcodeTablesModel.MoveNamesTable, 0x1B0, "qrstuvwxyz".Select(c => c.ToString()).ToArray());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user