misc changes

add class/struct array to csv table with named columns utility

slight usum prep / cleanup
This commit is contained in:
Kurt
2017-11-03 21:15:36 -07:00
parent abc9272288
commit 5c633d205c
4 changed files with 63 additions and 4 deletions

View File

@@ -6,6 +6,6 @@ namespace pk3DS.Core.CTR
internal static class ETC1
{
[DllImport("ETC1Lib.dll", EntryPoint = "ConvertETC1", CallingConvention = CallingConvention.Cdecl)]
public static extern void ConvertETC1(IntPtr dataOut, ref uint dataOutSize, IntPtr dataIn, UInt16 width, UInt16 height, bool alpha);
public static extern void ConvertETC1(IntPtr dataOut, ref uint dataOutSize, IntPtr dataIn, ushort width, ushort height, bool alpha);
}
}

View File

@@ -50,9 +50,9 @@ private void LoadSM()
private void LoadUSUM()
{
MaxSpeciesID = Legal.MaxSpeciesID_7;
MaxMoveID = Legal.MaxMoveID_7;
MaxItemID = Legal.MaxItemID_7;
MaxSpeciesID = Legal.MaxSpeciesID_7_USUM;
MaxMoveID = Legal.MaxMoveID_7_USUM;
MaxItemID = Legal.MaxItemID_7_USUM;
HeldItems = Legal.HeldItems_SM;
MaxAbilityID = Legal.MaxAbilityID_7;
}

View File

@@ -11,6 +11,10 @@ public static partial class Legal
internal const int MaxBallID_7 = 0x1A; // 26
internal const int MaxGameID_7 = 41; // Crystal (VC?)
internal const int MaxSpeciesID_7_USUM = 802;
internal const int MaxMoveID_7_USUM = 720;
internal const int MaxItemID_7_USUM = 920;
#region Met Locations
internal static readonly int[] Met_SMc = { 0, 60002, 30002, };

55
pk3DS.Core/TableUtil.cs Normal file
View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace pk3DS.Core
{
public static class TableUtil
{
private const string sep = "\t";
public static string GetTable<T>(IEnumerable<T> arr, IList<string> names, string name = null) where T : new()
{
var list = GetTableRaw(arr).ToArray();
// slap in name to column header
list[0] = $"{name ?? typeof(T).Name}{sep}{list[0]}";
// slap in row name to row
for (int i = 1; i < list.Length; i++)
list[i] = $"{names[i - 1]}{sep}{list[i]}";
return string.Join(Environment.NewLine, list);
}
public static string GetTable<T>(IEnumerable<T> arr) where T : new()
{
return string.Join(Environment.NewLine, GetTableRaw(arr));
}
private static IEnumerable<string> GetTableRaw<T>(IEnumerable<T> arr) where T : new()
{
return Table(arr).Select(row => string.Join(sep, row));
}
private static IEnumerable<IEnumerable<string>> Table<T>(IEnumerable<T> arr) where T : new()
{
var type = typeof(T);
yield return GetNames(type);
foreach (var z in arr)
yield return GetValues(z, type);
}
private static IEnumerable<string> GetNames(Type type)
{
foreach (var z in type.GetProperties())
yield return z.Name;
foreach (var z in type.GetFields())
yield return z.Name;
}
private static IEnumerable<string> GetValues(object obj, Type type)
{
foreach (var z in type.GetProperties())
yield return z.GetValue(obj, null)?.ToString() ?? "";
foreach (var z in type.GetFields())
yield return z.GetValue(obj)?.ToString() ?? "";
}
}
}