Skip to content

Commit

Permalink
new and improved™ row iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAdam committed Feb 9, 2020
1 parent fd71c3f commit ef4e26b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 52 deletions.
3 changes: 2 additions & 1 deletion Lumina.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Lumina.Data;
using Lumina.Data.Structs;
using Lumina.Data.Structs.Excel;
using Lumina.Excel;
Expand Down Expand Up @@ -69,7 +70,7 @@ static void Main( string[] args )
Console.WriteLine($"ActionTimeline GetRows(): {actionTimelineRows.Count}");

var zoneSharedGroup = lumina.GetExcelSheet< ZoneSharedGroup >();
var zsgRows = zoneSharedGroup.GetSubRows();
var zsgRows = zoneSharedGroup.GetRows();
Console.WriteLine($"ZoneSharedGroup GetSubRows(): {zsgRows.Count}");


Expand Down
6 changes: 3 additions & 3 deletions Lumina/Data/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ namespace Lumina.Data
{
public class Category
{
public DirectoryInfo RootDir { get; private set; }
public DirectoryInfo RootDir { get; }

public byte CategoryId { get; }

public int Expansion { get; }

public int Chunk { get; }

public Structs.PlatformId Platform { get; }
public PlatformId Platform { get; }

public SqPackIndex SqPackIndex { get; }

public Dictionary< byte, SqPack > DatFiles { get; internal set; }
public Dictionary< byte, SqPack > DatFiles { get; }

public Category(
byte category,
Expand Down
66 changes: 19 additions & 47 deletions Lumina/Excel/ExcelSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ internal T GetRowInternal( int row, int subRow, Language lang )
return rowObj;
}

public Dictionary< int, T > GetRows()
public List< T > GetRows()
{
return GetRows( Lumina.Options.DefaultExcelLanguage );
}

public Dictionary< int, T > GetRows( Language lang )
public List< T > GetRows( Language lang )
{
var rows = new Dictionary< int, T >();
var rows = new List< T >();
var segments = GetLangSegments( lang );

foreach( var segment in segments )
Expand All @@ -84,59 +84,31 @@ public Dictionary< int, T > GetRows( Language lang )

var parser = new RowParser( this, file );

foreach( var rowPtr in rowPtrs )
{
var id = (int)rowPtr.RowId;
parser.SeekToRow( id );

var obj = Activator.CreateInstance< T >();
obj.PopulateData( parser );

rows[ id ] = obj;
}
}

return rows;
}

public Dictionary< Tuple< int, int >, T > GetSubRows()
{
return GetSubRows( Lumina.Options.DefaultExcelLanguage );
}

public Dictionary< Tuple< int, int >, T > GetSubRows( Language lang )
{
if( Header.Variant != ExcelVariant.Subrows )
{
throw new InvalidOperationException( "can't use GetSubRows to iterate a sheet that doesn't contain subrows!" );
}

var rows = new Dictionary< Tuple< int, int >, T >();
var segments = GetLangSegments( lang );

foreach( var segment in segments )
{
var file = segment.File;

var rowPtrs = file.RowData;

var parser = new RowParser( this, file );

foreach( var rowPtr in rowPtrs )
{
parser.SeekToRow( (int)rowPtr.RowId );

// read subrows
for( int i = 0; i < parser.RowCount; i++ )
if( Header.Variant == ExcelVariant.Subrows )
{
parser.SeekToRow( (int)rowPtr.RowId, i );
// read subrows
for( int i = 0; i < parser.RowCount; i++ )
{
parser.SeekToRow( (int)rowPtr.RowId, i );
var obj = Activator.CreateInstance< T >();

obj.PopulateData( parser );

rows.Add( obj );
}
}
else
{
parser.SeekToRow( (int)rowPtr.RowId );
var obj = Activator.CreateInstance< T >();

obj.PopulateData( parser );

var rowIndex = Tuple.Create( (int)rowPtr.RowId, i );

rows[ rowIndex ] = obj;
rows.Add( obj );
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Lumina/Excel/Generated/ActionTimeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ public class ActionTimeline : IExcelRow
public bool IsMotionCanceledByMoving;
public bool IsLoop;

public int RowId { get; set; }
public int SubRowId { get; set; }

public void PopulateData( RowParser parser )
{
RowId = parser.Row;
SubRowId = parser.SubRow;

Name = parser.ReadOffset< string >( 0x0 );
Type = parser.ReadOffset< byte >( 0x6 );
Priority = parser.ReadOffset< byte >( 0x7 );
Expand Down
6 changes: 6 additions & 0 deletions Lumina/Excel/Generated/ZoneSharedGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ public class ZoneSharedGroup : IExcelRow
public uint col0;
public uint Quest1;

public int RowId { get; set; }
public int SubRowId { get; set; }

public void PopulateData( RowParser parser )
{
RowId = parser.Row;
SubRowId = parser.SubRow;

col0 = parser.ReadColumn< uint >( 0 );
Quest1 = parser.ReadColumn< uint >( 2 );
}
Expand Down
3 changes: 3 additions & 0 deletions Lumina/Excel/IExcelRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ namespace Lumina.Excel
{
public interface IExcelRow
{
int RowId { get; set; }
int SubRowId { get; set; }

void PopulateData( RowParser parser );
}
}
2 changes: 1 addition & 1 deletion Lumina/Lumina.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageProjectUrl>https://github.com/NotAdam/Lumina</PackageProjectUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/NotAdam/Lumina</RepositoryUrl>
<PackageVersion>1.0.0-preview3</PackageVersion>
<PackageVersion>1.0.0-preview4</PackageVersion>
<Description>Lumina is a small, performant and simple library for interacting with FINAL FANTASY XIV game data.</Description>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down

0 comments on commit ef4e26b

Please sign in to comment.