1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-26 03:56:42 -05:00

Moving files around to make more sense (#279)

* Prevent input fighting between terminal and other input listeners.

* Moving files around, removing exports

* Add missing line
This commit is contained in:
Alex Yatskov 2020-02-01 15:55:56 -08:00 committed by GitHub
parent e878ebcbcd
commit 8a547ebf0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 604 additions and 709 deletions

View File

@ -27,7 +27,8 @@ type Cache struct {
func CreateCache(budget int) *Cache {
return &Cache{lookup: make(map[string]*cacheNode), budget: budget}
}
func (c *Cache) SetCacheVerbose(verbose bool) {
func (c *Cache) SetVerbose(verbose bool) {
c.verbose = verbose
}

View File

@ -6,31 +6,6 @@ import (
"runtime"
)
// Configuration defines the configuration for the engine, loaded from config.json
type Configuration struct {
Language string
FullScreen bool
Scale float64
RunInBackground bool
TicksPerSecond int
FpsCap int
VsyncEnabled bool
MpqPath string
MpqLoadOrder []string
SfxVolume float64
BgmVolume float64
}
/*
func getConfigurationPath() string {
configDir, err := os.UserConfigDir()
if err != nil {
return "config.json"
}
return path.Join(configDir, "OpenDiablo2/config.json")
}
*/
func getDefaultConfiguration() *Configuration {
config := &Configuration{
Language: "ENG",

View File

@ -13,6 +13,21 @@ var (
ErrHasInit = errors.New("configuration has already been initialized")
)
// Configuration defines the configuration for the engine, loaded from config.json
type Configuration struct {
Language string
FullScreen bool
Scale float64
RunInBackground bool
TicksPerSecond int
FpsCap int
VsyncEnabled bool
MpqPath string
MpqLoadOrder []string
SfxVolume float64
BgmVolume float64
}
var singleton *Configuration
func Initialize() error {

View File

@ -1,4 +1,4 @@
package d2render
package d2asset
import (
"errors"
@ -6,11 +6,12 @@ import (
"math"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
type playMode int
@ -49,7 +50,7 @@ type Animation struct {
playLoop bool
}
func CreateAnimationFromDCC(dcc *d2dcc.DCC, palette *d2datadict.PaletteRec, transparency int) (*Animation, error) {
func createAnimationFromDCC(dcc *d2dcc.DCC, palette *d2datadict.PaletteRec, transparency int) (*Animation, error) {
animation := &Animation{
playLength: 1.0,
playLoop: true,
@ -83,7 +84,7 @@ func CreateAnimationFromDCC(dcc *d2dcc.DCC, palette *d2datadict.PaletteRec, tran
}
}
err, image := NewSurface(frameWidth, frameHeight, d2common.FilterNearest)
err, image := d2render.NewSurface(frameWidth, frameHeight, d2common.FilterNearest)
if err != nil {
return nil, err
}
@ -111,14 +112,14 @@ func CreateAnimationFromDCC(dcc *d2dcc.DCC, palette *d2datadict.PaletteRec, tran
return animation, nil
}
func CreateAnimationFromDC6(dc6 *d2dc6.DC6File) (*Animation, error) {
func createAnimationFromDC6(dc6 *d2dc6.DC6File) (*Animation, error) {
animation := &Animation{
playLength: 1.0,
playLoop: true,
}
for frameIndex, dc6Frame := range dc6.Frames {
err, image := NewSurface(int(dc6Frame.Width), int(dc6Frame.Height), d2common.FilterNearest)
err, image := d2render.NewSurface(int(dc6Frame.Width), int(dc6Frame.Height), d2common.FilterNearest)
if err != nil {
return nil, err
}

View File

@ -0,0 +1,67 @@
package d2asset
import (
"errors"
"fmt"
"path/filepath"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
const (
animationBudget = 64
)
type animationManager struct {
cache *d2common.Cache
}
func createAnimationManager() *animationManager {
return &animationManager{d2common.CreateCache(animationBudget)}
}
func (am *animationManager) loadAnimation(animationPath, palettePath string, transparency int) (*Animation, error) {
cachePath := fmt.Sprintf("%s;%s;%d", animationPath, palettePath, transparency)
if animation, found := am.cache.Retrieve(cachePath); found {
return animation.(*Animation).Clone(), nil
}
var animation *Animation
switch strings.ToLower(filepath.Ext(animationPath)) {
case ".dc6":
dc6, err := loadDC6(animationPath, palettePath)
if err != nil {
return nil, err
}
animation, err = createAnimationFromDC6(dc6)
if err != nil {
return nil, err
}
case ".dcc":
dcc, err := loadDCC(animationPath)
if err != nil {
return nil, err
}
palette, err := loadPalette(palettePath)
if err != nil {
return nil, err
}
animation, err = createAnimationFromDCC(dcc, palette, transparency)
if err != nil {
return nil, err
}
default:
return nil, errors.New("unknown animation format")
}
if err := am.cache.Insert(cachePath, animation.Clone(), 1); err != nil {
return nil, err
}
return animation, nil
}

View File

@ -1,4 +1,4 @@
package d2archivemanager
package d2asset
import (
"errors"
@ -6,9 +6,7 @@ import (
"sync"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"
)
@ -17,7 +15,7 @@ type archiveEntry struct {
hashEntryMap d2mpq.HashEntryMap
}
type ArchiveManager struct {
type archiveManager struct {
cache *d2common.Cache
config *d2config.Configuration
entries []archiveEntry
@ -25,51 +23,35 @@ type ArchiveManager struct {
}
const (
ArchiveBudget = 1024 * 1024 * 512
archiveBudget = 1024 * 1024 * 512
)
func CreateArchiveManager(config *d2config.Configuration) *ArchiveManager {
return &ArchiveManager{cache: d2common.CreateCache(ArchiveBudget), config: config}
func createArchiveManager(config *d2config.Configuration) *archiveManager {
return &archiveManager{cache: d2common.CreateCache(archiveBudget), config: config}
}
func (am *ArchiveManager) SetCacheVerbose(verbose bool) {
am.cache.SetCacheVerbose(verbose)
}
func (am *ArchiveManager) GetCacheWeight() int {
return am.cache.GetWeight()
}
func (am *ArchiveManager) GetCacheBudget() int {
return am.cache.GetBudget()
}
func (am *ArchiveManager) ClearCache() {
am.cache.Clear()
}
func (am *ArchiveManager) LoadArchiveForFile(filePath string) (*d2mpq.MPQ, error) {
func (am *archiveManager) loadArchiveForFile(filePath string) (*d2mpq.MPQ, error) {
am.mutex.Lock()
defer am.mutex.Unlock()
if err := am.CacheArchiveEntries(); err != nil {
if err := am.cacheArchiveEntries(); err != nil {
return nil, err
}
for _, archiveEntry := range am.entries {
if archiveEntry.hashEntryMap.Contains(filePath) {
return am.LoadArchive(archiveEntry.archivePath)
return am.loadArchive(archiveEntry.archivePath)
}
}
return nil, errors.New("file not found")
}
func (am *ArchiveManager) FileExistsInArchive(filePath string) (bool, error) {
func (am *archiveManager) fileExistsInArchive(filePath string) (bool, error) {
am.mutex.Lock()
defer am.mutex.Unlock()
if err := am.CacheArchiveEntries(); err != nil {
if err := am.cacheArchiveEntries(); err != nil {
return false, err
}
@ -82,7 +64,7 @@ func (am *ArchiveManager) FileExistsInArchive(filePath string) (bool, error) {
return false, nil
}
func (am *ArchiveManager) LoadArchive(archivePath string) (*d2mpq.MPQ, error) {
func (am *archiveManager) loadArchive(archivePath string) (*d2mpq.MPQ, error) {
if archive, found := am.cache.Retrieve(archivePath); found {
return archive.(*d2mpq.MPQ), nil
}
@ -99,7 +81,7 @@ func (am *ArchiveManager) LoadArchive(archivePath string) (*d2mpq.MPQ, error) {
return archive, nil
}
func (am *ArchiveManager) CacheArchiveEntries() error {
func (am *archiveManager) cacheArchiveEntries() error {
if len(am.entries) == len(am.config.MpqLoadOrder) {
return nil
}
@ -108,7 +90,7 @@ func (am *ArchiveManager) CacheArchiveEntries() error {
for _, archiveName := range am.config.MpqLoadOrder {
archivePath := path.Join(am.config.MpqPath, archiveName)
archive, err := am.LoadArchive(archivePath)
archive, err := am.loadArchive(archivePath)
if err != nil {
return err
}

View File

@ -0,0 +1,67 @@
package d2asset
import (
"errors"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
)
var (
ErrHasInit error = errors.New("asset system is already initialized")
ErrNoInit error = errors.New("asset system is not initialized")
)
type assetManager struct {
archiveManager *archiveManager
fileManager *fileManager
paletteManager *paletteManager
animationManager *animationManager
}
func loadPalette(palettePath string) (*d2datadict.PaletteRec, error) {
if singleton == nil {
return nil, ErrNoInit
}
return singleton.paletteManager.loadPalette(palettePath)
}
func loadDC6(dc6Path, palettePath string) (*d2dc6.DC6File, error) {
dc6Data, err := LoadFile(dc6Path)
if err != nil {
return nil, err
}
paletteData, err := loadPalette(palettePath)
if err != nil {
return nil, err
}
dc6, err := d2dc6.LoadDC6(dc6Data, *paletteData)
if err != nil {
return nil, err
}
return &dc6, nil
}
func loadDCC(dccPath string) (*d2dcc.DCC, error) {
dccData, err := LoadFile(dccPath)
if err != nil {
return nil, err
}
return d2dcc.LoadDCC(dccData)
}
func loadCOF(cofPath string) (*d2cof.COF, error) {
cofData, err := LoadFile(cofPath)
if err != nil {
return nil, err
}
return d2cof.LoadCOF(cofData)
}

View File

@ -1,14 +1,11 @@
package d2assetmanager
package d2asset
import (
"errors"
"fmt"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
@ -108,7 +105,7 @@ type compositeMode struct {
directionCount int
playedCount int
layers []*d2render.Animation
layers []*Animation
drawOrder [][]d2enum.CompositeType
frameCount int
@ -143,7 +140,7 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
weaponClass: weaponClass,
direction: direction,
directionCount: cof.NumberOfDirections,
layers: make([]*d2render.Animation, d2enum.CompositeTypeMax),
layers: make([]*Animation, d2enum.CompositeTypeMax),
frameCount: animationData[0].FramesPerDirection,
animationSpeed: 1.0 / ((float64(animationData[0].AnimationSpeed) * 25.0) / 256.0),
}
@ -248,7 +245,7 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
return mode, nil
}
func loadCompositeLayer(object *d2datadict.ObjectLookupRecord, layerKey, layerValue, animationMode, weaponClass, palettePath string, transparency int) (*d2render.Animation, error) {
func loadCompositeLayer(object *d2datadict.ObjectLookupRecord, layerKey, layerValue, animationMode, weaponClass, palettePath string, transparency int) (*Animation, error) {
animationPaths := []string{
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dcc", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, weaponClass),
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dcc", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, "HTH"),

116
d2core/d2asset/d2asset.go Normal file
View File

@ -0,0 +1,116 @@
package d2asset
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2term"
)
var singleton *assetManager
func Initialize() error {
if singleton != nil {
return ErrHasInit
}
config, err := d2config.Get()
if err != nil {
return err
}
var (
archiveManager = createArchiveManager(config)
fileManager = createFileManager(config, archiveManager)
paletteManager = createPaletteManager()
animationManager = createAnimationManager()
)
singleton = &assetManager{
archiveManager,
fileManager,
paletteManager,
animationManager,
}
d2term.BindAction("assetspam", "display verbose asset manager logs", func(verbose bool) {
if verbose {
d2term.OutputInfo("asset manager verbose logging enabled")
} else {
d2term.OutputInfo("asset manager verbose logging disabled")
}
archiveManager.cache.SetVerbose(verbose)
fileManager.cache.SetVerbose(verbose)
paletteManager.cache.SetVerbose(verbose)
animationManager.cache.SetVerbose(verbose)
})
d2term.BindAction("assetstat", "display asset manager cache statistics", func() {
d2term.OutputInfo("archive cache: %f%%", float64(archiveManager.cache.GetWeight())/float64(archiveManager.cache.GetBudget())*100.0)
d2term.OutputInfo("file cache: %f%%", float64(fileManager.cache.GetWeight())/float64(fileManager.cache.GetBudget())*100.0)
d2term.OutputInfo("palette cache: %f%%", float64(paletteManager.cache.GetWeight())/float64(paletteManager.cache.GetBudget())*100.0)
d2term.OutputInfo("animation cache: %f%%", float64(animationManager.cache.GetWeight())/float64(animationManager.cache.GetBudget())*100.0)
})
d2term.BindAction("assetclear", "clear asset manager cache", func() {
archiveManager.cache.Clear()
fileManager.cache.Clear()
paletteManager.cache.Clear()
animationManager.cache.Clear()
})
return nil
}
func Shutdown() {
singleton = nil
}
func LoadArchive(archivePath string) (*d2mpq.MPQ, error) {
if singleton == nil {
return nil, ErrNoInit
}
return singleton.archiveManager.loadArchive(archivePath)
}
func LoadFile(filePath string) ([]byte, error) {
if singleton == nil {
return nil, ErrNoInit
}
data, err := singleton.fileManager.loadFile(filePath)
if err != nil {
log.Printf("error loading file %s (%v)", filePath, err.Error())
}
return data, err
}
func FileExists(filePath string) (bool, error) {
if singleton == nil {
return false, ErrNoInit
}
return singleton.fileManager.fileExists(filePath)
}
func LoadAnimation(animationPath, palettePath string) (*Animation, error) {
return LoadAnimationWithTransparency(animationPath, palettePath, 255)
}
func LoadAnimationWithTransparency(animationPath, palettePath string, transparency int) (*Animation, error) {
if singleton == nil {
return nil, ErrNoInit
}
return singleton.animationManager.loadAnimation(animationPath, palettePath, transparency)
}
func LoadComposite(object *d2datadict.ObjectLookupRecord, palettePath string) (*Composite, error) {
return CreateComposite(object, palettePath), nil
}

View File

@ -1,52 +1,34 @@
package d2filemanager
package d2asset
import (
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2archivemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
)
const (
FileBudget = 1024 * 1024 * 32
fileBudget = 1024 * 1024 * 32
)
type FileManager struct {
type fileManager struct {
cache *d2common.Cache
archiveManager *d2archivemanager.ArchiveManager
archiveManager *archiveManager
config *d2config.Configuration
}
func CreateFileManager(config *d2config.Configuration, archiveManager *d2archivemanager.ArchiveManager) *FileManager {
return &FileManager{d2common.CreateCache(FileBudget), archiveManager, config}
func createFileManager(config *d2config.Configuration, archiveManager *archiveManager) *fileManager {
return &fileManager{d2common.CreateCache(fileBudget), archiveManager, config}
}
func (fm *FileManager) SetCacheVerbose(verbose bool) {
fm.cache.SetCacheVerbose(verbose)
}
func (fm *FileManager) ClearCache() {
fm.cache.Clear()
}
func (fm *FileManager) GetCacheWeight() int {
return fm.cache.GetWeight()
}
func (fm *FileManager) GetCacheBudget() int {
return fm.cache.GetBudget()
}
func (fm *FileManager) LoadFile(filePath string) ([]byte, error) {
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)
archive, err := fm.archiveManager.loadArchiveForFile(filePath)
if err != nil {
return nil, err
}
@ -63,12 +45,12 @@ func (fm *FileManager) LoadFile(filePath string) ([]byte, error) {
return data, nil
}
func (fm *FileManager) FileExists(filePath string) (bool, error) {
func (fm *fileManager) fileExists(filePath string) (bool, error) {
filePath = fm.fixupFilePath(filePath)
return fm.archiveManager.FileExistsInArchive(filePath)
return fm.archiveManager.fileExistsInArchive(filePath)
}
func (fm *FileManager) fixupFilePath(filePath string) string {
func (fm *fileManager) fixupFilePath(filePath string) string {
filePath = strings.ReplaceAll(filePath, "{LANG}", fm.config.Language)
if strings.ToUpper(d2resource.LanguageCode) == "CHI" {
filePath = strings.ReplaceAll(filePath, "{LANG_FONT}", fm.config.Language)

View File

@ -0,0 +1,33 @@
package d2asset
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
)
type paletteManager struct {
cache *d2common.Cache
}
const (
paletteBudget = 64
)
func createPaletteManager() *paletteManager {
return &paletteManager{d2common.CreateCache(paletteBudget)}
}
func (pm *paletteManager) loadPalette(palettePath string) (*d2datadict.PaletteRec, error) {
if palette, found := pm.cache.Retrieve(palettePath); found {
return palette.(*d2datadict.PaletteRec), nil
}
paletteData, err := LoadFile(palettePath)
if err != nil {
return nil, err
}
palette := d2datadict.CreatePalette("", paletteData)
pm.cache.Insert(palettePath, &palette, 1)
return &palette, nil
}

View File

@ -1,246 +0,0 @@
package d2assetmanager
import (
"errors"
"fmt"
"log"
"path/filepath"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2archivemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2filemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2term"
)
const (
AnimationBudget = 64
)
var (
ErrHasInit error = errors.New("asset system is already initialized")
ErrNoInit error = errors.New("asset system is not initialized")
)
type AssetManager struct {
archiveManager *d2archivemanager.ArchiveManager
fileManager *d2filemanager.FileManager
paletteManager *PaletteManager
cache *d2common.Cache
}
var singleton *AssetManager
func Initialize() error {
if singleton != nil {
return ErrHasInit
}
config, _ := d2config.Get()
var (
archiveManager = d2archivemanager.CreateArchiveManager(config)
fileManager = d2filemanager.CreateFileManager(config, archiveManager)
paletteManager = CreatePaletteManager()
//animationManager = d2animationmanager.CreateAnimationManager()
)
singleton = &AssetManager{
archiveManager,
fileManager,
paletteManager,
nil,
}
singleton.cache = d2common.CreateCache(AnimationBudget)
d2term.BindAction("assetspam", "display verbose asset manager logs", func(verbose bool) {
if verbose {
d2term.OutputInfo("asset manager verbose logging enabled")
} else {
d2term.OutputInfo("asset manager verbose logging disabled")
}
archiveManager.SetCacheVerbose(verbose)
fileManager.SetCacheVerbose(verbose)
paletteManager.SetCacheVerbose(verbose)
})
d2term.BindAction("assetstat", "display asset manager cache statistics", func() {
d2term.OutputInfo("archive cache: %f%%", float64(archiveManager.GetCacheWeight())/float64(archiveManager.GetCacheBudget())*100.0)
d2term.OutputInfo("file cache: %f%%", float64(fileManager.GetCacheWeight())/float64(fileManager.GetCacheBudget())*100.0)
d2term.OutputInfo("palette cache: %f%%", float64(paletteManager.GetCacheWeight())/float64(paletteManager.GetCacheBudget())*100.0)
//d2term.OutputInfo("animation cache: %f%%", float64(GetCacheWeight())/float64(GetCacheBudget())*100.0)
})
d2term.BindAction("assetclear", "clear asset manager cache", func() {
archiveManager.ClearCache()
fileManager.ClearCache()
paletteManager.ClearCache()
//am.ClearCache()
})
return nil
}
func Shutdown() {
singleton = nil
}
func LoadArchive(archivePath string) (*d2mpq.MPQ, error) {
if singleton == nil {
return nil, ErrNoInit
}
return singleton.archiveManager.LoadArchive(archivePath)
}
func LoadFile(filePath string) ([]byte, error) {
if singleton == nil {
return nil, ErrNoInit
}
data, err := singleton.fileManager.LoadFile(filePath)
if err != nil {
log.Printf("error loading file %s (%v)", filePath, err.Error())
}
return data, err
}
func FileExists(filePath string) (bool, error) {
if singleton == nil {
return false, ErrNoInit
}
return singleton.fileManager.FileExists(filePath)
}
func LoadAnimation(animationPath, palettePath string) (*d2render.Animation, error) {
return LoadAnimationWithTransparency(animationPath, palettePath, 255)
}
func LoadAnimationWithTransparency(animationPath, palettePath string, transparency int) (*d2render.Animation, error) {
if singleton == nil {
return nil, ErrNoInit
}
return singleton.LoadAnimation(animationPath, palettePath, transparency)
}
func LoadComposite(object *d2datadict.ObjectLookupRecord, palettePath string) (*Composite, error) {
return CreateComposite(object, palettePath), nil
}
func loadPalette(palettePath string) (*d2datadict.PaletteRec, error) {
if singleton == nil {
return nil, ErrNoInit
}
return singleton.paletteManager.LoadPalette(palettePath)
}
func loadDC6(dc6Path, palettePath string) (*d2dc6.DC6File, error) {
dc6Data, err := LoadFile(dc6Path)
if err != nil {
return nil, err
}
paletteData, err := loadPalette(palettePath)
if err != nil {
return nil, err
}
dc6, err := d2dc6.LoadDC6(dc6Data, *paletteData)
if err != nil {
return nil, err
}
return &dc6, nil
}
func loadDCC(dccPath string) (*d2dcc.DCC, error) {
dccData, err := LoadFile(dccPath)
if err != nil {
return nil, err
}
return d2dcc.LoadDCC(dccData)
}
func loadCOF(cofPath string) (*d2cof.COF, error) {
cofData, err := LoadFile(cofPath)
if err != nil {
return nil, err
}
return d2cof.LoadCOF(cofData)
}
func (am *AssetManager) SetCacheVerbose(verbose bool) {
am.cache.SetCacheVerbose(verbose)
}
func (am *AssetManager) ClearCache() {
am.cache.Clear()
}
func (am *AssetManager) GetCacheWeight() int {
return am.cache.GetWeight()
}
func (am *AssetManager) GetCacheBudget() int {
return am.cache.GetBudget()
}
func (am *AssetManager) LoadAnimation(animationPath, palettePath string, transparency int) (*d2render.Animation, error) {
cachePath := fmt.Sprintf("%s;%s;%d", animationPath, palettePath, transparency)
if animation, found := am.cache.Retrieve(cachePath); found {
return animation.(*d2render.Animation).Clone(), nil
}
var animation *d2render.Animation
switch strings.ToLower(filepath.Ext(animationPath)) {
case ".dc6":
dc6, err := loadDC6(animationPath, palettePath)
if err != nil {
return nil, err
}
animation, err = d2render.CreateAnimationFromDC6(dc6)
if err != nil {
return nil, err
}
case ".dcc":
dcc, err := loadDCC(animationPath)
if err != nil {
return nil, err
}
palette, err := loadPalette(palettePath)
if err != nil {
return nil, err
}
animation, err = d2render.CreateAnimationFromDCC(dcc, palette, transparency)
if err != nil {
return nil, err
}
default:
return nil, errors.New("unknown animation format")
}
if err := am.cache.Insert(cachePath, animation.Clone(), 1); err != nil {
return nil, err
}
return animation, nil
}

View File

@ -1,49 +0,0 @@
package d2assetmanager
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
)
type PaletteManager struct {
cache *d2common.Cache
}
const (
PaletteBudget = 64
)
func CreatePaletteManager() *PaletteManager {
return &PaletteManager{d2common.CreateCache(PaletteBudget)}
}
func (pm *PaletteManager) SetCacheVerbose(verbose bool) {
pm.cache.SetCacheVerbose(verbose)
}
func (pm *PaletteManager) ClearCache() {
pm.cache.Clear()
}
func (pm *PaletteManager) GetCacheWeight() int {
return pm.cache.GetWeight()
}
func (pm *PaletteManager) GetCacheBudget() int {
return pm.cache.GetBudget()
}
func (pm *PaletteManager) LoadPalette(palettePath string) (*d2datadict.PaletteRec, error) {
if palette, found := pm.cache.Retrieve(palettePath); found {
return palette.(*d2datadict.PaletteRec), nil
}
paletteData, err := LoadFile(palettePath)
if err != nil {
return nil, err
}
palette := d2datadict.CreatePalette("", paletteData)
pm.cache.Insert(palettePath, &palette, 1)
return &palette, nil
}

View File

@ -5,7 +5,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/hajimehoshi/ebiten/audio/wav"
"github.com/hajimehoshi/ebiten/audio"
@ -46,7 +46,7 @@ func (eap *EbitenAudioProvider) PlayBGM(song string) {
log.Panic(err)
}
}
audioData, err := d2assetmanager.LoadFile(song)
audioData, err := d2asset.LoadFile(song)
if err != nil {
panic(err)
}

View File

@ -4,7 +4,7 @@ import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/hajimehoshi/ebiten/audio"
"github.com/hajimehoshi/ebiten/audio/wav"
)
@ -23,7 +23,7 @@ func CreateSoundEffect(sfx string, context *audio.Context, volume float64) *Ebit
soundFile = sfx
}
audioData, err := d2assetmanager.LoadFile(soundFile)
audioData, err := d2asset.LoadFile(soundFile)
if err != nil {
panic(err)
}

View File

@ -9,9 +9,8 @@ import (
"strings"
"time"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
)
@ -36,7 +35,7 @@ type GameState struct {
HeroLevel int
Act int
FilePath string
Equipment d2hero.CharacterEquipment
Equipment d2inventory.CharacterEquipment
}
const GameStateVersion = uint32(2) // Update this when you make breaking changes

View File

@ -1,4 +1,4 @@
package d2hero
package d2inventory
type CharacterEquipment struct {
Head *InventoryItemArmor // Head

View File

@ -1,4 +1,4 @@
package d2hero
package d2inventory
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"

View File

@ -1,4 +1,4 @@
package d2hero
package d2inventory
import (
"log"

View File

@ -1,4 +1,4 @@
package d2hero
package d2inventory
import (
"log"

View File

@ -1,15 +1,14 @@
package d2assetmanager
package d2map
import (
"math"
"math/rand"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
)
// AnimatedEntity represents an entity on the map that can be animated
@ -27,12 +26,12 @@ type AnimatedEntity struct {
action int32
repetitions int
composite *Composite
composite *d2asset.Composite
}
// CreateAnimatedEntity creates an instance of AnimatedEntity
func CreateAnimatedEntity(x, y int32, object *d2datadict.ObjectLookupRecord, palettePath string) (*AnimatedEntity, error) {
composite, err := LoadComposite(object, palettePath)
composite, err := d2asset.LoadComposite(object, palettePath)
if err != nil {
return nil, err
}

View File

@ -1,4 +1,4 @@
package d2mapengine
package d2map
type Camera struct {
x float64

View File

@ -1,4 +1,4 @@
package d2mapengine
package d2map
import (
"strings"

View File

@ -1,21 +1,21 @@
package d2hero
package d2map
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
)
type Hero struct {
AnimatedEntity *d2assetmanager.AnimatedEntity
Equipment CharacterEquipment
AnimatedEntity *AnimatedEntity
Equipment d2inventory.CharacterEquipment
mode d2enum.AnimationMode
direction int
}
func CreateHero(x, y int32, direction int, heroType d2enum.Hero, equipment CharacterEquipment) *Hero {
func CreateHero(x, y int32, direction int, heroType d2enum.Hero, equipment d2inventory.CharacterEquipment) *Hero {
object := &d2datadict.ObjectLookupRecord{
Mode: d2enum.AnimationModePlayerNeutral.String(),
Base: "/data/global/chars",
@ -32,7 +32,7 @@ func CreateHero(x, y int32, direction int, heroType d2enum.Hero, equipment Chara
LH: equipment.LeftHand.ItemCode(),
}
entity, err := d2assetmanager.CreateAnimatedEntity(x, y, object, d2resource.PaletteUnits)
entity, err := CreateAnimatedEntity(x, y, object, d2resource.PaletteUnits)
if err != nil {
panic(err)
}

View File

@ -1,21 +1,20 @@
package d2npc
package d2map
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
)
type NPC struct {
AnimatedEntity *d2assetmanager.AnimatedEntity
AnimatedEntity *AnimatedEntity
HasPaths bool
Paths []d2common.Path
path int
}
func CreateNPC(x, y int32, object *d2datadict.ObjectLookupRecord, direction int) *NPC {
entity, err := d2assetmanager.CreateAnimatedEntity(x, y, object, d2resource.PaletteUnits)
entity, err := CreateAnimatedEntity(x, y, object, d2resource.PaletteUnits)
if err != nil {
panic(err)
}

View File

@ -1,4 +1,4 @@
package d2mapengine
package d2map
import (
"image/color"
@ -7,9 +7,7 @@ import (
"math/rand"
"strconv"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2npc"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
@ -54,7 +52,7 @@ func loadRegion(seed int64, tileOffsetX, tileOffsetY int, levelType d2enum.Regio
for _, levelTypeDt1 := range region.levelType.Files {
if len(levelTypeDt1) != 0 && levelTypeDt1 != "" && levelTypeDt1 != "0" {
fileData, err := d2assetmanager.LoadFile("/data/global/tiles/" + levelTypeDt1)
fileData, err := d2asset.LoadFile("/data/global/tiles/" + levelTypeDt1)
if err != nil {
panic(err)
}
@ -77,7 +75,7 @@ func loadRegion(seed int64, tileOffsetX, tileOffsetY int, levelType d2enum.Regio
}
region.regionPath = levelFilesToPick[levelIndex]
fileData, err := d2assetmanager.LoadFile("/data/global/tiles/" + region.regionPath)
fileData, err := d2asset.LoadFile("/data/global/tiles/" + region.regionPath)
if err != nil {
panic(err)
}
@ -136,13 +134,13 @@ func (mr *MapRegion) loadEntities() []MapEntity {
switch object.Lookup.Type {
case d2datadict.ObjectTypeCharacter:
if object.Lookup.Base != "" && object.Lookup.Token != "" && object.Lookup.TR != "" {
npc := d2npc.CreateNPC(int32(worldX), int32(worldY), object.Lookup, 0)
npc := CreateNPC(int32(worldX), int32(worldY), object.Lookup, 0)
npc.SetPaths(object.Paths)
entities = append(entities, npc)
}
case d2datadict.ObjectTypeItem:
if object.ObjectInfo != nil && object.ObjectInfo.Draw && object.Lookup.Base != "" && object.Lookup.Token != "" {
entity, err := d2assetmanager.CreateAnimatedEntity(int32(worldX), int32(worldY), object.Lookup, d2resource.PaletteUnits)
entity, err := CreateAnimatedEntity(int32(worldX), int32(worldY), object.Lookup, d2resource.PaletteUnits)
if err != nil {
panic(err)
}

View File

@ -1,4 +1,4 @@
package d2mapengine
package d2map
import (
"math"

View File

@ -1,4 +1,4 @@
package d2scenemanager
package d2scene
import (
"math"
@ -9,6 +9,14 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
// Scene defines the function necessary for scene management
type Scene interface {
Load() []func()
Unload()
Render(target d2common.Surface)
Advance(tickTime float64)
}
var nextScene Scene // The next scene to be loaded at the end of the game loop
var currentScene Scene // The current scene being rendered
var loadingIndex int // Determines which load function is currently being called

View File

@ -1,13 +0,0 @@
package d2scenemanager
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
// Scene defines the function necessary for scene management
type Scene interface {
Load() []func()
Unload()
Render(target d2common.Surface)
Advance(tickTime float64)
}

View File

@ -4,7 +4,7 @@ import (
"image"
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
@ -116,8 +116,8 @@ func CreateButton(buttonType ButtonType, text string) Button {
result.buttonLayout = buttonLayout
font := GetFont(buttonLayout.FontPath, d2resource.PaletteUnits)
animation, _ := d2assetmanager.LoadAnimation(buttonLayout.ResourceName, buttonLayout.PaletteName)
buttonSprite, _ := d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(buttonLayout.ResourceName, buttonLayout.PaletteName)
buttonSprite, _ := LoadSprite(animation)
totalButtonTypes := buttonSprite.GetFrameCount() / (buttonLayout.XSegments * buttonLayout.YSegments)
for i := 0; i < buttonLayout.XSegments; i++ {
w, _, _ := buttonSprite.GetFrameSize(i)

View File

@ -3,7 +3,7 @@ package d2ui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
@ -27,8 +27,8 @@ func CreateCheckbox(checkState bool) Checkbox {
enabled: true,
}
animation, _ := d2assetmanager.LoadAnimation(d2resource.Checkbox, d2resource.PaletteFechar)
checkboxSprite, _ := d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.Checkbox, d2resource.PaletteFechar)
checkboxSprite, _ := LoadSprite(animation)
result.width, result.height, _ = checkboxSprite.GetFrameSize(0)
checkboxSprite.SetPosition(0, 0)

View File

@ -5,7 +5,6 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/hajimehoshi/ebiten"
)
@ -20,7 +19,7 @@ const (
)
var widgets []Widget
var cursorSprite *d2render.Sprite
var cursorSprite *Sprite
var cursorButtons CursorButton
var pressedIndex int
var CursorX int
@ -28,7 +27,7 @@ var CursorY int
var clickSfx d2interface.SoundEffect
var waitForLeftMouseUp bool
func Initialize(curSprite *d2render.Sprite) {
func Initialize(curSprite *Sprite) {
cursorSprite = curSprite
pressedIndex = -1
clickSfx, _ = d2audio.LoadSoundEffect(d2resource.SFXButtonClick)
@ -145,6 +144,6 @@ func KeyPressed(key ebiten.Key) bool {
return ebiten.IsKeyPressed(key)
}
func GetCursorSprite() *d2render.Sprite {
func GetCursorSprite() *Sprite {
return cursorSprite
}

View File

@ -4,14 +4,12 @@ import (
"image/color"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"encoding/binary"
"unicode"
@ -27,7 +25,7 @@ type FontSize struct {
// Font represents a font
type Font struct {
fontSprite *d2render.Sprite
fontSprite *Sprite
fontTable map[uint16]uint16
metrics map[uint16]FontSize
}
@ -50,10 +48,10 @@ func CreateFont(font string, palettePath string) *Font {
metrics: make(map[uint16]FontSize),
}
// bug: performance issue when using CJK fonts, because ten thousand frames will be rendered PER font
animation, _ := d2assetmanager.LoadAnimation(font+".dc6", palettePath)
result.fontSprite, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(font+".dc6", palettePath)
result.fontSprite, _ = LoadSprite(animation)
woo := "Woo!\x01"
fontData, err := d2assetmanager.LoadFile(font + ".tbl")
fontData, err := d2asset.LoadFile(font + ".tbl")
if err != nil {
panic(err)
}

View File

@ -3,8 +3,7 @@ package d2ui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/hajimehoshi/ebiten"
)
@ -16,12 +15,12 @@ type Scrollbar struct {
maxOffset int
lastDirChange int
onActivate func()
scrollbarSprite *d2render.Sprite
scrollbarSprite *Sprite
}
func CreateScrollbar(x, y, height int) Scrollbar {
animation, _ := d2assetmanager.LoadAnimation(d2resource.Scrollbar, d2resource.PaletteSky)
scrollbarSprite, _ := d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.Scrollbar, d2resource.PaletteSky)
scrollbarSprite, _ := LoadSprite(animation)
result := Scrollbar{
visible: true,
enabled: true,

View File

@ -1,10 +1,11 @@
package d2render
package d2ui
import (
"errors"
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
)
@ -12,14 +13,14 @@ import (
type Sprite struct {
x int
y int
animation *Animation
animation *d2asset.Animation
}
var (
ErrNoAnimation error = errors.New("No animation was specified")
)
func LoadSprite(animation *Animation) (*Sprite, error) {
func LoadSprite(animation *d2asset.Animation) (*Sprite, error) {
if animation == nil {
return nil, ErrNoAnimation
}

View File

@ -4,14 +4,13 @@ import (
"strings"
"time"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/hajimehoshi/ebiten/inpututil"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/hajimehoshi/ebiten"
)
@ -22,14 +21,14 @@ type TextBox struct {
y int
visible bool
enabled bool
bgSprite *d2render.Sprite
bgSprite *Sprite
textLabel Label
lineBar Label
}
func CreateTextbox() TextBox {
animation, _ := d2assetmanager.LoadAnimation(d2resource.TextBox2, d2resource.PaletteUnits)
bgSprite, _ := d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.TextBox2, d2resource.PaletteUnits)
bgSprite, _ := LoadSprite(animation)
result := TextBox{
bgSprite: bgSprite,
textLabel: CreateLabel(d2resource.FontFormal11, d2resource.PaletteUnits),

View File

@ -9,7 +9,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scenemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
@ -18,8 +18,8 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
var loadingSprite *d2render.Sprite // The sprite shown when loading stuff
var lastTime float64 // Last time we updated the scene
var loadingSprite *d2ui.Sprite // The sprite shown when loading stuff
var lastTime float64 // Last time we updated the scene
var showFPS bool
var timeScale float64
@ -28,7 +28,7 @@ type bsForInputHanding struct {
var bsHandler *bsForInputHanding
func Initialize(loadingSpr *d2render.Sprite) error {
func Initialize(loadingSpr *d2ui.Sprite) error {
bsHandler = &bsForInputHanding{}
loadingSprite = loadingSpr
timeScale = 1.0
@ -76,12 +76,12 @@ func (bs *bsForInputHanding) OnKeyDown(event d2input.KeyEvent) bool {
// Advance updates the internal state of the engine
func Advance() {
d2scenemanager.UpdateScene()
if d2scenemanager.GetCurrentScene() == nil {
d2scene.UpdateScene()
if d2scene.GetCurrentScene() == nil {
log.Fatal("no scene loaded")
}
if d2scenemanager.IsLoading() {
if d2scene.IsLoading() {
return
}
@ -89,7 +89,7 @@ func Advance() {
deltaTime := (currentTime - lastTime) * timeScale
lastTime = currentTime
d2scenemanager.Advance(deltaTime)
d2scene.Advance(deltaTime)
d2ui.Advance(deltaTime)
d2term.Advance(deltaTime)
d2input.Advance(deltaTime)
@ -97,16 +97,16 @@ func Advance() {
// Draw draws the game
func render(target d2common.Surface) {
if d2scenemanager.GetLoadingProgress() < 1.0 {
if d2scene.GetLoadingProgress() < 1.0 {
loadingSprite.SetCurrentFrame(int(d2helper.Max(0,
d2helper.Min(uint32(loadingSprite.GetFrameCount()-1),
uint32(float64(loadingSprite.GetFrameCount()-1)*d2scenemanager.GetLoadingProgress())))))
uint32(float64(loadingSprite.GetFrameCount()-1)*d2scene.GetLoadingProgress())))))
loadingSprite.Render(target)
} else {
if d2scenemanager.GetCurrentScene() == nil {
if d2scene.GetCurrentScene() == nil {
log.Fatal("no scene loaded")
}
d2scenemanager.Render(target)
d2scene.Render(target)
d2ui.Render(target)
}
if showFPS {

View File

@ -1,8 +1,8 @@
package d2scene
package d2gamescene
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2video"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/hajimehoshi/ebiten"
)
@ -19,7 +19,7 @@ func CreateBlizzardIntro() *BlizzardIntro {
func (v *BlizzardIntro) Load() []func() {
return []func(){
func() {
videoBytes, err := d2assetmanager.LoadFile("/data/local/video/BlizNorth640x480.bik")
videoBytes, err := d2asset.LoadFile("/data/local/video/BlizNorth640x480.bik")
if err != nil {
panic(err)
}

View File

@ -1,4 +1,4 @@
package d2scene
package d2gamescene
import (
"image/color"
@ -6,13 +6,11 @@ import (
"os"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scenemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
@ -20,13 +18,12 @@ import (
dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/hajimehoshi/ebiten"
)
type CharacterSelect struct {
background *d2render.Sprite
background *d2ui.Sprite
newCharButton d2ui.Button
convertCharButton d2ui.Button
deleteCharButton d2ui.Button
@ -34,15 +31,15 @@ type CharacterSelect struct {
okButton d2ui.Button
deleteCharCancelButton d2ui.Button
deleteCharOkButton d2ui.Button
selectionBox *d2render.Sprite
okCancelBox *d2render.Sprite
selectionBox *d2ui.Sprite
okCancelBox *d2ui.Sprite
d2HeroTitle d2ui.Label
deleteCharConfirmLabel d2ui.Label
charScrollbar d2ui.Scrollbar
characterNameLabel [8]d2ui.Label
characterStatsLabel [8]d2ui.Label
characterExpLabel [8]d2ui.Label
characterImage [8]*d2hero.Hero
characterImage [8]*d2map.Hero
gameStates []*d2gamestate.GameState
selectedCharacter int
mouseButtonPressed bool
@ -60,8 +57,8 @@ func (v *CharacterSelect) Load() []func() {
d2audio.PlayBGM(d2resource.BGMTitle)
return []func(){
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.CharacterSelectionBackground, d2resource.PaletteSky)
v.background, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.CharacterSelectionBackground, d2resource.PaletteSky)
v.background, _ = d2ui.LoadSprite(animation)
v.background.SetPosition(0, 0)
},
func() {
@ -121,13 +118,13 @@ func (v *CharacterSelect) Load() []func() {
v.deleteCharConfirmLabel.SetPosition(400, 185)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.CharacterSelectionSelectBox, d2resource.PaletteSky)
v.selectionBox, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.CharacterSelectionSelectBox, d2resource.PaletteSky)
v.selectionBox, _ = d2ui.LoadSprite(animation)
v.selectionBox.SetPosition(37, 86)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.PopUpOkCancel, d2resource.PaletteFechar)
v.okCancelBox, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.PopUpOkCancel, d2resource.PaletteFechar)
v.okCancelBox, _ = d2ui.LoadSprite(animation)
v.okCancelBox.SetPosition(270, 175)
},
func() {
@ -175,24 +172,24 @@ func (v *CharacterSelect) updateCharacterBoxes() {
v.characterStatsLabel[i].SetText("Level 1 " + v.gameStates[idx].HeroType.String())
v.characterExpLabel[i].SetText(expText)
// TODO: Generate or load the object from the actual player data...
v.characterImage[i] = d2hero.CreateHero(
v.characterImage[i] = d2map.CreateHero(
0,
0,
0,
v.gameStates[idx].HeroType,
d2hero.HeroObjects[v.gameStates[idx].HeroType],
d2inventory.HeroObjects[v.gameStates[idx].HeroType],
)
}
}
func (v *CharacterSelect) onNewCharButtonClicked() {
d2scenemanager.SetNextScene(CreateSelectHeroClass())
d2scene.SetNextScene(CreateSelectHeroClass())
}
func (v *CharacterSelect) onExitButtonClicked() {
mainMenu := CreateMainMenu()
mainMenu.ShowTrademarkScreen = false
d2scenemanager.SetNextScene(mainMenu)
d2scene.SetNextScene(mainMenu)
}
func (v *CharacterSelect) Unload() {
@ -312,5 +309,5 @@ func (v *CharacterSelect) refreshGameStates() {
}
func (v *CharacterSelect) onOkButtonClicked() {
d2scenemanager.SetNextScene(CreateGame(v.gameStates[v.selectedCharacter]))
d2scene.SetNextScene(CreateGame(v.gameStates[v.selectedCharacter]))
}

View File

@ -1,4 +1,4 @@
package d2scene
package d2gamescene
import (
"bufio"
@ -8,14 +8,12 @@ import (
"path"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scenemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
@ -30,7 +28,7 @@ type labelItem struct {
// Credits represents the credits scene
type Credits struct {
creditsBackground *d2render.Sprite
creditsBackground *d2ui.Sprite
exitButton d2ui.Button
creditsText []string
labels []*labelItem
@ -71,8 +69,8 @@ func (v *Credits) LoadContributors() []string {
func (v *Credits) Load() []func() {
return []func(){
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.CreditsBackground, d2resource.PaletteSky)
v.creditsBackground, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.CreditsBackground, d2resource.PaletteSky)
v.creditsBackground, _ = d2ui.LoadSprite(animation)
v.creditsBackground.SetPosition(0, 0)
},
func() {
@ -82,7 +80,7 @@ func (v *Credits) Load() []func() {
d2ui.AddWidget(&v.exitButton)
},
func() {
fileData, err := d2assetmanager.LoadFile(d2resource.CreditsText)
fileData, err := d2asset.LoadFile(d2resource.CreditsText)
if err != nil {
panic(err)
}
@ -140,7 +138,7 @@ func (v *Credits) Advance(tickTime float64) {
func (v *Credits) onExitButtonClicked() {
mainMenu := CreateMainMenu()
mainMenu.ShowTrademarkScreen = false
d2scenemanager.SetNextScene(mainMenu)
d2scene.SetNextScene(mainMenu)
}
func (v *Credits) addNextItem() {

View File

@ -1,32 +1,28 @@
package d2scene
package d2gamescene
import (
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render/d2mapengine"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2player"
)
type Game struct {
gameState *d2gamestate.GameState
pentSpinLeft *d2render.Sprite
pentSpinRight *d2render.Sprite
pentSpinLeft *d2ui.Sprite
pentSpinRight *d2ui.Sprite
testLabel d2ui.Label
mapEngine *d2mapengine.MapEngine
hero *d2hero.Hero
mapEngine *d2map.MapEngine
hero *d2map.Hero
gameControls *d2player.GameControls
}
@ -42,15 +38,15 @@ func CreateGame(
func (v *Game) Load() []func() {
return []func(){
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.PentSpin, d2resource.PaletteSky)
v.pentSpinLeft, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.PentSpin, d2resource.PaletteSky)
v.pentSpinLeft, _ = d2ui.LoadSprite(animation)
v.pentSpinLeft.PlayBackward()
v.pentSpinLeft.SetPlayLengthMs(475)
v.pentSpinLeft.SetPosition(100, 300)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.PentSpin, d2resource.PaletteSky)
v.pentSpinRight, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.PentSpin, d2resource.PaletteSky)
v.pentSpinRight, _ = d2ui.LoadSprite(animation)
v.pentSpinRight.PlayForward()
v.pentSpinRight.SetPlayLengthMs(475)
v.pentSpinRight.SetPosition(650, 300)
@ -62,11 +58,11 @@ func (v *Game) Load() []func() {
v.testLabel.SetPosition(400, 250)
},
func() {
v.mapEngine = d2mapengine.CreateMapEngine(v.gameState)
v.mapEngine = d2map.CreateMapEngine(v.gameState)
v.mapEngine.GenerateMap(d2enum.RegionAct1Town, 1, 0)
startX, startY := v.mapEngine.GetStartPosition()
v.hero = d2hero.CreateHero(
v.hero = d2map.CreateHero(
int32(startX*5)+3,
int32(startY*5)+3,
0,

View File

@ -1,4 +1,4 @@
package d2scene
package d2gamescene
import (
"fmt"
@ -8,30 +8,28 @@ import (
"os/exec"
"runtime"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scenemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
)
// MainMenu represents the main menu
type MainMenu struct {
trademarkBackground *d2render.Sprite
background *d2render.Sprite
diabloLogoLeft *d2render.Sprite
diabloLogoRight *d2render.Sprite
diabloLogoLeftBack *d2render.Sprite
diabloLogoRightBack *d2render.Sprite
trademarkBackground *d2ui.Sprite
background *d2ui.Sprite
diabloLogoLeft *d2ui.Sprite
diabloLogoRight *d2ui.Sprite
diabloLogoLeftBack *d2ui.Sprite
diabloLogoRightBack *d2ui.Sprite
singlePlayerButton d2ui.Button
githubButton d2ui.Button
exitDiabloButton d2ui.Button
@ -97,37 +95,37 @@ func (v *MainMenu) Load() []func() {
v.openDiabloLabel.SetPosition(400, 580)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.GameSelectScreen, d2resource.PaletteSky)
v.background, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.GameSelectScreen, d2resource.PaletteSky)
v.background, _ = d2ui.LoadSprite(animation)
v.background.SetPosition(0, 0)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.TrademarkScreen, d2resource.PaletteSky)
v.trademarkBackground, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.TrademarkScreen, d2resource.PaletteSky)
v.trademarkBackground, _ = d2ui.LoadSprite(animation)
v.trademarkBackground.SetPosition(0, 0)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.Diablo2LogoFireLeft, d2resource.PaletteUnits)
v.diabloLogoLeft, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.Diablo2LogoFireLeft, d2resource.PaletteUnits)
v.diabloLogoLeft, _ = d2ui.LoadSprite(animation)
v.diabloLogoLeft.SetBlend(true)
v.diabloLogoLeft.PlayForward()
v.diabloLogoLeft.SetPosition(400, 120)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.Diablo2LogoFireRight, d2resource.PaletteUnits)
v.diabloLogoRight, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.Diablo2LogoFireRight, d2resource.PaletteUnits)
v.diabloLogoRight, _ = d2ui.LoadSprite(animation)
v.diabloLogoRight.SetBlend(true)
v.diabloLogoRight.PlayForward()
v.diabloLogoRight.SetPosition(400, 120)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.Diablo2LogoBlackLeft, d2resource.PaletteUnits)
v.diabloLogoLeftBack, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.Diablo2LogoBlackLeft, d2resource.PaletteUnits)
v.diabloLogoLeftBack, _ = d2ui.LoadSprite(animation)
v.diabloLogoLeftBack.SetPosition(400, 120)
},
func() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.Diablo2LogoBlackRight, d2resource.PaletteUnits)
v.diabloLogoRightBack, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.Diablo2LogoBlackRight, d2resource.PaletteUnits)
v.diabloLogoRightBack, _ = d2ui.LoadSprite(animation)
v.diabloLogoRightBack.SetPosition(400, 120)
},
func() {
@ -175,7 +173,7 @@ func (v *MainMenu) Load() []func() {
}
func (v *MainMenu) onMapTestClicked() {
d2scenemanager.SetNextScene(CreateMapEngineTest(0, 1))
d2scene.SetNextScene(CreateMapEngineTest(0, 1))
}
func openbrowser(url string) {
@ -200,10 +198,10 @@ func openbrowser(url string) {
func (v *MainMenu) onSinglePlayerClicked() {
// Go here only if existing characters are available to select
if d2gamestate.HasGameStates() {
d2scenemanager.SetNextScene(CreateCharacterSelect())
d2scene.SetNextScene(CreateCharacterSelect())
return
}
d2scenemanager.SetNextScene(CreateSelectHeroClass())
d2scene.SetNextScene(CreateSelectHeroClass())
}
func (v *MainMenu) onGithubButtonClicked() {
@ -215,7 +213,7 @@ func (v *MainMenu) onExitButtonClicked() {
}
func (v *MainMenu) onCreditsButtonClicked() {
d2scenemanager.SetNextScene(CreateCredits())
d2scene.SetNextScene(CreateCredits())
}
// Unload unloads the data for the main menu

View File

@ -1,4 +1,4 @@
package d2scene
package d2gamescene
import (
"math"
@ -8,7 +8,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scenemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
@ -17,7 +17,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render/d2mapengine"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
)
type RegionSpec struct {
@ -83,7 +83,7 @@ var regions []RegionSpec = []RegionSpec{
type MapEngineTest struct {
gameState *d2gamestate.GameState
mapEngine *d2mapengine.MapEngine
mapEngine *d2map.MapEngine
//TODO: this is region specific properties, should be refactored for multi-region rendering
currentRegion int
@ -133,7 +133,7 @@ func (v *MapEngineTest) LoadRegionByIndex(n int, levelPreset, fileIndex int) {
if n == 0 {
v.mapEngine.GenerateAct1Overworld()
} else {
v.mapEngine = d2mapengine.CreateMapEngine(v.gameState) // necessary for map name update
v.mapEngine = d2map.CreateMapEngine(v.gameState) // necessary for map name update
v.mapEngine.GenerateMap(d2enum.RegionIdType(n), levelPreset, fileIndex)
}
@ -146,7 +146,7 @@ func (v *MapEngineTest) Load() []func() {
d2audio.PlayBGM("")
return []func(){
func() {
v.mapEngine = d2mapengine.CreateMapEngine(v.gameState)
v.mapEngine = d2map.CreateMapEngine(v.gameState)
v.LoadRegionByIndex(v.currentRegion, v.levelPreset, v.fileIndex)
},
}
@ -245,13 +245,13 @@ func (met *MapEngineTest) OnKeyDown(event d2input.KeyEvent) bool {
if event.Key == d2input.KeyN {
if event.KeyMod == d2input.KeyModControl {
met.fileIndex = increment(met.fileIndex, 0, met.filesCount-1)
d2scenemanager.SetNextScene(met)
d2scene.SetNextScene(met)
} else if event.KeyMod == d2input.KeyModShift {
met.levelPreset = increment(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex)
d2scenemanager.SetNextScene(met)
d2scene.SetNextScene(met)
} else {
met.currentRegion = increment(met.currentRegion, 0, len(regions))
d2scenemanager.SetNextScene(met)
d2scene.SetNextScene(met)
}
return true
@ -260,13 +260,13 @@ func (met *MapEngineTest) OnKeyDown(event d2input.KeyEvent) bool {
if event.Key == d2input.KeyP {
if event.KeyMod == d2input.KeyModControl {
met.fileIndex = decrement(met.fileIndex, 0, met.filesCount-1)
d2scenemanager.SetNextScene(met)
d2scene.SetNextScene(met)
} else if event.KeyMod == d2input.KeyModShift {
met.levelPreset = decrement(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex)
d2scenemanager.SetNextScene(met)
d2scene.SetNextScene(met)
} else {
met.currentRegion = decrement(met.currentRegion, 0, len(regions))
d2scenemanager.SetNextScene(met)
d2scene.SetNextScene(met)
}
return true

View File

@ -1,4 +1,4 @@
package d2scene
package d2gamescene
import (
"image"
@ -6,16 +6,14 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scenemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
@ -27,14 +25,14 @@ import (
type HeroRenderInfo struct {
Stance d2enum.HeroStance
IdleSprite *d2render.Sprite
IdleSelectedSprite *d2render.Sprite
ForwardWalkSprite *d2render.Sprite
ForwardWalkSpriteOverlay *d2render.Sprite
SelectedSprite *d2render.Sprite
SelectedSpriteOverlay *d2render.Sprite
BackWalkSprite *d2render.Sprite
BackWalkSpriteOverlay *d2render.Sprite
IdleSprite *d2ui.Sprite
IdleSelectedSprite *d2ui.Sprite
ForwardWalkSprite *d2ui.Sprite
ForwardWalkSpriteOverlay *d2ui.Sprite
SelectedSprite *d2ui.Sprite
SelectedSpriteOverlay *d2ui.Sprite
BackWalkSprite *d2ui.Sprite
BackWalkSpriteOverlay *d2ui.Sprite
SelectionBounds image.Rectangle
SelectSfx d2interface.SoundEffect
DeselectSfx d2interface.SoundEffect
@ -52,8 +50,8 @@ func (hri *HeroRenderInfo) Advance(elapsed float64) {
}
type SelectHeroClass struct {
bgImage *d2render.Sprite
campfire *d2render.Sprite
bgImage *d2ui.Sprite
campfire *d2ui.Sprite
headingLabel d2ui.Label
heroClassLabel d2ui.Label
heroDesc1Label d2ui.Label
@ -446,12 +444,12 @@ func (v *SelectHeroClass) Unload() {
}
func (v SelectHeroClass) onExitButtonClicked() {
d2scenemanager.SetNextScene(CreateCharacterSelect())
d2scene.SetNextScene(CreateCharacterSelect())
}
func (v SelectHeroClass) onOkButtonClicked() {
gameState := d2gamestate.CreateGameState(v.heroNameTextbox.GetText(), v.selectedHero, v.hardcoreCheckbox.GetCheckState())
d2scenemanager.SetNextScene(CreateGame(gameState))
d2scene.SetNextScene(CreateGame(gameState))
}
func (v *SelectHeroClass) Render(screen d2common.Surface) {
@ -652,27 +650,27 @@ func (v *SelectHeroClass) setDescLabels(descKey string) {
}
}
func setSpriteToFirstFrame(sprite *d2render.Sprite) {
func setSpriteToFirstFrame(sprite *d2ui.Sprite) {
if sprite != nil {
sprite.Rewind()
}
}
func drawSprite(sprite *d2render.Sprite, target d2common.Surface) {
func drawSprite(sprite *d2ui.Sprite, target d2common.Surface) {
if sprite != nil {
sprite.Render(target)
}
}
func advanceSprite(sprite *d2render.Sprite, elapsed float64) {
func advanceSprite(sprite *d2ui.Sprite, elapsed float64) {
if sprite != nil {
sprite.Advance(elapsed)
}
}
func loadSprite(animationPath, palettePath string) *d2render.Sprite {
animation, _ := d2assetmanager.LoadAnimation(animationPath, palettePath)
sprite, _ := d2render.LoadSprite(animation)
func loadSprite(animationPath, palettePath string) *d2ui.Sprite {
animation, _ := d2asset.LoadAnimation(animationPath, palettePath)
sprite, _ := d2ui.LoadSprite(animation)
return sprite
}

View File

@ -3,11 +3,10 @@ package d2player
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render/d2mapengine"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
)
type Panel interface {
@ -18,18 +17,18 @@ type Panel interface {
}
type GameControls struct {
hero *d2hero.Hero
mapEngine *d2mapengine.MapEngine
hero *d2map.Hero
mapEngine *d2map.MapEngine
inventory *Inventory
// UI
globeSprite *d2render.Sprite
mainPanel *d2render.Sprite
menuButton *d2render.Sprite
skillIcon *d2render.Sprite
globeSprite *d2ui.Sprite
mainPanel *d2ui.Sprite
menuButton *d2ui.Sprite
skillIcon *d2ui.Sprite
}
func NewGameControls(hero *d2hero.Hero, mapEngine *d2mapengine.MapEngine) *GameControls {
func NewGameControls(hero *d2map.Hero, mapEngine *d2map.MapEngine) *GameControls {
return &GameControls{
hero: hero,
mapEngine: mapEngine,
@ -57,17 +56,17 @@ func (g *GameControls) OnMouseButtonDown(event d2input.MouseEvent) bool {
}
func (g *GameControls) Load() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.GameGlobeOverlap, d2resource.PaletteSky)
g.globeSprite, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.GameGlobeOverlap, d2resource.PaletteSky)
g.globeSprite, _ = d2ui.LoadSprite(animation)
animation, _ = d2assetmanager.LoadAnimation(d2resource.GamePanels, d2resource.PaletteSky)
g.mainPanel, _ = d2render.LoadSprite(animation)
animation, _ = d2asset.LoadAnimation(d2resource.GamePanels, d2resource.PaletteSky)
g.mainPanel, _ = d2ui.LoadSprite(animation)
animation, _ = d2assetmanager.LoadAnimation(d2resource.MenuButton, d2resource.PaletteSky)
g.menuButton, _ = d2render.LoadSprite(animation)
animation, _ = d2asset.LoadAnimation(d2resource.MenuButton, d2resource.PaletteSky)
g.menuButton, _ = d2ui.LoadSprite(animation)
animation, _ = d2assetmanager.LoadAnimation(d2resource.GenericSkills, d2resource.PaletteSky)
g.skillIcon, _ = d2render.LoadSprite(animation)
animation, _ = d2asset.LoadAnimation(d2resource.GenericSkills, d2resource.PaletteSky)
g.skillIcon, _ = d2ui.LoadSprite(animation)
g.inventory.Load()
}

View File

@ -3,14 +3,14 @@ package d2player
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
)
type Inventory struct {
frame *d2render.Sprite
panel *d2render.Sprite
frame *d2ui.Sprite
panel *d2ui.Sprite
grid *ItemGrid
originX int
originY int
@ -44,18 +44,18 @@ func (g *Inventory) Close() {
}
func (g *Inventory) Load() {
animation, _ := d2assetmanager.LoadAnimation(d2resource.Frame, d2resource.PaletteSky)
g.frame, _ = d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.Frame, d2resource.PaletteSky)
g.frame, _ = d2ui.LoadSprite(animation)
animation, _ = d2assetmanager.LoadAnimation(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
g.panel, _ = d2render.LoadSprite(animation)
animation, _ = d2asset.LoadAnimation(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
g.panel, _ = d2ui.LoadSprite(animation)
items := []InventoryItem{
d2hero.GetWeaponItemByCode("wnd"),
d2hero.GetWeaponItemByCode("sst"),
d2hero.GetWeaponItemByCode("jav"),
d2hero.GetArmorItemByCode("buc"),
d2hero.GetWeaponItemByCode("clb"),
d2inventory.GetWeaponItemByCode("wnd"),
d2inventory.GetWeaponItemByCode("sst"),
d2inventory.GetWeaponItemByCode("jav"),
d2inventory.GetArmorItemByCode("buc"),
d2inventory.GetWeaponItemByCode("clb"),
}
g.grid.Add(items...)
}

View File

@ -5,12 +5,12 @@ import (
"fmt"
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
type InventoryItem interface {
@ -30,7 +30,7 @@ type ItemGrid struct {
height int
originX int
originY int
sprites map[string]*d2render.Sprite
sprites map[string]*d2ui.Sprite
slotSize int
}
@ -41,7 +41,7 @@ func NewItemGrid(width int, height int, originX int, originY int) *ItemGrid {
originX: originX,
originY: originY,
slotSize: 29,
sprites: make(map[string]*d2render.Sprite),
sprites: make(map[string]*d2ui.Sprite),
}
}
@ -92,7 +92,7 @@ func (g *ItemGrid) Add(items ...InventoryItem) (int, error) {
// Load reads the inventory sprites for items into local cache for rendering.
func (g *ItemGrid) Load(items ...InventoryItem) {
var itemSprite *d2render.Sprite
var itemSprite *d2ui.Sprite
for _, item := range items {
if _, exists := g.sprites[item.ItemCode()]; exists {
@ -101,7 +101,7 @@ func (g *ItemGrid) Load(items ...InventoryItem) {
}
// TODO: Put the pattern into D2Shared
animation, err := d2assetmanager.LoadAnimation(
animation, err := d2asset.LoadAnimation(
fmt.Sprintf("/data/global/items/inv%s.dc6", item.ItemCode()),
d2resource.PaletteSky,
)
@ -109,7 +109,7 @@ func (g *ItemGrid) Load(items ...InventoryItem) {
log.Printf("failed to load sprite for item (%s): %v", item.ItemCode(), err)
continue
}
itemSprite, err = d2render.LoadSprite(animation)
itemSprite, err = d2ui.LoadSprite(animation)
g.sprites[item.ItemCode()] = itemSprite
}

12
go.sum
View File

@ -12,28 +12,25 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 h1:b+9H1GAsx5RsjvDFLoS5zkNBzIQMuVKUYQDmxU3N5XE=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-restruct/restruct v0.0.0-20191018101351-5fb876c952c9 h1:f25lTFrAliLucJ3G6a9PcgyaGXA6omEF+682jgfC+7U=
github.com/go-restruct/restruct v0.0.0-20191018101351-5fb876c952c9/go.mod h1:KqrpKpn4M8OLznErihXTGLlsXFGeLxHUrLRRI/1YjGk=
github.com/go-restruct/restruct v0.0.0-20191227155143-5734170a48a1 h1:LoN2wx/aN8JPGebG+2DaUyk4M+xRcqJXfuIbs8AWHdE=
github.com/go-restruct/restruct v0.0.0-20191227155143-5734170a48a1/go.mod h1:KqrpKpn4M8OLznErihXTGLlsXFGeLxHUrLRRI/1YjGk=
github.com/gofrs/flock v0.7.1 h1:DP+LD/t0njgoPBvT5MJLeliUIVQR03hiKR6vezdwHlc=
github.com/gofrs/flock v0.7.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/hajimehoshi/bitmapfont v1.2.0/go.mod h1:h9QrPk6Ktb2neObTlAbma6Ini1xgMjbJ3w7ysmD7IOU=
github.com/hajimehoshi/ebiten v1.10.3 h1:ywrEsXclsjrdKIhYYrmy/yxLFCd1y4efGVsnFRl8OLU=
github.com/hajimehoshi/ebiten v1.10.3/go.mod h1:i9dIEUf5/MuPtbK1/wHR0PB7ZtqhjOxxg+U1xfxapcY=
github.com/hajimehoshi/ebiten v1.11.0-alpha.2.0.20200102072751-e66f1fb71e2e h1:NRGAeXOSMrAo0f4GPaUoiF61eo0wWrfgONPSTZA6Zhg=
github.com/hajimehoshi/ebiten v1.11.0-alpha.2.0.20200102072751-e66f1fb71e2e/go.mod h1:0SLvfr8iI2NxzpNB/olBM+dLN9Ur5a9szG13wOgQ0nQ=
github.com/hajimehoshi/go-mp3 v0.2.1/go.mod h1:Rr+2P46iH6PwTPVgSsEwBkon0CK5DxCAeX/Rp65DCTE=
github.com/hajimehoshi/oto v0.3.4 h1:FSlftYfESnZgI1ghi6WLMqVMjTrl9i8nRri3bL4Bdhs=
github.com/hajimehoshi/oto v0.3.4/go.mod h1:PgjqsBJff0efqL2nlMJidJgVJywLn6M4y8PI4TfeWfA=
github.com/hajimehoshi/oto v0.5.4 h1:Dn+WcYeF310xqStKm0tnvoruYUV5Sce8+sfUaIvWGkE=
github.com/hajimehoshi/oto v0.5.4/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/jakecoffman/cp v0.1.0/go.mod h1:a3xPx9N8RyFAACD644t2dj/nK4SuLg1v+jL61m2yVo4=
github.com/jfreymuth/oggvorbis v1.0.0/go.mod h1:abe6F9QRjuU9l+2jek3gj46lu40N4qlYxh2grqkLEDM=
github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
@ -47,18 +44,15 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 h1:A1gGSx58LAGVHUUsOf7IiR0u8Xb6W51gRwfDBhkdcaw=
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20191025110607-73ccc5ba0426/go.mod h1:p895TfNkDgPEmEQrNiOtIl3j98d/tGU95djDj7NfyjQ=
golang.org/x/mobile v0.0.0-20191115022231-f0c40035f2ba h1:NVszahdZPQTROdO0F5gnXdZhGl2lXFb9w7Ek1F2Pbmk=
golang.org/x/mobile v0.0.0-20191115022231-f0c40035f2ba/go.mod h1:p895TfNkDgPEmEQrNiOtIl3j98d/tGU95djDj7NfyjQ=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@ -70,7 +64,6 @@ golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191115151921-52ab43148777 h1:wejkGHRTr38uaKRqECZlsCsJ1/TGxIyFbH32x5zUdu4=
golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
@ -81,7 +74,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

96
main.go
View File

@ -3,38 +3,28 @@ package main
import (
"log"
ebiten2 "github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio/ebiten"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2assetmanager"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scenemanager"
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2game"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render/ebiten"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2term"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2gamescene"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
ebiten2 "github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio/ebiten"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render/ebiten"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2term"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2game"
)
// GitBranch is set by the CI build process to the name of the branch
@ -48,9 +38,9 @@ var preset = kingpin.Arg("preset", "Level preset").Int()
func main() {
if len(GitBranch) == 0 {
GitBranch = "Local Build"
GitCommit = ""
}
GitBranch = "Local Build"
GitCommit = ""
}
d2common.SetBuildInfo(GitBranch, GitCommit)
log.SetFlags(log.Lshortfile)
log.Println("OpenDiablo2 - Open source Diablo 2 engine")
@ -67,9 +57,9 @@ func main() {
kingpin.Parse()
if *region == 0 {
d2scenemanager.SetNextScene(d2scene.CreateMainMenu())
d2scene.SetNextScene(d2gamescene.CreateMainMenu())
} else {
d2scenemanager.SetNextScene(d2scene.CreateMapEngineTest(*region, *preset))
d2scene.SetNextScene(d2gamescene.CreateMapEngineTest(*region, *preset))
}
err = d2game.Run(GitBranch)
if err != nil {
@ -89,7 +79,7 @@ func loadTextDictionary() bool {
}
for _, item := range toLoad {
fileData, err = d2assetmanager.LoadFile(item)
fileData, err = d2asset.LoadFile(item)
if err != nil {
log.Fatal(err)
return false
@ -107,7 +97,7 @@ func loadPalettes() bool {
} {
filePath := `data\global\palette\` + pal + `\pal.dat`
paletteType := d2enum.PaletteType(pal)
file, _ := d2assetmanager.LoadFile(filePath)
file, _ := d2asset.LoadFile(filePath)
d2datadict.LoadPalette(paletteType, file)
}
log.Printf("Loaded %d palettes", len(d2datadict.Palettes))
@ -143,7 +133,7 @@ func initializeEverything() error {
}
d2term.BindLogger()
d2assetmanager.Initialize()
d2asset.Initialize()
err = d2render.SetWindowIcon("d2logo.png")
if err != nil {
@ -172,86 +162,86 @@ func initializeEverything() error {
loadTextDictionary()
file, err = d2assetmanager.LoadFile(d2resource.LevelType)
file, err = d2asset.LoadFile(d2resource.LevelType)
if err != nil {
return err
}
d2datadict.LoadLevelTypes(file)
file, err = d2assetmanager.LoadFile(d2resource.LevelPreset)
file, err = d2asset.LoadFile(d2resource.LevelPreset)
if err != nil {
return err
}
d2datadict.LoadLevelPresets(file)
file, err = d2assetmanager.LoadFile(d2resource.LevelWarp)
file, err = d2asset.LoadFile(d2resource.LevelWarp)
if err != nil {
return err
}
d2datadict.LoadLevelWarps(file)
file, err = d2assetmanager.LoadFile(d2resource.ObjectType)
file, err = d2asset.LoadFile(d2resource.ObjectType)
if err != nil {
return err
}
d2datadict.LoadObjectTypes(file)
file, err = d2assetmanager.LoadFile(d2resource.ObjectDetails)
file, err = d2asset.LoadFile(d2resource.ObjectDetails)
if err != nil {
return err
}
d2datadict.LoadObjects(file)
file, err = d2assetmanager.LoadFile(d2resource.Weapons)
file, err = d2asset.LoadFile(d2resource.Weapons)
if err != nil {
return err
}
d2datadict.LoadWeapons(file)
file, err = d2assetmanager.LoadFile(d2resource.Armor)
file, err = d2asset.LoadFile(d2resource.Armor)
if err != nil {
return err
}
d2datadict.LoadArmors(file)
file, err = d2assetmanager.LoadFile(d2resource.Misc)
file, err = d2asset.LoadFile(d2resource.Misc)
if err != nil {
return err
}
d2datadict.LoadMiscItems(file)
file, err = d2assetmanager.LoadFile(d2resource.UniqueItems)
file, err = d2asset.LoadFile(d2resource.UniqueItems)
if err != nil {
return err
}
d2datadict.LoadUniqueItems(file)
file, err = d2assetmanager.LoadFile(d2resource.Missiles)
file, err = d2asset.LoadFile(d2resource.Missiles)
if err != nil {
return err
}
d2datadict.LoadMissiles(file)
file, err = d2assetmanager.LoadFile(d2resource.SoundSettings)
file, err = d2asset.LoadFile(d2resource.SoundSettings)
if err != nil {
return err
}
d2datadict.LoadSounds(file)
file, err = d2assetmanager.LoadFile(d2resource.AnimationData)
file, err = d2asset.LoadFile(d2resource.AnimationData)
if err != nil {
return err
}
d2data.LoadAnimationData(file)
file, err = d2assetmanager.LoadFile(d2resource.MonStats)
file, err = d2asset.LoadFile(d2resource.MonStats)
if err != nil {
return err
}
d2datadict.LoadMonStats(file)
animation, _ := d2assetmanager.LoadAnimation(d2resource.LoadingScreen, d2resource.PaletteLoading)
loadingSprite, _ := d2render.LoadSprite(animation)
animation, _ := d2asset.LoadAnimation(d2resource.LoadingScreen, d2resource.PaletteLoading)
loadingSprite, _ := d2ui.LoadSprite(animation)
loadingSpriteSizeX, loadingSpriteSizeY := loadingSprite.GetCurrentFrameSize()
loadingSprite.SetPosition(int(400-(loadingSpriteSizeX/2)), int(300+(loadingSpriteSizeY/2)))
err = d2game.Initialize(loadingSprite)
@ -259,8 +249,8 @@ func initializeEverything() error {
return err
}
animation, _ = d2assetmanager.LoadAnimation(d2resource.CursorDefault, d2resource.PaletteUnits)
cursorSprite, _ := d2render.LoadSprite(animation)
animation, _ = d2asset.LoadAnimation(d2resource.CursorDefault, d2resource.PaletteUnits)
cursorSprite, _ := d2ui.LoadSprite(animation)
d2ui.Initialize(cursorSprite)
d2term.BindAction("timescale", "set scalar for elapsed time", func(scale float64) {