mirror of
https://github.com/kwsch/pkNX.git
synced 2026-07-19 17:02:18 -05:00
Make GameManager abstract
This commit is contained in:
parent
dec088766c
commit
2e12e326ef
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using pkNX.Containers;
|
||||
using pkNX.Structures;
|
||||
|
||||
|
|
@ -8,16 +7,13 @@ namespace pkNX.Game
|
|||
/// <summary>
|
||||
/// Manages fetching of game data.
|
||||
/// </summary>
|
||||
public sealed class GameManager
|
||||
public abstract class GameManager
|
||||
{
|
||||
private readonly GameLocation ROM;
|
||||
private readonly TextManager Text; // GameText
|
||||
private readonly GameFileMapping FileMap;
|
||||
public readonly GameInfo Info;
|
||||
|
||||
public string ROMPath => ROM.RomFS;
|
||||
public string EXEPath => ROM.ExeFS;
|
||||
|
||||
/// <summary>
|
||||
/// Language to use when fetching string & graphic assets.
|
||||
/// </summary>
|
||||
|
|
@ -31,14 +27,14 @@ public sealed class GameManager
|
|||
/// <summary>
|
||||
/// Generally useful game data that can be used by multiple editors.
|
||||
/// </summary>
|
||||
public GameData Data { get; private set; }
|
||||
public GameData Data { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="GameManager"/> for the input <see cref="GameLocation"/> with initial <see cref="Language"/>.
|
||||
/// </summary>
|
||||
/// <param name="rom"></param>
|
||||
/// <param name="language"></param>
|
||||
public GameManager(GameLocation rom, int language)
|
||||
protected GameManager(GameLocation rom, int language)
|
||||
{
|
||||
ROM = rom;
|
||||
Language = language;
|
||||
|
|
@ -86,45 +82,7 @@ public void SaveAll(bool closing)
|
|||
Initialize();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
if (ROM.Game == GameVersion.GG)
|
||||
InitializeDataGG();
|
||||
}
|
||||
|
||||
private void InitializeDataGG()
|
||||
{
|
||||
// initialize gametext
|
||||
GetFilteredFolder(GameFile.GameText, z => Path.GetExtension(z) == ".dat");
|
||||
|
||||
// initialize common structures
|
||||
Data = new GameData
|
||||
{
|
||||
MoveData = new DataCache<Move>(this[GameFile.MoveStats]) // mini
|
||||
{
|
||||
Create = z => new Move7(z),
|
||||
Write = z => z.Write(),
|
||||
},
|
||||
LevelUpData = new DataCache<Learnset>(this[GameFile.Learnsets]) // gfpak
|
||||
{
|
||||
Create = z => new Learnset6(z),
|
||||
Write = z => z.Write(),
|
||||
},
|
||||
|
||||
// folders
|
||||
PersonalData = new PersonalTable(GetFilteredFolder(GameFile.PersonalStats, z => Path.GetFileNameWithoutExtension(z) == "personal_total").GetFiles().Result[0], Game),
|
||||
MegaEvolutionData = new DataCache<MegaEvolutionSet[]>(GetFilteredFolder(GameFile.MegaEvolutions))
|
||||
{
|
||||
Create = MegaEvolutionSet.ReadArray,
|
||||
Write = MegaEvolutionSet.WriteArray,
|
||||
},
|
||||
EvolutionData = new DataCache<EvolutionSet>(GetFilteredFolder(GameFile.Evolutions))
|
||||
{
|
||||
Create = (data) => new EvolutionSet7(data),
|
||||
Write = evo => evo.Write(),
|
||||
},
|
||||
};
|
||||
}
|
||||
protected abstract void Initialize();
|
||||
|
||||
public FolderContainer GetFilteredFolder(GameFile type, Func<string, bool> filter = null)
|
||||
{
|
||||
|
|
@ -132,5 +90,16 @@ public FolderContainer GetFilteredFolder(GameFile type, Func<string, bool> filte
|
|||
c.Initialize(filter);
|
||||
return c;
|
||||
}
|
||||
|
||||
public static GameManager GetManager(GameLocation loc, int language)
|
||||
{
|
||||
switch (loc.Game)
|
||||
{
|
||||
case GameVersion.GG:
|
||||
return new GameManagerGG(loc, language);
|
||||
default:
|
||||
throw new ArgumentException(nameof(loc.Game));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
47
pkNX.Game/GameManagerGG.cs
Normal file
47
pkNX.Game/GameManagerGG.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System.IO;
|
||||
using pkNX.Structures;
|
||||
|
||||
namespace pkNX.Game
|
||||
{
|
||||
public class GameManagerGG : GameManager
|
||||
{
|
||||
public GameManagerGG(GameLocation rom, int language) : base(rom, language) { }
|
||||
|
||||
private const string Pikachu = "010003F003A34000";
|
||||
private const string Eevee = "0100187003A36000";
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
// initialize gametext
|
||||
GetFilteredFolder(GameFile.GameText, z => Path.GetExtension(z) == ".dat");
|
||||
|
||||
// initialize common structures
|
||||
Data = new GameData
|
||||
{
|
||||
MoveData = new DataCache<Move>(this[GameFile.MoveStats]) // mini
|
||||
{
|
||||
Create = z => new Move7(z),
|
||||
Write = z => z.Write(),
|
||||
},
|
||||
LevelUpData = new DataCache<Learnset>(this[GameFile.Learnsets]) // gfpak
|
||||
{
|
||||
Create = z => new Learnset6(z),
|
||||
Write = z => z.Write(),
|
||||
},
|
||||
|
||||
// folders
|
||||
PersonalData = new PersonalTable(GetFilteredFolder(GameFile.PersonalStats, z => Path.GetFileNameWithoutExtension(z) == "personal_total").GetFiles().Result[0], Game),
|
||||
MegaEvolutionData = new DataCache<MegaEvolutionSet[]>(GetFilteredFolder(GameFile.MegaEvolutions))
|
||||
{
|
||||
Create = MegaEvolutionSet.ReadArray,
|
||||
Write = MegaEvolutionSet.WriteArray,
|
||||
},
|
||||
EvolutionData = new DataCache<EvolutionSet>(GetFilteredFolder(GameFile.Evolutions))
|
||||
{
|
||||
Create = (data) => new EvolutionSet7(data),
|
||||
Write = evo => evo.Write(),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ private static EditorBase GetEditor(GameManager ROM)
|
|||
public static EditorBase GetEditor(string loc, int language)
|
||||
{
|
||||
var gl = GameLocation.GetGame(loc);
|
||||
var gm = new GameManager(gl, language);
|
||||
GameManager gm = GameManager.GetManager(gl, language);
|
||||
EditorBase editor = GetEditor(gm);
|
||||
editor.Location = loc;
|
||||
return editor;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user