mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-25 18:57:23 -05:00
Remove language option from config file
This commit is contained in:
parent
12821147ce
commit
5d5e10f229
@ -66,6 +66,7 @@ type App struct {
|
|||||||
captureFrames []*image.RGBA
|
captureFrames []*image.RGBA
|
||||||
gitBranch string
|
gitBranch string
|
||||||
gitCommit string
|
gitCommit string
|
||||||
|
language string
|
||||||
asset *d2asset.AssetManager
|
asset *d2asset.AssetManager
|
||||||
inputManager d2interface.InputManager
|
inputManager d2interface.InputManager
|
||||||
terminal d2interface.Terminal
|
terminal d2interface.Terminal
|
||||||
@ -373,6 +374,8 @@ func (a *App) initialize() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.initLanguage()
|
||||||
|
|
||||||
if err := a.initDataDictionaries(); err != nil {
|
if err := a.initDataDictionaries(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -454,6 +457,11 @@ func (a *App) initConfig(config *d2config.Configuration) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) initLanguage() {
|
||||||
|
a.language = a.asset.LoadLanguage(d2resource.LocalLanguage)
|
||||||
|
a.asset.Loader.SetLanguage(&a.language)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) initDataDictionaries() error {
|
func (a *App) initDataDictionaries() error {
|
||||||
dictPaths := []string{
|
dictPaths := []string{
|
||||||
d2resource.LevelType, d2resource.LevelPreset, d2resource.LevelWarp,
|
d2resource.LevelType, d2resource.LevelPreset, d2resource.LevelWarp,
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2loader/mpq"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2loader/mpq"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -24,8 +23,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultLanguage = "ENG"
|
logPrefix = "File Loader"
|
||||||
logPrefix = "File Loader"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -49,24 +47,27 @@ func NewLoader(l d2util.LogLevel) (*Loader, error) {
|
|||||||
// Loader represents the manager that handles loading and caching assets with the asset Sources
|
// Loader represents the manager that handles loading and caching assets with the asset Sources
|
||||||
// that have been added
|
// that have been added
|
||||||
type Loader struct {
|
type Loader struct {
|
||||||
config *d2config.Configuration
|
language *string
|
||||||
d2interface.Cache
|
d2interface.Cache
|
||||||
*d2util.Logger
|
*d2util.Logger
|
||||||
Sources []asset.Source
|
Sources []asset.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLanguage sets the language for loader
|
||||||
|
func (l *Loader) SetLanguage(language *string) {
|
||||||
|
l.language = language
|
||||||
|
}
|
||||||
|
|
||||||
// Load attempts to load an asset with the given sub-path. The sub-path is relative to the root
|
// 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)
|
// of each asset source root (regardless of the type of asset source)
|
||||||
func (l *Loader) Load(subPath string) (asset.Asset, error) {
|
func (l *Loader) Load(subPath string) (asset.Asset, error) {
|
||||||
lang := defaultLanguage
|
|
||||||
|
|
||||||
if l.config != nil {
|
|
||||||
lang = l.config.Language
|
|
||||||
}
|
|
||||||
|
|
||||||
subPath = filepath.Clean(subPath)
|
subPath = filepath.Clean(subPath)
|
||||||
subPath = strings.ReplaceAll(subPath, fontToken, "latin")
|
|
||||||
subPath = strings.ReplaceAll(subPath, tableToken, lang)
|
if l.language != nil {
|
||||||
|
lang := l.language
|
||||||
|
subPath = strings.ReplaceAll(subPath, fontToken, "latin")
|
||||||
|
subPath = strings.ReplaceAll(subPath, tableToken, *lang)
|
||||||
|
}
|
||||||
|
|
||||||
// first, we check the cache for an existing entry
|
// first, we check the cache for an existing entry
|
||||||
if cached, found := l.Retrieve(subPath); found {
|
if cached, found := l.Retrieve(subPath); found {
|
||||||
|
26
d2common/d2resource/languages_map.go
Normal file
26
d2common/d2resource/languages_map.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package d2resource
|
||||||
|
|
||||||
|
func getLanguages() map[byte]string {
|
||||||
|
return map[byte]string{
|
||||||
|
0x00: "ENG", // (English)
|
||||||
|
0x01: "ESP", // (Spanish)
|
||||||
|
0x02: "DEU", // (German)
|
||||||
|
0x03: "FRA", // (French)
|
||||||
|
0x04: "POR", // (Portuguese)
|
||||||
|
0x05: "ITA", // (Italian)
|
||||||
|
0x06: "JPN", // (Japanese)
|
||||||
|
0x07: "KOR", // (Korean)
|
||||||
|
0x08: "SIN", //
|
||||||
|
0x09: "CHI", // (Chinese)
|
||||||
|
0x0A: "POL", // (Polish)
|
||||||
|
0x0B: "RUS", // (Russian)
|
||||||
|
0x0C: "ENG", // (English)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLanguageLiteral returns string representation of language code
|
||||||
|
func GetLanguageLiteral(code byte) string {
|
||||||
|
languages := getLanguages()
|
||||||
|
|
||||||
|
return languages[code]
|
||||||
|
}
|
@ -2,19 +2,25 @@ package d2resource
|
|||||||
|
|
||||||
// Paths of the resources inside the mpq files.
|
// Paths of the resources inside the mpq files.
|
||||||
const (
|
const (
|
||||||
|
// --- Language
|
||||||
|
|
||||||
|
LocalLanguage = "/data/local/use"
|
||||||
|
LanguageFontToken = "{LANG_FONT}" //nolint:gosec // this is just a format string
|
||||||
|
LanguageTableToken = "{LANG}"
|
||||||
|
|
||||||
// --- Screens ---
|
// --- Screens ---
|
||||||
|
|
||||||
LoadingScreen = "/data/global/ui/Loading/loadingscreen.dc6"
|
LoadingScreen = "/data/global/ui/Loading/loadingscreen.dc6"
|
||||||
|
|
||||||
// --- Video Paths ---
|
// --- Video Paths ---
|
||||||
|
|
||||||
Act1Intro = "/data/local/video/eng/d2intro640x292.bik"
|
Act1Intro = "/data/local/video/" + LanguageTableToken + "/d2intro640x292.bik"
|
||||||
Act2Intro = "/data/local/video/eng/act02start640x292.bik"
|
Act2Intro = "/data/local/video/" + LanguageTableToken + "/act02start640x292.bik"
|
||||||
Act3Intro = "/data/local/video/eng/act03start640x292.bik"
|
Act3Intro = "/data/local/video/" + LanguageTableToken + "/act03start640x292.bik"
|
||||||
Act4Intro = "/data/local/video/eng/act04start640x292.bik"
|
Act4Intro = "/data/local/video/" + LanguageTableToken + "/act04start640x292.bik"
|
||||||
Act4Outro = "/data/local/video/eng/act04end640x292.bik"
|
Act4Outro = "/data/local/video/" + LanguageTableToken + "/act04end640x292.bik"
|
||||||
Act5Intro = "/data/local/video/eng/d2x_intro_640x292.bik"
|
Act5Intro = "/data/local/video/" + LanguageTableToken + "/d2x_intro_640x292.bik"
|
||||||
Act5Outro = "/data/local/video/eng/d2x_out_640x292.bik"
|
Act5Outro = "/data/local/video/" + LanguageTableToken + "/d2x_out_640x292.bik"
|
||||||
|
|
||||||
// --- Main Menu ---
|
// --- Main Menu ---
|
||||||
|
|
||||||
@ -128,9 +134,6 @@ const (
|
|||||||
CursorDefault = "/data/global/ui/CURSOR/ohand.DC6"
|
CursorDefault = "/data/global/ui/CURSOR/ohand.DC6"
|
||||||
|
|
||||||
// --- Fonts & Locale (strings) ---
|
// --- Fonts & Locale (strings) ---
|
||||||
|
|
||||||
LanguageFontToken = "{LANG_FONT}" //nolint:gosec // this is just a format string
|
|
||||||
LanguageTableToken = "{LANG}"
|
|
||||||
Font6 = "/data/local/FONT/" + LanguageFontToken + "/font6"
|
Font6 = "/data/local/FONT/" + LanguageFontToken + "/font6"
|
||||||
Font8 = "/data/local/FONT/" + LanguageFontToken + "/font8"
|
Font8 = "/data/local/FONT/" + LanguageFontToken + "/font8"
|
||||||
Font16 = "/data/local/FONT/" + LanguageFontToken + "/font16"
|
Font16 = "/data/local/FONT/" + LanguageFontToken + "/font16"
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
||||||
@ -34,6 +35,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
defaultLanguage = "ENG"
|
||||||
logPrefix = "Asset Manager"
|
logPrefix = "Asset Manager"
|
||||||
fmtLoadAsset = "could not load file stream %s (%v)"
|
fmtLoadAsset = "could not load file stream %s (%v)"
|
||||||
fmtLoadAnimation = "loading animation %s with palette %s, draw effect %d"
|
fmtLoadAnimation = "loading animation %s with palette %s, draw effect %d"
|
||||||
@ -108,6 +110,23 @@ func (am *AssetManager) FileExists(filePath string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadLanguage loads language from resource path
|
||||||
|
func (am *AssetManager) LoadLanguage(languagePath string) string {
|
||||||
|
languageByte, err := am.LoadFile(languagePath)
|
||||||
|
if err != nil {
|
||||||
|
am.Debugf("Unable to load language file: %s", err)
|
||||||
|
return defaultLanguage
|
||||||
|
}
|
||||||
|
|
||||||
|
languageCode := languageByte[0]
|
||||||
|
am.Debugf("Language code: %#02x", languageCode)
|
||||||
|
|
||||||
|
language := d2resource.GetLanguageLiteral(languageCode)
|
||||||
|
am.Infof("Language: %s", language)
|
||||||
|
|
||||||
|
return language
|
||||||
|
}
|
||||||
|
|
||||||
// LoadAnimation loads an Animation by its resource path and its palette path
|
// LoadAnimation loads an Animation by its resource path and its palette path
|
||||||
func (am *AssetManager) LoadAnimation(animationPath, palettePath string) (d2interface.Animation, error) {
|
func (am *AssetManager) LoadAnimation(animationPath, palettePath string) (d2interface.Animation, error) {
|
||||||
return am.LoadAnimationWithEffect(animationPath, palettePath, d2enum.DrawEffectNone)
|
return am.LoadAnimationWithEffect(animationPath, palettePath, d2enum.DrawEffectNone)
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
// Configuration defines the configuration for the engine, loaded from config.json
|
// Configuration defines the configuration for the engine, loaded from config.json
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
MpqLoadOrder []string
|
MpqLoadOrder []string
|
||||||
Language string
|
|
||||||
MpqPath string
|
MpqPath string
|
||||||
TicksPerSecond int
|
TicksPerSecond int
|
||||||
FpsCap int
|
FpsCap int
|
||||||
|
@ -16,7 +16,6 @@ func DefaultConfig() *Configuration {
|
|||||||
)
|
)
|
||||||
|
|
||||||
config := &Configuration{
|
config := &Configuration{
|
||||||
Language: "ENG",
|
|
||||||
FullScreen: false,
|
FullScreen: false,
|
||||||
TicksPerSecond: -1,
|
TicksPerSecond: -1,
|
||||||
RunInBackground: true,
|
RunInBackground: true,
|
||||||
|
@ -62,14 +62,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
|
||||||
<td>Language</td>
|
|
||||||
<td>
|
|
||||||
Defines the locale the game is running in. For english this should be set to <code>ENG</code>. Other values include
|
|
||||||
(but are not limited to) <code>CHI</code>, <code>DEU</code>, <code>ESP</code>, <code>FRA</code>, <code>ITA</code>,
|
|
||||||
<code>JPN</code>, etc.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>FullScreen</td>
|
<td>FullScreen</td>
|
||||||
<td>Determines if the client is initially full screen or not. Do note that fullscreen mode can be toggled at any time
|
<td>Determines if the client is initially full screen or not. Do note that fullscreen mode can be toggled at any time
|
||||||
|
Loading…
Reference in New Issue
Block a user