From bbba67487d576368066871c9b39f58d4aef29802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mro=CC=81wka?= Date: Mon, 16 Nov 2020 21:39:48 +0100 Subject: [PATCH] Added support for charset --- d2app/app.go | 4 ++++ d2common/d2loader/loader.go | 14 +++++++++++--- d2common/d2resource/languages_map.go | 25 +++++++++++++++++++++++++ d2common/d2resource/resource_paths.go | 2 +- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/d2app/app.go b/d2app/app.go index 3548d506..e1c16d94 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -67,6 +67,7 @@ type App struct { gitBranch string gitCommit string language string + charset string asset *d2asset.AssetManager inputManager d2interface.InputManager terminal d2interface.Terminal @@ -460,6 +461,9 @@ func (a *App) initConfig(config *d2config.Configuration) error { func (a *App) initLanguage() { a.language = a.asset.LoadLanguage(d2resource.LocalLanguage) a.asset.Loader.SetLanguage(&a.language) + + a.charset = d2resource.GetFontCharset(a.language) + a.asset.Loader.SetCharset(&a.charset) } func (a *App) initDataDictionaries() error { diff --git a/d2common/d2loader/loader.go b/d2common/d2loader/loader.go index c9a7ba3d..f3f6ae66 100644 --- a/d2common/d2loader/loader.go +++ b/d2common/d2loader/loader.go @@ -48,6 +48,7 @@ func NewLoader(l d2util.LogLevel) (*Loader, error) { // that have been added type Loader struct { language *string + charset *string d2interface.Cache *d2util.Logger Sources []asset.Source @@ -58,15 +59,22 @@ func (l *Loader) SetLanguage(language *string) { l.language = language } +// SetCharset sets the charset for loader +func (l *Loader) SetCharset(charset *string) { + l.charset = charset +} + // Load attempts to load an asset with the given sub-path. The sub-path is relative to the root // of each asset source root (regardless of the type of asset source) func (l *Loader) Load(subPath string) (asset.Asset, error) { subPath = filepath.Clean(subPath) if l.language != nil { - lang := l.language - subPath = strings.ReplaceAll(subPath, fontToken, "latin") - subPath = strings.ReplaceAll(subPath, tableToken, *lang) + charset := l.charset + language := l.language + + subPath = strings.ReplaceAll(subPath, fontToken, *charset) + subPath = strings.ReplaceAll(subPath, tableToken, *language) } // first, we check the cache for an existing entry diff --git a/d2common/d2resource/languages_map.go b/d2common/d2resource/languages_map.go index d5aadb0c..af6a012f 100644 --- a/d2common/d2resource/languages_map.go +++ b/d2common/d2resource/languages_map.go @@ -24,3 +24,28 @@ func GetLanguageLiteral(code byte) string { return languages[code] } + +// Source https://github.com/eezstreet/OpenD2/blob/065f6e466048482b28b9dbc6286908dc1e0d10f6/Shared/D2Shared.hpp#L36 +func getCharsets() map[string]string { + return map[string]string{ + "ENG": "LATIN", // (English) + "ESP": "LATIN", // (Spanish) + "DEU": "LATIN", // (German) + "FRA": "LATIN", // (French) + "POR": "LATIN", // (Portuguese) + "ITA": "LATIN", // (Italian) + "JPN": "JAPAN", // (Japanese) + "KOR": "KOREAN", // (Korean) + "SIN": "LATIN", // + "CHI": "CHINESE", // (Chinese) + "POL": "LATIN2", // (Polish) + "RUS": "RUSSIAN", // (Russian) + } +} + +// GetFontCharset returns string representation of font charset +func GetFontCharset(language string) string { + charset := getCharsets() + + return charset[language] +} diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index 01edb034..d052a3e0 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -35,7 +35,7 @@ const ( // --- Credits --- CreditsBackground = "/data/global/ui/CharSelect/creditsbckgexpand.dc6" - CreditsText = "/data/local/ui/{LANG}/ExpansionCredits.txt" + CreditsText = "/data/local/ui/" + LanguageTableToken + "/ExpansionCredits.txt" // --- Cinematics ---