forked from LostArtefacts/TR-Rando
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TRR secret support (LostArtefacts#681)
Part of LostArtefacts#614.
- Loading branch information
Showing
32 changed files
with
1,835 additions
and
799 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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,67 @@ | ||
using TRLevelControl; | ||
using TRLevelControl.Model; | ||
|
||
namespace TRDataControl; | ||
|
||
public abstract class BaseTRRDataCache<TKey, TAlias> | ||
where TKey : Enum | ||
where TAlias : Enum | ||
{ | ||
private const string _pdpExt = ".PDP"; | ||
|
||
private readonly Dictionary<TKey, TRModel> _pdpCache = new(); | ||
|
||
public string PDPFolder { get; set; } | ||
|
||
public void SetData(TRDictionary<TKey, TRModel> pdpData, Dictionary<TKey, TAlias> mapData, TKey sourceType, TKey destinationType = default) | ||
{ | ||
if (EqualityComparer<TKey>.Default.Equals(destinationType, default)) | ||
{ | ||
destinationType = sourceType; | ||
} | ||
|
||
SetPDPData(pdpData, sourceType, destinationType); | ||
SetMapData(mapData, sourceType, destinationType); | ||
} | ||
|
||
public void SetPDPData(TRDictionary<TKey, TRModel> pdpData, TKey sourceType, TKey destinationType) | ||
{ | ||
TKey translatedKey = TranslateKey(sourceType); | ||
if (!_pdpCache.ContainsKey(sourceType)) | ||
{ | ||
string sourceLevel = GetSourceLevel(sourceType) | ||
?? throw new KeyNotFoundException($"Source PDP file for {sourceType} is undefined"); | ||
|
||
TRPDPControlBase<TKey> control = GetPDPControl(); | ||
TRDictionary<TKey, TRModel> models = control.Read(Path.Combine(PDPFolder, Path.GetFileNameWithoutExtension(sourceLevel) + _pdpExt)); | ||
if (models.ContainsKey(translatedKey)) | ||
{ | ||
_pdpCache[sourceType] = models[translatedKey]; | ||
} | ||
else | ||
{ | ||
throw new KeyNotFoundException($"Could not load cached PDP data for {sourceType}"); | ||
} | ||
} | ||
|
||
translatedKey = TranslateKey(destinationType); | ||
pdpData[translatedKey] = _pdpCache[sourceType]; | ||
} | ||
|
||
public void SetMapData(Dictionary<TKey, TAlias> mapData, TKey sourceType, TKey destinationType) | ||
{ | ||
TAlias alias = GetAlias(sourceType); | ||
if (EqualityComparer<TAlias>.Default.Equals(alias, default)) | ||
{ | ||
return; | ||
} | ||
|
||
TKey translatedKey = TranslateKey(destinationType); | ||
mapData[translatedKey] = alias; | ||
} | ||
|
||
protected abstract TRPDPControlBase<TKey> GetPDPControl(); | ||
public abstract string GetSourceLevel(TKey key); | ||
public abstract TKey TranslateKey(TKey key); | ||
public abstract TAlias GetAlias(TKey key); | ||
} |
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,49 @@ | ||
using TRLevelControl; | ||
using TRLevelControl.Helpers; | ||
using TRLevelControl.Model; | ||
|
||
namespace TRDataControl; | ||
|
||
public class TR1RDataCache : BaseTRRDataCache<TR1Type, TR1RAlias> | ||
{ | ||
private TR1PDPControl _control; | ||
private TR1DataProvider _dataProvider; | ||
|
||
protected override TRPDPControlBase<TR1Type> GetPDPControl() | ||
=> _control ??= new(); | ||
|
||
public override TR1Type TranslateKey(TR1Type key) | ||
=> TR1TypeUtilities.TranslateSourceType(key); | ||
|
||
public override string GetSourceLevel(TR1Type key) | ||
{ | ||
_dataProvider ??= new(); | ||
TR1Type translatedType = _dataProvider.TranslateAlias(key); | ||
return _sourceLevels.ContainsKey(translatedType) ? _sourceLevels[translatedType] : null; | ||
} | ||
|
||
public override TR1RAlias GetAlias(TR1Type key) | ||
{ | ||
_dataProvider ??= new(); | ||
TR1Type translatedType = _dataProvider.TranslateAlias(key); | ||
return _mapAliases.ContainsKey(translatedType) ? _mapAliases[translatedType] : default; | ||
} | ||
|
||
private static readonly Dictionary<TR1Type, string> _sourceLevels = new() | ||
{ | ||
[TR1Type.SecretAnkh_M_H] = TR1LevelNames.OBELISK, | ||
[TR1Type.SecretGoldBar_M_H] = TR1LevelNames.MIDAS, | ||
[TR1Type.SecretGoldIdol_M_H] = TR1LevelNames.VILCABAMBA, | ||
[TR1Type.SecretLeadBar_M_H] = TR1LevelNames.MIDAS, | ||
[TR1Type.SecretScion_M_H] = TR1LevelNames.QUALOPEC, | ||
}; | ||
|
||
private static readonly Dictionary<TR1Type, TR1RAlias> _mapAliases = new() | ||
{ | ||
[TR1Type.SecretAnkh_M_H] = TR1RAlias.PUZZLE_OPTION4_8A_8B, | ||
[TR1Type.SecretGoldBar_M_H] = TR1RAlias.PUZZLE_OPTION1_6, | ||
[TR1Type.SecretGoldIdol_M_H] = TR1RAlias.PUZZLE_OPTION1_2, | ||
[TR1Type.SecretLeadBar_M_H] = TR1RAlias.LEADBAR_OPTION, | ||
[TR1Type.SecretScion_M_H] = TR1RAlias.SCION_OPTION, | ||
}; | ||
} |
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,70 @@ | ||
using TRLevelControl; | ||
using TRLevelControl.Helpers; | ||
using TRLevelControl.Model; | ||
|
||
namespace TRDataControl; | ||
|
||
public class TR3RDataCache : BaseTRRDataCache<TR3Type, TR3RAlias> | ||
{ | ||
private TR3PDPControl _control; | ||
private TR3DataProvider _dataProvider; | ||
|
||
protected override TRPDPControlBase<TR3Type> GetPDPControl() | ||
=> _control ??= new(); | ||
|
||
public override TR3Type TranslateKey(TR3Type key) | ||
{ | ||
return key switch | ||
{ | ||
TR3Type.Quest1_P or TR3Type.Quest2_P => TR3Type.Puzzle1_P, | ||
TR3Type.Quest1_M_H or TR3Type.Quest2_M_H => TR3Type.Puzzle1_M_H, | ||
_ => key, | ||
}; | ||
} | ||
|
||
public override string GetSourceLevel(TR3Type key) | ||
{ | ||
_dataProvider ??= new(); | ||
TR3Type translatedType = _dataProvider.TranslateAlias(key); | ||
return _sourceLevels.ContainsKey(translatedType) ? _sourceLevels[translatedType] : null; | ||
} | ||
|
||
public override TR3RAlias GetAlias(TR3Type key) | ||
{ | ||
_dataProvider ??= new(); | ||
TR3Type translatedType = _dataProvider.TranslateAlias(key); | ||
return _mapAliases.ContainsKey(translatedType) ? _mapAliases[translatedType] : default; | ||
} | ||
|
||
private static readonly Dictionary<TR3Type, string> _sourceLevels = new() | ||
{ | ||
[TR3Type.Infada_P] = TR3LevelNames.CAVES, | ||
[TR3Type.Infada_M_H] = TR3LevelNames.CAVES, | ||
[TR3Type.OraDagger_P] = TR3LevelNames.PUNA, | ||
[TR3Type.OraDagger_M_H] = TR3LevelNames.PUNA, | ||
[TR3Type.EyeOfIsis_P] = TR3LevelNames.CITY, | ||
[TR3Type.EyeOfIsis_M_H] = TR3LevelNames.CITY, | ||
[TR3Type.Element115_P] = TR3LevelNames.AREA51, | ||
[TR3Type.Element115_M_H] = TR3LevelNames.AREA51, | ||
[TR3Type.Quest1_P] = TR3LevelNames.COASTAL, | ||
[TR3Type.Quest1_M_H] = TR3LevelNames.COASTAL, | ||
[TR3Type.Quest2_P] = TR3LevelNames.MADHOUSE, | ||
[TR3Type.Quest2_M_H] = TR3LevelNames.MADHOUSE, | ||
}; | ||
|
||
private static readonly Dictionary<TR3Type, TR3RAlias> _mapAliases = new() | ||
{ | ||
[TR3Type.Infada_P] = TR3RAlias.ICON_PICKUP1_ITEM, | ||
[TR3Type.Infada_M_H] = TR3RAlias.ICON_PICKUP1_OPTION, | ||
[TR3Type.OraDagger_P] = TR3RAlias.ICON_PICKUP4_ITEM, | ||
[TR3Type.OraDagger_M_H] = TR3RAlias.ICON_PICKUP4_OPTION, | ||
[TR3Type.EyeOfIsis_P] = TR3RAlias.ICON_PICKUP3_ITEM, | ||
[TR3Type.EyeOfIsis_M_H] = TR3RAlias.ICON_PICKUP3_OPTION, | ||
[TR3Type.Element115_P] = TR3RAlias.ICON_PICKUP2_ITEM, | ||
[TR3Type.Element115_M_H] = TR3RAlias.ICON_PICKUP2_OPTION, | ||
[TR3Type.Quest1_P] = TR3RAlias.PUZZLE_ITEM1_SHORE, | ||
[TR3Type.Quest1_M_H] = TR3RAlias.PUZZLE_OPTION1_SHORE, | ||
[TR3Type.Quest2_P] = TR3RAlias.PUZZLE_ITEM1_HAND, | ||
[TR3Type.Quest2_M_H] = TR3RAlias.PUZZLE_OPTION1_HAND, | ||
}; | ||
} |
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
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
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
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
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
Oops, something went wrong.