mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-06 00:26:40 -05:00
* make game update at 25fps, ui update at max fps * minor edits to func names, d2resource constants * renamed `loadDictionary` to `loadTextDictionary` to avoid confusion with `LoadDataDictionary` * updated line in main.go that calls `loadTextDictionary` * added tokens as constants inside of `d2resource/resource_paths.go` that are used in font/language paths * moved locale string handling stuff into it's own func, now uses tokens defined in d2resource * minor edits to func names, d2resource constants * renamed `loadDictionary` to `loadTextDictionary` to avoid confusion with `LoadDataDictionary` * updated line in main.go that calls `loadTextDictionary` * added tokens as constants inside of `d2resource/resource_paths.go` that are used in font/language paths * moved locale string handling stuff into it's own func, now uses tokens defined in d2resource * fix: accidentally renamed func in d2asset * git is hard accidentally added changes not meant for this commit
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
package d2asset
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
|
|
)
|
|
|
|
const (
|
|
fileBudget = 1024 * 1024 * 32
|
|
)
|
|
|
|
type fileManager struct {
|
|
cache *d2common.Cache
|
|
archiveManager *archiveManager
|
|
config d2config.Configuration
|
|
}
|
|
|
|
func createFileManager(config d2config.Configuration, archiveManager *archiveManager) *fileManager {
|
|
return &fileManager{d2common.CreateCache(fileBudget), archiveManager, config}
|
|
}
|
|
|
|
func (fm *fileManager) loadFile(filePath string) ([]byte, error) {
|
|
filePath = fm.fixupFilePath(filePath)
|
|
if value, found := fm.cache.Retrieve(filePath); found {
|
|
return value.([]byte), nil
|
|
}
|
|
|
|
archive, err := fm.archiveManager.loadArchiveForFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
data, err := archive.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := fm.cache.Insert(filePath, data, len(data)); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return data, nil
|
|
}
|
|
|
|
func (fm *fileManager) fileExists(filePath string) (bool, error) {
|
|
filePath = fm.fixupFilePath(filePath)
|
|
return fm.archiveManager.fileExistsInArchive(filePath)
|
|
}
|
|
|
|
func (fm *fileManager) fixupFilePath(filePath string) string {
|
|
filePath = fm.removeLocaleTokens(filePath)
|
|
filePath = strings.ToLower(filePath)
|
|
filePath = strings.ReplaceAll(filePath, `/`, "\\")
|
|
filePath = strings.TrimPrefix(filePath, "\\")
|
|
|
|
return filePath
|
|
}
|
|
|
|
func (fm *fileManager) removeLocaleTokens(filePath string) string {
|
|
tableToken := d2resource.LanguageTableToken
|
|
fontToken := d2resource.LanguageFontToken
|
|
|
|
filePath = strings.ReplaceAll(filePath, tableToken, fm.config.Language)
|
|
|
|
// fixme: not all languages==latin
|
|
filePath = strings.ReplaceAll(filePath, fontToken, "latin")
|
|
|
|
return filePath
|
|
}
|