-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically got all file bundle implementations via reflection.
- Loading branch information
1 parent
f7e894a
commit 4f89e99
Showing
4 changed files
with
75 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using fin.util.asserts; | ||
using fin.util.linq; | ||
|
||
namespace fin.util.types; | ||
|
||
public static class TypesUtil { | ||
public static IEnumerable<Type> GetAllImplementationTypes<TInterface>() | ||
=> AppDomain.CurrentDomain.GetAssemblies() | ||
.SelectMany(s => s.GetTypes()) | ||
.Where(typeof(TInterface).IsAssignableFrom) | ||
.Where(t => t is { | ||
IsAbstract: false, ContainsGenericParameters: false | ||
}); | ||
|
||
public static IEnumerable<TInterface> | ||
InstantiateAllImplementationsWithDefaultConstructor<TInterface>() | ||
=> GetAllImplementationTypes<TInterface>() | ||
.SelectWhere<Type, TInterface>( | ||
TryToInstantiateWIthDefaultConstructor_); | ||
|
||
private static bool TryToInstantiateWIthDefaultConstructor_<TInterface>( | ||
Type type, | ||
out TInterface value) { | ||
var constructor = type.GetConstructor([]); | ||
if (constructor == null) { | ||
value = default; | ||
return false; | ||
} | ||
|
||
value = constructor.Invoke([]).AssertAsA<TInterface>(); | ||
return true; | ||
} | ||
} |
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
81 changes: 3 additions & 78 deletions
81
FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/games/RootFileBundleGatherer.cs
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
32 changes: 32 additions & 0 deletions
32
...Tool/UniversalAssetTool/src/games/phantom_hourglass/PhantomHourglassFileBundleGatherer.cs
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 fin.io.bundles; | ||
using fin.util.progress; | ||
|
||
using SceneGate.Ekona.Containers.Rom; | ||
|
||
using uni.platforms; | ||
|
||
using Yarhl.FileSystem; | ||
|
||
namespace uni.games.phantom_hourglass; | ||
|
||
public class PhantomHourglassFileBundleGatherer | ||
: IAnnotatedFileBundleGatherer { | ||
public void GatherFileBundles( | ||
IFileBundleOrganizer organizer, | ||
IMutablePercentageProgress mutablePercentageProgress) { | ||
if (!DirectoryConstants.ROMS_DIRECTORY.TryToGetExistingFile( | ||
"phantom_hourglass.nds", | ||
out var phantomHourglassRom)) { | ||
return; | ||
} | ||
|
||
using var game = NodeFactory.FromFile(phantomHourglassRom.FullPath); | ||
game.TransformWith<Binary2NitroRom>(); | ||
|
||
var names = new List<string>(); | ||
|
||
foreach (var node in Navigator.IterateNodes(game)) { | ||
names.Add(node.Name); | ||
} | ||
} | ||
} |