Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TRR gamestring support #699

Merged
merged 8 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
- added separate secret audio for TR1 and TR3 when not using reward rooms (#687)
- added an option to shuffle items rather than randomize their types and locations in each level (#625)
- added an option to control weapon allocation in item randomization (#690)
- added Finnish, Portuguese, and Swedish translations to TR1 and added all supported language translations to TRUB (#701)
- fixed several potential key item softlocks in TR2 (#691)
- fixed a key item softlock in Crash Site (#662)
- fixed incorrect item and mesh positions in Home Sweet Home when mirrored (#676)
- fixed uncontrolled SFX in gym/assault course levels not being linked to the correct setting (#684)
- fixed the scion being difficult to shoot if Lara only has the shotgun (#696)
- fixed character encoding in TR3 gamestrings, which was causing data loss in some cases (#698)
- improved the layout of some options in the UI (#694)

## [V1.8.4](https://github.com/LostArtefacts/TR-Rando/compare/V1.8.3...V1.8.4) - 2024-02-12
Expand Down
Binary file modified Deps/TRGE.Coord.dll
Binary file not shown.
Binary file modified Deps/TRGE.Core.dll
Binary file not shown.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ For keeping track of levels while you play, check out the [TRRandoTracker](https
* Lilly Jericho - For endless testing to fix issues such as the opera house/barkhang entity freeze, mirrored levels, and providing great continuous feedback. Lilly was also a coordinator of the huge translation effort by the community, with a special thanks to the following translators:
* Croatian - Erackk
* Czech - Sabatu
* Dutch - BeardedBogle, Dokus, & LordMeShine
* Finnish - Riku
* French - Hedteur & LeonHeart
* Dutch - BeardedBogle, Dokus, LordMeShine, & Dutchyraider
* Finnish - Riku, mawia, & Footi
* French - Hedteur, LeonHeart, & Towandaa
* German - Lilly Jericho & Radgryd
* Italian - Diego & Nanaki
* Italian - Diego, Nanaki, & Warpy
* Japanese - ChiburuTV
* Polish - DJ_Full & NaBu
* Polish - DJ_Full, NaBu, & Nickelony
* Portuguese - Fuse & Jumica
* Russian - Fetch
* Swedish - Pikkufighter & Woof Smit
* Russian - Ayiluy
* Swedish - Pikkufighter, Woof Smit, & Zahnac
19 changes: 19 additions & 0 deletions TRRandomizerCore/Editors/TR1RemasteredEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ protected override int GetSaveTarget(int numLevels)
{
int target = 0;

if (Settings.RandomizeGameStrings)
{
target++;
}

if (Settings.RandomizeSecrets)
{
target += numLevels * 3;
Expand Down Expand Up @@ -104,6 +109,20 @@ protected override void SaveImpl(AbstractTRScriptEditor scriptEditor, TRSaveMoni
Settings = Settings,
};

if (!monitor.IsCancelled && Settings.RandomizeGameStrings)
{
monitor.FireSaveStateBeginning(TRSaveCategory.Custom, "Randomizing text");
new TR1RGameStringRandomizer
{
ScriptEditor = scriptEditor,
Levels = levels,
BasePath = wipDirectory,
BackupPath = backupDirectory,
SaveMonitor = monitor,
Settings = Settings
}.Randomize(Settings.GameStringsSeed);
}

if (!monitor.IsCancelled && Settings.RandomizeSecrets)
{
monitor.FireSaveStateBeginning(TRSaveCategory.Custom, "Randomizing secrets");
Expand Down
19 changes: 19 additions & 0 deletions TRRandomizerCore/Editors/TR2RemasteredEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ protected override int GetSaveTarget(int numLevels)
{
int target = 0;

if (Settings.RandomizeGameStrings)
{
target++;
}

if (Settings.RandomizeSecrets)
{
target += numLevels;
Expand Down Expand Up @@ -100,6 +105,20 @@ protected override void SaveImpl(AbstractTRScriptEditor scriptEditor, TRSaveMoni
Settings = Settings,
};

if (!monitor.IsCancelled && Settings.RandomizeGameStrings)
{
monitor.FireSaveStateBeginning(TRSaveCategory.Custom, "Randomizing text");
new TR2RGameStringRandomizer
{
ScriptEditor = scriptEditor,
Levels = levels,
BasePath = wipDirectory,
BackupPath = backupDirectory,
SaveMonitor = monitor,
Settings = Settings
}.Randomize(Settings.GameStringsSeed);
}

if (!monitor.IsCancelled && Settings.RandomizeSecrets)
{
monitor.FireSaveStateBeginning(TRSaveCategory.Custom, "Randomizing secrets");
Expand Down
19 changes: 19 additions & 0 deletions TRRandomizerCore/Editors/TR3RemasteredEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ protected override int GetSaveTarget(int numLevels)
{
int target = 0;

if (Settings.RandomizeGameStrings)
{
target++;
}

if (Settings.RandomizeSecrets)
{
target += numLevels * 3;
Expand Down Expand Up @@ -108,6 +113,20 @@ protected override void SaveImpl(AbstractTRScriptEditor scriptEditor, TRSaveMoni
Settings = Settings,
};

if (!monitor.IsCancelled && Settings.RandomizeGameStrings)
{
monitor.FireSaveStateBeginning(TRSaveCategory.Custom, "Randomizing text");
new TR3RGameStringRandomizer
{
ScriptEditor = scriptEditor,
Levels = levels,
BasePath = wipDirectory,
BackupPath = backupDirectory,
SaveMonitor = monitor,
Settings = Settings
}.Randomize(Settings.GameStringsSeed);
}

if (!monitor.IsCancelled && Settings.RandomizeSecrets)
{
monitor.FireSaveStateBeginning(TRSaveCategory.Custom, "Randomizing secrets");
Expand Down
67 changes: 21 additions & 46 deletions TRRandomizerCore/Globalisation/G11N.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.Text;
using TRLevelControl.Model;

namespace TRRandomizerCore.Globalisation;

Expand All @@ -13,21 +14,21 @@ static G11N()
@"Resources\Shared\G11N\languages.json"));
}

private readonly G11NGame _game;
private readonly SortedDictionary<Language, IGameStrings> _languageMap;
private readonly TRGameVersion _game;
private readonly SortedDictionary<Language, TRGameStrings> _languageMap;
private readonly SortedSet<Language> _realLanguages;

public Language[] RealLanguages => _realLanguages.ToArray();
public List<Language> RealLanguages => _realLanguages.ToList();

public G11N(G11NGame game)
public G11N(TRGameVersion game)
{
_game = game;
_languageMap = new SortedDictionary<Language, IGameStrings>();
_realLanguages = new SortedSet<Language>();
_languageMap = new();
_realLanguages = new();

foreach (Language language in _definedLanguages)
{
IGameStrings strings;
TRGameStrings strings;
if (!language.IsHybrid && (strings = LoadLanguage(language, _game)) != null)
{
_languageMap[language] = strings;
Expand All @@ -36,57 +37,31 @@ public G11N(G11NGame game)
}
}

public static List<Language> GetSupportedLanguages(G11NGame game) =>
_definedLanguages.Where(l => l.IsHybrid || LoadLanguage(l, game) != null).ToList();
public static List<Language> GetSupportedLanguages(TRGameVersion game)
=> _definedLanguages.Where(l => l.IsHybrid || LoadLanguage(l, game) != null).ToList();

public static Language GetLanguage(string tag)
{
tag = tag.ToUpper();
return _definedLanguages.Find(l => l.Tag.ToUpper().Equals(tag));
}
=> _definedLanguages.Find(l => string.Equals(l.Tag, tag, StringComparison.InvariantCultureIgnoreCase));

public IGameStrings GetDefaultGameStrings()
{
return GetGameStrings(GetLanguage(Language.DefaultTag));
}
public TRGameStrings GetDefaultGameStrings()
=> GetGameStrings(Language.DefaultTag);

public IGameStrings GetGameStrings(string tag)
{
return GetGameStrings(GetLanguage(tag));
}
public TRGameStrings GetGameStrings(string tag)
=> GetGameStrings(GetLanguage(tag));

public IGameStrings GetGameStrings(Language language)
{
if (!_languageMap.ContainsKey(language))
{
throw new KeyNotFoundException(string.Format("There is no language defined for {0} ({1})).", language.Name, language.Tag));
}

return _languageMap[language];
}
public TRGameStrings GetGameStrings(Language language)
=> _languageMap.ContainsKey(language)
? _languageMap[language]
: throw new KeyNotFoundException($"There is no language defined for {language.Name} ({language.Tag}).");

private static IGameStrings LoadLanguage(Language language, G11NGame game)
private static TRGameStrings LoadLanguage(Language language, TRGameVersion game)
{
string path = $@"Resources\{game}\Strings\G11N\gamestrings_{language.Tag}.json";
if (!File.Exists(path))
{
return null;
}

string data = File.ReadAllText(path, Encoding.UTF8);
return game switch
{
G11NGame.TR1 => JsonConvert.DeserializeObject<TR1GameStrings>(data),
G11NGame.TR2
or G11NGame.TR3 => JsonConvert.DeserializeObject<TR23GameStrings>(data),
_ => null,
};
return JsonConvert.DeserializeObject<TRGameStrings>(File.ReadAllText(path, Encoding.UTF8));
}
}

public enum G11NGame
{
TR1,
TR2,
TR3
}
6 changes: 0 additions & 6 deletions TRRandomizerCore/Globalisation/IGameStrings.cs

This file was deleted.

7 changes: 0 additions & 7 deletions TRRandomizerCore/Globalisation/TR1LevelStrings.cs

This file was deleted.

98 changes: 0 additions & 98 deletions TRRandomizerCore/Globalisation/TR23GameStrings.cs

This file was deleted.

9 changes: 0 additions & 9 deletions TRRandomizerCore/Globalisation/TR23LevelStrings.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace TRRandomizerCore.Globalisation;

public class TR1GameStrings : IGameStrings
public class TRGameStrings
{
public Dictionary<string, List<string>> GlobalStrings { get; set; }
public Dictionary<string, TR1LevelStrings> LevelStrings { get; set; }
public Dictionary<TRStringKey, List<string>> GlobalStrings { get; set; }
public Dictionary<string, TRLevelStrings> LevelStrings { get; set; }

public string Encode(string text)
public static string Encode(string text)
{
// Uppercase accented characters will be normalised in all cases.
// Some lowercase accented characters are supported.
Expand Down
15 changes: 15 additions & 0 deletions TRRandomizerCore/Globalisation/TRKeyItemKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace TRRandomizerCore.Globalisation;

public enum TRKeyItemKey
{
Key1,
Key2,
Key3,
Key4,
Puzzle1,
Puzzle2,
Puzzle3,
Puzzle4,
Pickup1,
Pickup2,
}
Loading
Loading