Added support for charset

This commit is contained in:
Michał Mrówka 2020-11-16 21:39:48 +01:00
parent 9ab89a59d4
commit bbba67487d
No known key found for this signature in database
GPG Key ID: EAD1B438A5B55C21
4 changed files with 41 additions and 4 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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]
}

View File

@ -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 ---