mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-11 11:57:44 -05:00
Adds error handling everywhere (#743)
* adds error handling, returns early from funcs where it makes sense * fixes build errors * merge ballresin PR with upstream * adds error handling, returns early from funcs where it makes sense * fixes build errors * merge ballresin PR with upstream Co-authored-by: dknuth <dknuth0101@gmail.com>
This commit is contained in:
parent
a5f9067248
commit
ca45be0948
17
d2app/app.go
17
d2app/app.go
@ -362,7 +362,10 @@ func (a *App) dumpHeap() {
|
||||
}
|
||||
}
|
||||
|
||||
fileOut, _ := os.Create("./pprof/heap.pprof")
|
||||
fileOut, err := os.Create("./pprof/heap.pprof")
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
if err := pprof.WriteHeapProfile(fileOut); err != nil {
|
||||
log.Fatal(err)
|
||||
@ -569,7 +572,10 @@ func enableProfiler(profileOption string) interface{ Stop() } {
|
||||
}
|
||||
|
||||
func updateInitError(target d2interface.Surface) error {
|
||||
_ = target.Clear(colornames.Darkred)
|
||||
err := target.Clear(colornames.Darkred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
target.PushTranslation(errMsgPadding, errMsgPadding)
|
||||
target.DrawTextf(`Could not find the MPQ files in the directory:
|
||||
@ -604,9 +610,12 @@ func (a *App) ToSelectHero(connType d2clientconnectiontype.ClientConnectionType,
|
||||
|
||||
// ToCreateGame forces the game to transition to the Create Game screen
|
||||
func (a *App) ToCreateGame(filePath string, connType d2clientconnectiontype.ClientConnectionType, host string) {
|
||||
gameClient, _ := d2client.Create(connType, a.asset, a.scriptEngine)
|
||||
gameClient, err := d2client.Create(connType, a.asset, a.scriptEngine)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
if err := gameClient.Open(host, filePath); err != nil {
|
||||
if err = gameClient.Open(host, filePath); err != nil {
|
||||
// TODO an error screen should be shown in this case
|
||||
fmt.Printf("can not connect to the host: %s", host)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package d2animdata
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
@ -30,7 +31,11 @@ func TestLoad(t *testing.T) {
|
||||
t.Error(loadErr)
|
||||
}
|
||||
|
||||
_ = testFile.Close()
|
||||
err := testFile.Close()
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad_BadData(t *testing.T) {
|
||||
@ -58,7 +63,11 @@ func TestLoad_BadData(t *testing.T) {
|
||||
t.Error("bad data file should not be parsed")
|
||||
}
|
||||
|
||||
_ = testFile.Close()
|
||||
err := testFile.Close()
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnimationData_GetRecordNames(t *testing.T) {
|
||||
|
@ -158,13 +158,17 @@ func (v *MPQ) readHeader() error {
|
||||
return errors.New("invalid mpq header")
|
||||
}
|
||||
|
||||
v.loadHashTable()
|
||||
err = v.loadHashTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v.loadBlockTable()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *MPQ) loadHashTable() {
|
||||
func (v *MPQ) loadHashTable() error {
|
||||
_, err := v.file.Seek(int64(v.data.HashTableOffset), 0)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
@ -174,7 +178,11 @@ func (v *MPQ) loadHashTable() {
|
||||
hash := make([]byte, 4)
|
||||
|
||||
for i := range hashData {
|
||||
_, _ = v.file.Read(hash)
|
||||
_, err := v.file.Read(hash)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
hashData[i] = binary.LittleEndian.Uint32(hash)
|
||||
}
|
||||
|
||||
@ -190,6 +198,8 @@ func (v *MPQ) loadHashTable() {
|
||||
BlockIndex: hashData[(i*4)+3],
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *MPQ) loadBlockTable() {
|
||||
@ -202,7 +212,10 @@ func (v *MPQ) loadBlockTable() {
|
||||
hash := make([]byte, 4)
|
||||
|
||||
for i := range blockData {
|
||||
_, _ = v.file.Read(hash[:]) //nolint:errcheck Will fix later
|
||||
_, err = v.file.Read(hash[:]) //nolint:errcheck Will fix later
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
blockData[i] = binary.LittleEndian.Uint32(hash)
|
||||
}
|
||||
|
||||
|
@ -62,11 +62,17 @@ func (v *Stream) loadBlockOffsets() error {
|
||||
blockPositionCount := ((v.BlockTableEntry.UncompressedFileSize + v.BlockSize - 1) / v.BlockSize) + 1
|
||||
v.BlockPositions = make([]uint32, blockPositionCount)
|
||||
|
||||
_, _ = v.MPQData.file.Seek(int64(v.BlockTableEntry.FilePosition), 0)
|
||||
_, err := v.MPQData.file.Seek(int64(v.BlockTableEntry.FilePosition), 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mpqBytes := make([]byte, blockPositionCount*4) //nolint:gomnd MPQ magic
|
||||
|
||||
_, _ = v.MPQData.file.Read(mpqBytes)
|
||||
_, err = v.MPQData.file.Read(mpqBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range v.BlockPositions {
|
||||
idx := i * 4 //nolint:gomnd MPQ magic
|
||||
@ -160,8 +166,14 @@ func (v *Stream) bufferData() {
|
||||
|
||||
func (v *Stream) loadSingleUnit() {
|
||||
fileData := make([]byte, v.BlockSize)
|
||||
_, _ = v.MPQData.file.Seek(int64(v.MPQData.data.HeaderSize), 0)
|
||||
_, _ = v.MPQData.file.Read(fileData)
|
||||
_, err := v.MPQData.file.Seek(int64(v.MPQData.data.HeaderSize), 0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
_, err = v.MPQData.file.Read(fileData)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
if v.BlockSize == v.BlockTableEntry.UncompressedFileSize {
|
||||
v.CurrentData = fileData
|
||||
@ -188,8 +200,14 @@ func (v *Stream) loadBlock(blockIndex, expectedLength uint32) []byte {
|
||||
offset += v.BlockTableEntry.FilePosition
|
||||
data := make([]byte, toRead)
|
||||
|
||||
_, _ = v.MPQData.file.Seek(int64(offset), 0)
|
||||
_, _ = v.MPQData.file.Read(data)
|
||||
_, err := v.MPQData.file.Seek(int64(offset), 0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
_, err = v.MPQData.file.Read(data)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
if v.BlockTableEntry.HasFlag(FileEncrypted) && v.BlockTableEntry.UncompressedFileSize > 3 {
|
||||
if v.EncryptionSeed == 0 {
|
||||
|
@ -2,6 +2,7 @@ package d2loader
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2loader/asset"
|
||||
@ -83,11 +84,26 @@ func TestLoader_AddSource(t *testing.T) {
|
||||
func TestLoader_Load(t *testing.T) {
|
||||
loader := NewLoader(nil)
|
||||
|
||||
_, _ = loader.AddSource(sourcePathB) // we expect files common to any source to come from here
|
||||
_, _ = loader.AddSource(sourcePathD)
|
||||
_, _ = loader.AddSource(sourcePathA)
|
||||
_, _ = loader.AddSource(sourcePathC)
|
||||
|
||||
_, err := loader.AddSource(sourcePathB) // we expect files common to any source to come from here
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
log.Print(err)
|
||||
}
|
||||
_, err = loader.AddSource(sourcePathD)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
log.Print(err)
|
||||
}
|
||||
_, err = loader.AddSource(sourcePathA)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
log.Print(err)
|
||||
}
|
||||
_, err = loader.AddSource(sourcePathC)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
log.Print(err)
|
||||
}
|
||||
entryCommon, errCommon := loader.Load(commonFile) // common file exists in all three Sources
|
||||
|
||||
entryA, errA := loader.Load(exclusiveA) // each source has a file exclusive to itself
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"image"
|
||||
"log"
|
||||
|
||||
"golang.org/x/image/bmp"
|
||||
)
|
||||
@ -48,7 +49,10 @@ func CreateTextImage() image.Image {
|
||||
panic(fmt.Sprintf("assets: bmp.Decode failed: %v", err))
|
||||
}
|
||||
|
||||
_ = s.Close()
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return debugBmp
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package d2util
|
||||
|
||||
import (
|
||||
"image"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util/assets"
|
||||
|
||||
@ -90,7 +91,10 @@ func (p *GlyphPrinter) drawDebugText(target *ebiten.Image, str string, ox, oy in
|
||||
op.GeoM.Translate(float64(ox+1), float64(oy))
|
||||
|
||||
op.CompositeMode = ebiten.CompositeModeLighter
|
||||
_ = target.DrawImage(s, op)
|
||||
err := target.DrawImage(s, op)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
x += cw
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package d2util
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
)
|
||||
|
||||
// LogLevel determines how verbose the logging is (higher is more verbose)
|
||||
@ -93,7 +94,10 @@ func (l *Logger) print(level LogLevel, msg string) {
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = l.Write(format(fmtString, []byte(msg)))
|
||||
_, err := l.Write(format(fmtString, []byte(msg)))
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
func format(fmtStr string, fmtInput []byte) []byte {
|
||||
|
@ -1,6 +1,10 @@
|
||||
package d2util
|
||||
|
||||
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
)
|
||||
|
||||
func ImgIndexToRGBA(indexData []byte, palette d2interface.Palette) []byte {
|
||||
bytesPerPixel := 4
|
||||
@ -12,7 +16,10 @@ func ImgIndexToRGBA(indexData []byte, palette d2interface.Palette) []byte {
|
||||
continue
|
||||
}
|
||||
|
||||
c, _ := palette.GetColor(int(indexData[i]))
|
||||
c, err := palette.GetColor(int(indexData[i]))
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
colorData[i*bytesPerPixel] = c.R()
|
||||
colorData[i*bytesPerPixel+1] = c.G()
|
||||
colorData[i*bytesPerPixel+2] = c.B()
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"image"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
@ -137,7 +138,10 @@ func (a *Animation) renderShadow(target d2interface.Surface) error {
|
||||
// Render renders the animation to the given surface
|
||||
func (a *Animation) Render(target d2interface.Surface) error {
|
||||
if a.renderer == nil {
|
||||
a.BindRenderer(target.Renderer())
|
||||
err := a.BindRenderer(target.Renderer())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
direction := a.directions[a.directionIndex]
|
||||
@ -168,7 +172,10 @@ func (a *Animation) BindRenderer(r d2interface.Renderer) error {
|
||||
// RenderFromOrigin renders the animation from the animation origin
|
||||
func (a *Animation) RenderFromOrigin(target d2interface.Surface, shadow bool) error {
|
||||
if a.renderer == nil {
|
||||
a.BindRenderer(target.Renderer())
|
||||
err := a.BindRenderer(target.Renderer())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if a.originAtBottom {
|
||||
@ -195,7 +202,10 @@ func (a *Animation) RenderFromOrigin(target d2interface.Surface, shadow bool) er
|
||||
// RenderSection renders the section of the animation frame enclosed by bounds
|
||||
func (a *Animation) RenderSection(sfc d2interface.Surface, bound image.Rectangle) error {
|
||||
if a.renderer == nil {
|
||||
a.BindRenderer(sfc.Renderer())
|
||||
err := a.BindRenderer(sfc.Renderer())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
direction := a.directions[a.directionIndex]
|
||||
@ -224,7 +234,10 @@ func (a *Animation) GetFrameSize(frameIndex int) (width, height int, err error)
|
||||
|
||||
// GetCurrentFrameSize gets the Size(width, height) of the current frame.
|
||||
func (a *Animation) GetCurrentFrameSize() (width, height int) {
|
||||
width, height, _ = a.GetFrameSize(a.frameIndex)
|
||||
width, height, err := a.GetFrameSize(a.frameIndex)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
return width, height
|
||||
}
|
||||
|
||||
@ -300,7 +313,10 @@ func (a *Animation) SetCurrentFrame(frameIndex int) error {
|
||||
|
||||
// Rewind animation to beginning
|
||||
func (a *Animation) Rewind() {
|
||||
_ = a.SetCurrentFrame(0)
|
||||
err := a.SetCurrentFrame(0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
// PlayForward plays animation forward
|
||||
|
@ -232,8 +232,8 @@ type compositeMode struct {
|
||||
|
||||
func (c *Composite) createMode(animationMode animationMode, weaponClass string) (*compositeMode, error) {
|
||||
cofPath := fmt.Sprintf("%s/%s/COF/%s%s%s.COF", c.basePath, c.token, c.token, animationMode, weaponClass)
|
||||
if exists, _ := c.FileExists(cofPath); !exists {
|
||||
return nil, errors.New("composite not found")
|
||||
if exists, err := c.FileExists(cofPath); !exists {
|
||||
return nil, fmt.Errorf("composite not found at path '%s': %v", cofPath, err)
|
||||
}
|
||||
|
||||
cof, err := c.loadCOF(cofPath)
|
||||
@ -295,16 +295,18 @@ func (c *Composite) loadCompositeLayer(layerKey, layerValue, animationMode, weap
|
||||
}
|
||||
|
||||
for _, animationPath := range animationPaths {
|
||||
if exists, _ := c.FileExists(animationPath); exists {
|
||||
animation, err := c.LoadAnimationWithEffect(animationPath, palettePath,
|
||||
drawEffect)
|
||||
|
||||
if exists, err := c.FileExists(animationPath); exists && err == nil {
|
||||
animation, err := c.LoadAnimationWithEffect(animationPath, palettePath, drawEffect)
|
||||
if err == nil {
|
||||
return animation, nil
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("animation path '%s' not found: %v", animationPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.New("Animation not found")
|
||||
return nil, errors.New("animation not found")
|
||||
}
|
||||
|
||||
// GetSize returns the size of the composite
|
||||
|
@ -51,7 +51,10 @@ func (eap *AudioProvider) PlayBGM(song string) {
|
||||
eap.lastBgm = song
|
||||
|
||||
if song == "" && eap.bgmAudio != nil && eap.bgmAudio.IsPlaying() {
|
||||
_ = eap.bgmAudio.Pause()
|
||||
err := eap.bgmAudio.Pause()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -115,22 +115,40 @@ func NewSoundEngine(provider d2interface.AudioProvider,
|
||||
timer: 1,
|
||||
}
|
||||
|
||||
_ = term.BindAction("playsoundid", "plays the sound for a given id", func(id int) {
|
||||
err := term.BindAction("playsoundid", "plays the sound for a given id", func(id int) {
|
||||
r.PlaySoundID(id)
|
||||
})
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = term.BindAction("playsound", "plays the sound for a given handle string", func(handle string) {
|
||||
err = term.BindAction("playsound", "plays the sound for a given handle string", func(handle string) {
|
||||
r.PlaySoundHandle(handle)
|
||||
})
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = term.BindAction("activesounds", "list currently active sounds", func() {
|
||||
err = term.BindAction("activesounds", "list currently active sounds", func() {
|
||||
for s := range r.sounds {
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
log.Println(s)
|
||||
}
|
||||
})
|
||||
|
||||
_ = term.BindAction("killsounds", "kill active sounds", func() {
|
||||
err = term.BindAction("killsounds", "kill active sounds", func() {
|
||||
for s := range r.sounds {
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
s.Stop()
|
||||
}
|
||||
})
|
||||
@ -185,7 +203,11 @@ func (s *SoundEngine) PlaySoundID(id int) *Sound {
|
||||
entry = s.asset.Records.SelectSoundByIndex(entry.Index + rand.Intn(entry.GroupSize))
|
||||
}
|
||||
|
||||
effect, _ := s.provider.LoadSound(entry.FileName, entry.Loop, entry.MusicVol)
|
||||
effect, err := s.provider.LoadSound(entry.FileName, entry.Loop, entry.MusicVol)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
snd := Sound{
|
||||
entry: entry,
|
||||
|
@ -2,6 +2,7 @@ package d2gui
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
@ -163,7 +164,10 @@ func (m *GuiManager) ShowLoadScreen(progress float64) {
|
||||
animation := m.loadingAnim
|
||||
frameCount := animation.GetFrameCount()
|
||||
|
||||
_ = animation.SetCurrentFrame(int(float64(frameCount-1) * progress))
|
||||
err := animation.SetCurrentFrame(int(float64(frameCount-1) * progress))
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
m.loading = true
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package d2gui
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
@ -22,7 +24,11 @@ func createLabel(renderer d2interface.Renderer, text string, font *d2asset.Font)
|
||||
renderer: renderer,
|
||||
}
|
||||
|
||||
_ = label.setText(text)
|
||||
err := label.setText(text)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
label.SetVisible(true)
|
||||
|
||||
return label
|
||||
|
@ -85,7 +85,10 @@ func (m *MapEngine) addDT1(fileName string) {
|
||||
return
|
||||
}
|
||||
|
||||
dt1, _ := d2dt1.LoadDT1(fileData)
|
||||
dt1, err := d2dt1.LoadDT1(fileData)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
m.dt1TileData = append(m.dt1TileData, dt1.Tiles...)
|
||||
m.dt1Files = append(m.dt1Files, fileName)
|
||||
}
|
||||
@ -103,7 +106,10 @@ func (m *MapEngine) AddDS1(fileName string) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ds1, _ := d2ds1.LoadDS1(fileData)
|
||||
ds1, err := d2ds1.LoadDS1(fileData)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
for idx := range ds1.Files {
|
||||
dt1File := ds1.Files[idx]
|
||||
|
@ -190,8 +190,11 @@ func (f *MapEntityFactory) NewNPC(x, y int, monstat *d2records.MonStatsRecord, d
|
||||
equipment[compType] = selectEquip(opts)
|
||||
}
|
||||
|
||||
composite, _ := f.asset.LoadComposite(d2enum.ObjectTypeCharacter, monstat.AnimationDirectoryToken,
|
||||
composite, err := f.asset.LoadComposite(d2enum.ObjectTypeCharacter, monstat.AnimationDirectoryToken,
|
||||
d2resource.PaletteUnits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.composite = composite
|
||||
|
||||
if err := composite.SetMode(d2enum.MonsterAnimationModeNeutral,
|
||||
@ -235,9 +238,15 @@ func (f *MapEntityFactory) NewObject(x, y int, objectRec *d2records.ObjectDetail
|
||||
|
||||
entity.composite = composite
|
||||
|
||||
_ = entity.setMode(d2enum.ObjectAnimationModeNeutral, 0, false)
|
||||
err = entity.setMode(d2enum.ObjectAnimationModeNeutral, 0, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, _ = initObject(entity)
|
||||
_, err = initObject(entity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return entity, nil
|
||||
}
|
||||
|
@ -12,7 +12,11 @@ import (
|
||||
)
|
||||
|
||||
func (mr *MapRenderer) generateTileCache() {
|
||||
mr.palette, _ = mr.loadPaletteForAct(d2enum.RegionIdType(mr.mapEngine.LevelType().ID))
|
||||
var err error
|
||||
mr.palette, err = mr.loadPaletteForAct(d2enum.RegionIdType(mr.mapEngine.LevelType().ID))
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
tiles := *mr.mapEngine.Tiles()
|
||||
for idx := range tiles {
|
||||
@ -83,12 +87,19 @@ func (mr *MapRenderer) generateFloorCache(tile *d2ds1.FloorShadowRecord) {
|
||||
|
||||
tileYOffset := d2math.AbsInt32(tileYMinimum)
|
||||
tileHeight := d2math.AbsInt32(tileData[i].Height)
|
||||
image, _ := mr.renderer.NewSurface(int(tileData[i].Width), int(tileHeight), d2enum.FilterNearest)
|
||||
image, err := mr.renderer.NewSurface(int(tileData[i].Width), int(tileHeight), d2enum.FilterNearest)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
indexData := make([]byte, tileData[i].Width*tileHeight)
|
||||
d2dt1.DecodeTileGfxData(tileData[i].Blocks, &indexData, tileYOffset, tileData[i].Width)
|
||||
pixels := d2util.ImgIndexToRGBA(indexData, mr.palette)
|
||||
|
||||
_ = image.ReplacePixels(pixels)
|
||||
err = image.ReplacePixels(pixels)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
mr.setImageCacheRecord(tile.Style, tile.Sequence, 0, tileIndex, image)
|
||||
}
|
||||
}
|
||||
@ -125,11 +136,20 @@ func (mr *MapRenderer) generateShadowCache(tile *d2ds1.FloorShadowRecord) {
|
||||
return
|
||||
}
|
||||
|
||||
image, _ := mr.renderer.NewSurface(int(tileData.Width), tileHeight, d2enum.FilterNearest)
|
||||
image, err := mr.renderer.NewSurface(int(tileData.Width), tileHeight, d2enum.FilterNearest)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
indexData := make([]byte, tileData.Width*int32(tileHeight))
|
||||
d2dt1.DecodeTileGfxData(tileData.Blocks, &indexData, tileYOffset, tileData.Width)
|
||||
pixels := d2util.ImgIndexToRGBA(indexData, mr.palette)
|
||||
_ = image.ReplacePixels(pixels)
|
||||
|
||||
err = image.ReplacePixels(pixels)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
mr.setImageCacheRecord(tile.Style, tile.Sequence, 13, tile.RandomIndex, image)
|
||||
}
|
||||
|
||||
@ -184,7 +204,11 @@ func (mr *MapRenderer) generateWallCache(tile *d2ds1.WallRecord) {
|
||||
return
|
||||
}
|
||||
|
||||
image, _ := mr.renderer.NewSurface(160, int(realHeight), d2enum.FilterNearest)
|
||||
image, err := mr.renderer.NewSurface(160, int(realHeight), d2enum.FilterNearest)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
indexData := make([]byte, 160*realHeight)
|
||||
|
||||
d2dt1.DecodeTileGfxData(tileData.Blocks, &indexData, tileYOffset, 160)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package d2mapstamp
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
|
||||
@ -38,7 +39,11 @@ func (f *StampFactory) LoadStamp(levelType d2enum.RegionIdType, levelPreset, fil
|
||||
panic(err)
|
||||
}
|
||||
|
||||
dt1, _ := d2dt1.LoadDT1(fileData)
|
||||
dt1, err := d2dt1.LoadDT1(fileData)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
stamp.tiles = append(stamp.tiles, dt1.Tiles...)
|
||||
}
|
||||
@ -68,7 +73,11 @@ func (f *StampFactory) LoadStamp(levelType d2enum.RegionIdType, levelPreset, fil
|
||||
panic(err)
|
||||
}
|
||||
|
||||
stamp.ds1, _ = d2ds1.LoadDS1(fileData)
|
||||
stamp.ds1, err = d2ds1.LoadDS1(fileData)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return stamp
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package d2records
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
@ -12,7 +13,10 @@ import (
|
||||
func TestIndexObjects(t *testing.T) {
|
||||
assert := testify.New(t)
|
||||
|
||||
r, _ := NewRecordManager()
|
||||
r, err := NewRecordManager()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
testObjects := []ObjectLookupRecord{
|
||||
{Act: 1, Type: d2enum.ObjectTypeCharacter, Id: 0, Description: "Act1CharId0"},
|
||||
|
@ -3,6 +3,7 @@ package d2ui
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
@ -207,19 +208,36 @@ func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button {
|
||||
lbl.Color[0] = d2util.Color(greyAlpha100)
|
||||
lbl.Alignment = d2gui.HorizontalAlignCenter
|
||||
|
||||
buttonSprite, _ := ui.NewSprite(buttonLayout.ResourceName, buttonLayout.PaletteName)
|
||||
buttonSprite, err := ui.NewSprite(buttonLayout.ResourceName, buttonLayout.PaletteName)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
for i := 0; i < buttonLayout.XSegments; i++ {
|
||||
w, _, _ := buttonSprite.GetFrameSize(i)
|
||||
w, _, err := buttonSprite.GetFrameSize(i)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
btn.width += w
|
||||
}
|
||||
|
||||
for i := 0; i < buttonLayout.YSegments; i++ {
|
||||
_, h, _ := buttonSprite.GetFrameSize(i * buttonLayout.YSegments)
|
||||
_, h, err := buttonSprite.GetFrameSize(i * buttonLayout.YSegments)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
btn.height += h
|
||||
}
|
||||
|
||||
btn.normalSurface, _ = ui.renderer.NewSurface(btn.width, btn.height, d2enum.FilterNearest)
|
||||
btn.normalSurface, err = ui.renderer.NewSurface(btn.width, btn.height, d2enum.FilterNearest)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
buttonSprite.SetPosition(0, 0)
|
||||
buttonSprite.SetEffect(d2enum.DrawEffectModulate)
|
||||
@ -232,9 +250,9 @@ func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button {
|
||||
}
|
||||
|
||||
func (v *Button) renderFrames(btnSprite *Sprite, btnLayout *ButtonLayout, label *Label) {
|
||||
var err error
|
||||
totalButtonTypes := btnSprite.GetFrameCount() / (btnLayout.XSegments * btnLayout.YSegments)
|
||||
|
||||
var err error
|
||||
err = btnSprite.RenderSegmented(v.normalSurface, btnLayout.XSegments, btnLayout.YSegments, btnLayout.BaseFrame)
|
||||
|
||||
if err != nil {
|
||||
@ -256,10 +274,13 @@ func (v *Button) renderFrames(btnSprite *Sprite, btnLayout *ButtonLayout, label
|
||||
if totalButtonTypes > 0 { // button has more than one type
|
||||
frameOffset++
|
||||
|
||||
v.pressedSurface, _ = v.manager.renderer.NewSurface(v.width, v.height,
|
||||
v.pressedSurface, err = v.manager.renderer.NewSurface(v.width, v.height,
|
||||
d2enum.FilterNearest)
|
||||
err = btnSprite.RenderSegmented(v.pressedSurface, xSeg, ySeg, baseFrame+frameOffset)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
err = btnSprite.RenderSegmented(v.pressedSurface, xSeg, ySeg, baseFrame+frameOffset)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to render button pressedSurface, err: %v\n", err)
|
||||
}
|
||||
@ -279,10 +300,13 @@ func (v *Button) renderFrames(btnSprite *Sprite, btnLayout *ButtonLayout, label
|
||||
if totalButtonTypes > 0 { // button has more than two types
|
||||
frameOffset++
|
||||
|
||||
v.toggledSurface, _ = v.manager.renderer.NewSurface(v.width, v.height,
|
||||
v.toggledSurface, err = v.manager.renderer.NewSurface(v.width, v.height,
|
||||
d2enum.FilterNearest)
|
||||
err = btnSprite.RenderSegmented(v.pressedSurface, xSeg, ySeg, baseFrame+frameOffset)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
err = btnSprite.RenderSegmented(v.pressedSurface, xSeg, ySeg, baseFrame+frameOffset)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to render button toggledSurface, err: %v\n", err)
|
||||
}
|
||||
@ -295,10 +319,13 @@ func (v *Button) renderFrames(btnSprite *Sprite, btnLayout *ButtonLayout, label
|
||||
if totalButtonTypes > 0 { // button has more than three types
|
||||
frameOffset++
|
||||
|
||||
v.pressedToggledSurface, _ = v.manager.renderer.NewSurface(v.width, v.height,
|
||||
v.pressedToggledSurface, err = v.manager.renderer.NewSurface(v.width, v.height,
|
||||
d2enum.FilterNearest)
|
||||
err = btnSprite.RenderSegmented(v.pressedSurface, xSeg, ySeg, baseFrame+frameOffset)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
err = btnSprite.RenderSegmented(v.pressedSurface, xSeg, ySeg, baseFrame+frameOffset)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to render button pressedToggledSurface, err: %v\n", err)
|
||||
}
|
||||
@ -308,10 +335,13 @@ func (v *Button) renderFrames(btnSprite *Sprite, btnLayout *ButtonLayout, label
|
||||
}
|
||||
|
||||
if btnLayout.DisabledFrame != -1 {
|
||||
v.disabledSurface, _ = v.manager.renderer.NewSurface(v.width, v.height,
|
||||
v.disabledSurface, err = v.manager.renderer.NewSurface(v.width, v.height,
|
||||
d2enum.FilterNearest)
|
||||
err = btnSprite.RenderSegmented(v.disabledSurface, xSeg, ySeg, btnLayout.DisabledFrame)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
err = btnSprite.RenderSegmented(v.disabledSurface, xSeg, ySeg, btnLayout.DisabledFrame)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to render button disabledSurface, err: %v\n", err)
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package d2ui
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
@ -23,6 +25,7 @@ type Checkbox struct {
|
||||
|
||||
// NewCheckbox creates a new instance of a checkbox
|
||||
func (ui *UIManager) NewCheckbox(checkState bool) *Checkbox {
|
||||
var err error
|
||||
result := &Checkbox{
|
||||
checkState: checkState,
|
||||
visible: true,
|
||||
@ -31,17 +34,42 @@ func (ui *UIManager) NewCheckbox(checkState bool) *Checkbox {
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
checkboxSprite, _ := ui.NewSprite(d2resource.Checkbox, d2resource.PaletteFechar)
|
||||
result.width, result.height, _ = checkboxSprite.GetFrameSize(0)
|
||||
checkboxSprite, err := ui.NewSprite(d2resource.Checkbox, d2resource.PaletteFechar)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
result.width, result.height, err = checkboxSprite.GetFrameSize(0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
checkboxSprite.SetPosition(0, 0)
|
||||
|
||||
result.Image, _ = ui.renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
|
||||
result.Image, err = ui.renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = checkboxSprite.RenderSegmented(result.Image, 1, 1, 0)
|
||||
err = checkboxSprite.RenderSegmented(result.Image, 1, 1, 0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
result.checkedImage, _ = ui.renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
|
||||
result.checkedImage, err = ui.renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = checkboxSprite.RenderSegmented(result.checkedImage, 1, 1, 1)
|
||||
err = checkboxSprite.RenderSegmented(result.checkedImage, 1, 1, 1)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
ui.addWidget(result)
|
||||
|
||||
@ -55,6 +83,7 @@ func (v *Checkbox) bindManager(manager *UIManager) {
|
||||
|
||||
// Render renders the checkbox
|
||||
func (v *Checkbox) Render(target d2interface.Surface) error {
|
||||
var err error
|
||||
target.PushTranslation(v.x, v.y)
|
||||
defer target.Pop()
|
||||
|
||||
@ -62,9 +91,15 @@ func (v *Checkbox) Render(target d2interface.Surface) error {
|
||||
defer target.Pop()
|
||||
|
||||
if v.checkState {
|
||||
_ = target.Render(v.checkedImage)
|
||||
err = target.Render(v.checkedImage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
_ = target.Render(v.Image)
|
||||
err = target.Render(v.Image)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -27,7 +27,11 @@ type Label struct {
|
||||
|
||||
// NewLabel creates a new instance of a UI label
|
||||
func (ui *UIManager) NewLabel(fontPath, palettePath string) *Label {
|
||||
font, _ := ui.asset.LoadFont(fontPath+".tbl", fontPath+".dc6", palettePath)
|
||||
font, err := ui.asset.LoadFont(fontPath+".tbl", fontPath+".dc6", palettePath)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
result := &Label{
|
||||
Alignment: d2gui.HorizontalAlignLeft,
|
||||
@ -69,7 +73,10 @@ func (v *Label) Render(target d2interface.Surface) {
|
||||
target.DrawRect(charWidth, charHeight, v.backgroundColor)
|
||||
}
|
||||
|
||||
_ = v.font.RenderText(character, target)
|
||||
err := v.font.RenderText(character, target)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
target.PushTranslation(charWidth, 0)
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package d2ui
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
)
|
||||
@ -28,7 +30,12 @@ type Scrollbar struct {
|
||||
|
||||
// NewScrollbar creates a scrollbar instance
|
||||
func (ui *UIManager) NewScrollbar(x, y, height int) *Scrollbar {
|
||||
scrollbarSprite, _ := ui.NewSprite(d2resource.Scrollbar, d2resource.PaletteSky)
|
||||
scrollbarSprite, err := ui.NewSprite(d2resource.Scrollbar, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
result := &Scrollbar{
|
||||
visible: true,
|
||||
enabled: true,
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
@ -154,7 +155,10 @@ func (s *Sprite) SetCurrentFrame(frameIndex int) error {
|
||||
|
||||
// Rewind sprite to beginning
|
||||
func (s *Sprite) Rewind() {
|
||||
_ = s.animation.SetCurrentFrame(0)
|
||||
err := s.animation.SetCurrentFrame(0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
// PlayForward plays sprite forward
|
||||
|
@ -1,6 +1,7 @@
|
||||
package d2ui
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -26,7 +27,12 @@ type TextBox struct {
|
||||
|
||||
// NewTextbox creates a new instance of a text box
|
||||
func (ui *UIManager) NewTextbox() *TextBox {
|
||||
bgSprite, _ := ui.NewSprite(d2resource.TextBox2, d2resource.PaletteUnits)
|
||||
bgSprite, err := ui.NewSprite(d2resource.TextBox2, d2resource.PaletteUnits)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
tb := &TextBox{
|
||||
filter: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
bgSprite: bgSprite,
|
||||
|
@ -49,7 +49,10 @@ func (ui *UIManager) Reset() {
|
||||
|
||||
// addWidget adds a widget to the UI manager
|
||||
func (ui *UIManager) addWidget(widget Widget) {
|
||||
_ = ui.inputManager.BindHandler(widget)
|
||||
err := ui.inputManager.BindHandler(widget)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
ui.widgets = append(ui.widgets, widget)
|
||||
|
||||
widget.bindManager(ui)
|
||||
@ -105,7 +108,10 @@ func (ui *UIManager) OnMouseButtonDown(event d2interface.MouseEvent) bool {
|
||||
func (ui *UIManager) Render(target d2interface.Surface) {
|
||||
for _, widget := range ui.widgets {
|
||||
if widget.GetVisible() {
|
||||
_ = widget.Render(target)
|
||||
err := widget.Render(target)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,7 +128,10 @@ func (ui *UIManager) contains(w Widget, x, y int) bool {
|
||||
func (ui *UIManager) Advance(elapsed float64) {
|
||||
for _, widget := range ui.widgets {
|
||||
if widget.GetVisible() {
|
||||
_ = widget.Advance(elapsed)
|
||||
err := widget.Advance(elapsed)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package d2gamescreen
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
|
||||
@ -135,6 +136,7 @@ const (
|
||||
|
||||
// OnLoad loads the resources for the Character Select screen
|
||||
func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) {
|
||||
var err error
|
||||
v.audioProvider.PlayBGM(d2resource.BGMTitle)
|
||||
|
||||
if err := v.inputManager.BindHandler(v); err != nil {
|
||||
@ -144,7 +146,10 @@ func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) {
|
||||
loading.Progress(tenPercent)
|
||||
|
||||
bgX, bgY := 0, 0
|
||||
v.background, _ = v.uiManager.NewSprite(d2resource.CharacterSelectionBackground, d2resource.PaletteSky)
|
||||
v.background, err = v.uiManager.NewSprite(d2resource.CharacterSelectionBackground, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.background.SetPosition(bgX, bgY)
|
||||
|
||||
v.createButtons(loading)
|
||||
@ -163,11 +168,17 @@ func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) {
|
||||
deleteConfirmX, deleteConfirmY := 400, 185
|
||||
v.deleteCharConfirmLabel.SetPosition(deleteConfirmX, deleteConfirmY)
|
||||
|
||||
v.selectionBox, _ = v.uiManager.NewSprite(d2resource.CharacterSelectionSelectBox, d2resource.PaletteSky)
|
||||
v.selectionBox, err = v.uiManager.NewSprite(d2resource.CharacterSelectionSelectBox, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
selBoxX, selBoxY := 37, 86
|
||||
v.selectionBox.SetPosition(selBoxX, selBoxY)
|
||||
|
||||
v.okCancelBox, _ = v.uiManager.NewSprite(d2resource.PopUpOkCancel, d2resource.PaletteFechar)
|
||||
v.okCancelBox, err = v.uiManager.NewSprite(d2resource.PopUpOkCancel, d2resource.PaletteFechar)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
okCancelX, okCancelY := 270, 175
|
||||
v.okCancelBox.SetPosition(okCancelX, okCancelY)
|
||||
|
||||
@ -416,7 +427,10 @@ func (v *CharacterSelect) onDeleteCharButtonClicked() {
|
||||
}
|
||||
|
||||
func (v *CharacterSelect) onDeleteCharacterConfirmClicked() {
|
||||
_ = os.Remove(v.gameStates[v.selectedCharacter].FilePath)
|
||||
err := os.Remove(v.gameStates[v.selectedCharacter].FilePath)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.charScrollbar.SetCurrentOffset(0)
|
||||
v.refreshGameStates()
|
||||
v.toggleDeleteCharacterDialog(false)
|
||||
|
@ -89,7 +89,11 @@ func (v *Credits) LoadContributors() []string {
|
||||
|
||||
// OnLoad is called to load the resources for the credits screen
|
||||
func (v *Credits) OnLoad(loading d2screen.LoadingState) {
|
||||
v.creditsBackground, _ = v.uiManager.NewSprite(d2resource.CreditsBackground, d2resource.PaletteSky)
|
||||
var err error
|
||||
v.creditsBackground, err = v.uiManager.NewSprite(d2resource.CreditsBackground, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.creditsBackground.SetPosition(creditsX, creditsY)
|
||||
loading.Progress(twentyPercent)
|
||||
|
||||
@ -106,7 +110,11 @@ func (v *Credits) OnLoad(loading d2screen.LoadingState) {
|
||||
|
||||
loading.Progress(sixtyPercent)
|
||||
|
||||
creditData, _ := d2util.Utf16BytesToString(fileData[2:])
|
||||
creditData, err := d2util.Utf16BytesToString(fileData[2:])
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
v.creditsText = strings.Split(creditData, "\r\n")
|
||||
|
||||
for i := range v.creditsText {
|
||||
|
@ -2,6 +2,7 @@ package d2gamescreen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
@ -225,7 +226,12 @@ func (m *EscapeMenu) wrapLayout(fn func(*layout)) *layout {
|
||||
|
||||
left := center.AddLayout(d2gui.PositionTypeHorizontal)
|
||||
left.SetSize(sidePanelsSize, 0)
|
||||
leftPent, _ := left.AddAnimatedSprite(d2resource.PentSpin, d2resource.PaletteUnits, d2gui.DirectionForward)
|
||||
leftPent, err := left.AddAnimatedSprite(d2resource.PentSpin, d2resource.PaletteUnits, d2gui.DirectionForward)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
m.leftPent = leftPent
|
||||
|
||||
// wrap the base layout so we can pass values around more easily
|
||||
@ -239,7 +245,12 @@ func (m *EscapeMenu) wrapLayout(fn func(*layout)) *layout {
|
||||
// For some reason, aligning the panel to the right won't align the pentagram, so we need to add a static spacer.
|
||||
right.AddSpacerStatic(sidePanelsSize-pentSize, 0)
|
||||
right.SetSize(sidePanelsSize, 0)
|
||||
rightPent, _ := right.AddAnimatedSprite(d2resource.PentSpin, d2resource.PaletteUnits, d2gui.DirectionBackward)
|
||||
rightPent, err := right.AddAnimatedSprite(d2resource.PentSpin, d2resource.PaletteUnits, d2gui.DirectionBackward)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
m.rightPent = rightPent
|
||||
|
||||
wrapper.AddSpacerDynamic()
|
||||
@ -262,7 +273,11 @@ func (m *EscapeMenu) addTitle(l *layout, text string) {
|
||||
}
|
||||
|
||||
func (m *EscapeMenu) addBigSelectionLabel(l *layout, text string, targetLayout layoutID) {
|
||||
guiLabel, _ := l.AddLabel(text, d2gui.FontStyle42Units)
|
||||
guiLabel, err := l.AddLabel(text, d2gui.FontStyle42Units)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
label := &showLayoutLabel{Label: guiLabel, target: targetLayout, showLayout: m.showLayout}
|
||||
label.SetMouseClickHandler(func(_ d2interface.MouseEvent) {
|
||||
label.Trigger()
|
||||
@ -279,7 +294,11 @@ func (m *EscapeMenu) addBigSelectionLabel(l *layout, text string, targetLayout l
|
||||
|
||||
func (m *EscapeMenu) addPreviousMenuLabel(l *layout) {
|
||||
l.AddSpacerStatic(spacerWidth, labelGutter)
|
||||
guiLabel, _ := l.AddLabel("PREVIOUS MENU", d2gui.FontStyle30Units)
|
||||
guiLabel, err := l.AddLabel("PREVIOUS MENU", d2gui.FontStyle30Units)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
label := &showLayoutLabel{Label: guiLabel, target: optionsLayoutID, showLayout: m.showLayout}
|
||||
label.SetMouseClickHandler(func(_ d2interface.MouseEvent) {
|
||||
label.Trigger()
|
||||
@ -310,7 +329,11 @@ func (m *EscapeMenu) addEnumLabel(l *layout, optID optionID, text string, values
|
||||
m.onHoverElement(elID)
|
||||
})
|
||||
layout.AddSpacerDynamic()
|
||||
guiLabel, _ := layout.AddLabel(values[0], d2gui.FontStyle30Units)
|
||||
guiLabel, err := layout.AddLabel(values[0], d2gui.FontStyle30Units)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
label := &enumLabel{
|
||||
Layout: guiLayout,
|
||||
textChangingLabel: guiLabel,
|
||||
@ -329,7 +352,11 @@ func (m *EscapeMenu) addEnumLabel(l *layout, optID optionID, text string, values
|
||||
}
|
||||
|
||||
func (m *EscapeMenu) onLoad() {
|
||||
m.selectSound, _ = m.audioProvider.LoadSound(d2resource.SFXCursorSelect, false, false)
|
||||
var err error
|
||||
m.selectSound, err = m.audioProvider.LoadSound(d2resource.SFXCursorSelect, false, false)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *EscapeMenu) onEscKey() {
|
||||
|
@ -182,16 +182,29 @@ func (v *MainMenu) OnLoad(loading d2screen.LoadingState) {
|
||||
}
|
||||
|
||||
func (v *MainMenu) loadBackgroundSprites() {
|
||||
v.background, _ = v.uiManager.NewSprite(d2resource.GameSelectScreen, d2resource.PaletteSky)
|
||||
var err error
|
||||
v.background, err = v.uiManager.NewSprite(d2resource.GameSelectScreen, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.background.SetPosition(backgroundX, backgroundY)
|
||||
|
||||
v.trademarkBackground, _ = v.uiManager.NewSprite(d2resource.TrademarkScreen, d2resource.PaletteSky)
|
||||
v.trademarkBackground, err = v.uiManager.NewSprite(d2resource.TrademarkScreen, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.trademarkBackground.SetPosition(backgroundX, backgroundY)
|
||||
|
||||
v.tcpIPBackground, _ = v.uiManager.NewSprite(d2resource.TCPIPBackground, d2resource.PaletteSky)
|
||||
v.tcpIPBackground, err = v.uiManager.NewSprite(d2resource.TCPIPBackground, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.tcpIPBackground.SetPosition(backgroundX, backgroundY)
|
||||
|
||||
v.serverIPBackground, _ = v.uiManager.NewSprite(d2resource.PopUpOkCancel, d2resource.PaletteFechar)
|
||||
v.serverIPBackground, err = v.uiManager.NewSprite(d2resource.PopUpOkCancel, d2resource.PaletteFechar)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.serverIPBackground.SetPosition(serverIPbackgroundX, serverIPbackgroundY)
|
||||
}
|
||||
|
||||
@ -242,21 +255,34 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) {
|
||||
}
|
||||
|
||||
func (v *MainMenu) createLogos(loading d2screen.LoadingState) {
|
||||
v.diabloLogoLeft, _ = v.uiManager.NewSprite(d2resource.Diablo2LogoFireLeft, d2resource.PaletteUnits)
|
||||
var err error
|
||||
v.diabloLogoLeft, err = v.uiManager.NewSprite(d2resource.Diablo2LogoFireLeft, d2resource.PaletteUnits)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.diabloLogoLeft.SetEffect(d2enum.DrawEffectModulate)
|
||||
v.diabloLogoLeft.PlayForward()
|
||||
v.diabloLogoLeft.SetPosition(diabloLogoX, diabloLogoY)
|
||||
loading.Progress(sixtyPercent)
|
||||
|
||||
v.diabloLogoRight, _ = v.uiManager.NewSprite(d2resource.Diablo2LogoFireRight, d2resource.PaletteUnits)
|
||||
v.diabloLogoRight, err = v.uiManager.NewSprite(d2resource.Diablo2LogoFireRight, d2resource.PaletteUnits)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.diabloLogoRight.SetEffect(d2enum.DrawEffectModulate)
|
||||
v.diabloLogoRight.PlayForward()
|
||||
v.diabloLogoRight.SetPosition(diabloLogoX, diabloLogoY)
|
||||
|
||||
v.diabloLogoLeftBack, _ = v.uiManager.NewSprite(d2resource.Diablo2LogoBlackLeft, d2resource.PaletteUnits)
|
||||
v.diabloLogoLeftBack, err = v.uiManager.NewSprite(d2resource.Diablo2LogoBlackLeft, d2resource.PaletteUnits)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.diabloLogoLeftBack.SetPosition(diabloLogoX, diabloLogoY)
|
||||
|
||||
v.diabloLogoRightBack, _ = v.uiManager.NewSprite(d2resource.Diablo2LogoBlackRight, d2resource.PaletteUnits)
|
||||
v.diabloLogoRightBack, err = v.uiManager.NewSprite(d2resource.Diablo2LogoBlackRight, d2resource.PaletteUnits)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
v.diabloLogoRightBack.SetPosition(diabloLogoX, diabloLogoY)
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package d2gamescreen
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
||||
|
||||
@ -784,6 +785,11 @@ func (v *SelectHeroClass) loadSprite(animationPath string, position image.Point,
|
||||
}
|
||||
|
||||
func (v *SelectHeroClass) loadSoundEffect(sfx string) d2interface.SoundEffect {
|
||||
result, _ := v.audioProvider.LoadSound(sfx, false, false)
|
||||
result, err := v.audioProvider.LoadSound(sfx, false, false)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ type GameControls struct {
|
||||
heroState *d2hero.HeroStateFactory
|
||||
mapEngine *d2mapengine.MapEngine
|
||||
mapRenderer *d2maprenderer.MapRenderer
|
||||
uiManager *d2ui.UIManager
|
||||
ui *d2ui.UIManager
|
||||
inventory *Inventory
|
||||
heroStatsPanel *HeroStatsPanel
|
||||
helpOverlay *help.Overlay
|
||||
@ -169,7 +169,7 @@ func NewGameControls(
|
||||
|
||||
gc := &GameControls{
|
||||
asset: asset,
|
||||
uiManager: ui,
|
||||
ui: ui,
|
||||
renderer: renderer,
|
||||
hero: hero,
|
||||
heroState: heroState,
|
||||
@ -418,17 +418,37 @@ func (g *GameControls) OnMouseButtonDown(event d2interface.MouseEvent) bool {
|
||||
|
||||
// Load the resources required for the GameControls
|
||||
func (g *GameControls) Load() {
|
||||
g.globeSprite, _ = g.uiManager.NewSprite(d2resource.GameGlobeOverlap, d2resource.PaletteSky)
|
||||
var err error
|
||||
g.globeSprite, err = g.ui.NewSprite(d2resource.GameGlobeOverlap, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
g.hpManaStatusSprite, _ = g.uiManager.NewSprite(d2resource.HealthManaIndicator, d2resource.PaletteSky)
|
||||
g.hpManaStatusSprite, err = g.ui.NewSprite(d2resource.HealthManaIndicator, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
g.mainPanel, _ = g.uiManager.NewSprite(d2resource.GamePanels, d2resource.PaletteSky)
|
||||
g.mainPanel, err = g.ui.NewSprite(d2resource.GamePanels, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
g.menuButton, _ = g.uiManager.NewSprite(d2resource.MenuButton, d2resource.PaletteSky)
|
||||
_ = g.menuButton.SetCurrentFrame(2)
|
||||
g.menuButton, err = g.ui.NewSprite(d2resource.MenuButton, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
err = g.menuButton.SetCurrentFrame(2)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
// TODO: temporarily hardcoded to Attack, should come from saved state for hero
|
||||
genericSkillsSprite, _ := g.uiManager.NewSprite(d2resource.GenericSkills, d2resource.PaletteSky)
|
||||
genericSkillsSprite, err := g.ui.NewSprite(d2resource.GenericSkills, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
attackIconID := 2
|
||||
|
||||
g.leftSkill = &SkillResource{SkillIcon: genericSkillsSprite, IconNumber: attackIconID, SkillResourcePath: d2resource.GenericSkills}
|
||||
@ -443,7 +463,7 @@ func (g *GameControls) Load() {
|
||||
|
||||
func (g *GameControls) loadUIButtons() {
|
||||
// Run button
|
||||
g.runButton = g.uiManager.NewButton(d2ui.ButtonTypeRun, "")
|
||||
g.runButton = g.ui.NewButton(d2ui.ButtonTypeRun, "")
|
||||
|
||||
g.runButton.SetPosition(255, 570)
|
||||
g.runButton.OnActivated(func() { g.onToggleRunButton() })
|
||||
@ -613,7 +633,7 @@ func (g *GameControls) Render(target d2interface.Surface) error {
|
||||
// Left skill
|
||||
skillResourcePath := g.getSkillResourceByClass(g.hero.LeftSkill.Charclass)
|
||||
if skillResourcePath != g.leftSkill.SkillResourcePath {
|
||||
g.leftSkill.SkillIcon, _ = g.uiManager.NewSprite(skillResourcePath, d2resource.PaletteSky)
|
||||
g.leftSkill.SkillIcon, _ = g.ui.NewSprite(skillResourcePath, d2resource.PaletteSky)
|
||||
}
|
||||
|
||||
if err := g.leftSkill.SkillIcon.SetCurrentFrame(g.hero.LeftSkill.IconCel); err != nil {
|
||||
@ -732,7 +752,7 @@ func (g *GameControls) Render(target d2interface.Surface) error {
|
||||
// Right skill
|
||||
skillResourcePath = g.getSkillResourceByClass(g.hero.RightSkill.Charclass)
|
||||
if skillResourcePath != g.rightSkill.SkillResourcePath {
|
||||
g.rightSkill.SkillIcon, _ = g.uiManager.NewSprite(skillResourcePath, d2resource.PaletteSky)
|
||||
g.rightSkill.SkillIcon, _ = g.ui.NewSprite(skillResourcePath, d2resource.PaletteSky)
|
||||
}
|
||||
|
||||
if err := g.rightSkill.SkillIcon.SetCurrentFrame(g.hero.RightSkill.IconCel); err != nil {
|
||||
|
@ -3,6 +3,7 @@ package help
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
|
||||
@ -109,8 +110,15 @@ func (h *Overlay) Load() {
|
||||
prevY = 0
|
||||
)
|
||||
for frameIndex := 0; frameIndex < 7; frameIndex++ {
|
||||
f, _ := h.uiManager.NewSprite(d2resource.HelpBorder, d2resource.PaletteSky)
|
||||
_ = f.SetCurrentFrame(frameIndex)
|
||||
f, err := h.uiManager.NewSprite(d2resource.HelpBorder, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
err = f.SetCurrentFrame(frameIndex)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
ww, hh := f.GetCurrentFrameSize()
|
||||
//fmt.Printf("Help frame %d size: %d, %d\n", frameIndex, ww, hh)
|
||||
@ -357,8 +365,15 @@ func (h *Overlay) createBullet(c callout) {
|
||||
newLabel.SetPosition(c.LabelX, c.LabelY)
|
||||
h.text = append(h.text, newLabel)
|
||||
|
||||
newDot, _ := h.uiManager.NewSprite(d2resource.HelpYellowBullet, d2resource.PaletteSky)
|
||||
_ = newDot.SetCurrentFrame(0)
|
||||
newDot, err := h.uiManager.NewSprite(d2resource.HelpYellowBullet, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
err = newDot.SetCurrentFrame(0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
newDot.SetPosition(c.DotX, c.DotY+14)
|
||||
h.frames = append(h.frames, newDot)
|
||||
}
|
||||
@ -382,8 +397,16 @@ func (h *Overlay) createCallout(c callout) {
|
||||
}
|
||||
h.lines = append(h.lines, l)
|
||||
|
||||
newDot, _ := h.uiManager.NewSprite(d2resource.HelpWhiteBullet, d2resource.PaletteSky)
|
||||
_ = newDot.SetCurrentFrame(0)
|
||||
newDot, err := h.uiManager.NewSprite(d2resource.HelpWhiteBullet, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
err = newDot.SetCurrentFrame(0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
newDot.SetPosition(c.DotX, c.DotY)
|
||||
h.frames = append(h.frames, newDot)
|
||||
}
|
||||
@ -394,7 +417,10 @@ func (h *Overlay) Render(target d2interface.Surface) error {
|
||||
}
|
||||
|
||||
for _, f := range h.frames {
|
||||
_ = f.Render(target)
|
||||
err := f.Render(target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, t := range h.text {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package d2player
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
@ -78,8 +79,17 @@ func NewHeroStatsPanel(asset *d2asset.AssetManager, ui *d2ui.UIManager, heroName
|
||||
|
||||
// Load the data for the hero status panel
|
||||
func (s *HeroStatsPanel) Load() {
|
||||
s.frame, _ = s.uiManager.NewSprite(d2resource.Frame, d2resource.PaletteSky)
|
||||
s.panel, _ = s.uiManager.NewSprite(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
|
||||
var err error
|
||||
s.frame, err = s.uiManager.NewSprite(d2resource.Frame, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
s.panel, err = s.uiManager.NewSprite(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
s.initStatValueLabels()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package d2player
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
||||
|
||||
@ -76,7 +77,12 @@ func (g *Inventory) Close() {
|
||||
|
||||
// Load the resources required by the inventory
|
||||
func (g *Inventory) Load() {
|
||||
g.frame, _ = g.uiManager.NewSprite(d2resource.Frame, d2resource.PaletteSky)
|
||||
sprite, err := g.uiManager.NewSprite(d2resource.Frame, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
g.frame = sprite
|
||||
|
||||
g.panel, _ = g.uiManager.NewSprite(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
|
||||
|
||||
@ -123,8 +129,7 @@ func (g *Inventory) Load() {
|
||||
}
|
||||
|
||||
// TODO: Load the player's actual items
|
||||
|
||||
_, err := g.grid.Add(inventoryItems...)
|
||||
_, err = g.grid.Add(inventoryItems...)
|
||||
if err != nil {
|
||||
fmt.Printf("could not add items to the inventory, err: %v\n", err)
|
||||
}
|
||||
|
@ -223,7 +223,10 @@ func (g *ItemGrid) renderItem(item InventoryItem, target d2interface.Surface, x,
|
||||
if itemSprite != nil {
|
||||
itemSprite.SetPosition(x, y)
|
||||
itemSprite.GetCurrentFrameSize()
|
||||
_ = itemSprite.Render(target)
|
||||
err := itemSprite.Render(target)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package d2player
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
@ -23,9 +25,17 @@ func newMiniPanel(asset *d2asset.AssetManager, uiManager *d2ui.UIManager, isSing
|
||||
miniPanelContainerPath = d2resource.MinipanelSmall
|
||||
}
|
||||
|
||||
containerSprite, _ := uiManager.NewSprite(miniPanelContainerPath, d2resource.PaletteSky)
|
||||
containerSprite, err := uiManager.NewSprite(miniPanelContainerPath, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
buttonSprite, _ := uiManager.NewSprite(d2resource.MinipanelButton, d2resource.PaletteSky)
|
||||
buttonSprite, err := uiManager.NewSprite(d2resource.MinipanelButton, d2resource.PaletteSky)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
rectangle := d2geom.Rectangle{Left: 325, Top: 526, Width: 156, Height: 26}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package d2netpackettype
|
||||
|
||||
import "encoding/json"
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
// NetPacketType is an enum referring to all packet types in package
|
||||
// d2netpacket.
|
||||
@ -50,7 +53,10 @@ func (n NetPacketType) String() string {
|
||||
}
|
||||
|
||||
func (n NetPacketType) MarshalPacket() []byte {
|
||||
p, _ := json.Marshal(n)
|
||||
p, err := json.Marshal(n)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
@ -37,7 +37,10 @@ func UnmarshalNetPacket(packet []byte) (NetPacket, error) {
|
||||
|
||||
// MarshalPacket is a quick helper function to Marshal very anything UNSAFELY, meaning the error is not checked before sending.
|
||||
func MarshalPacket(packet interface{}) []byte {
|
||||
b, _ := json.Marshal(packet)
|
||||
b, err := json.Marshal(packet)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
||||
@ -37,7 +38,10 @@ func CreateAddPlayerPacket(id, name string, x, y int, heroType d2enum.Hero,
|
||||
Stats: stats,
|
||||
Skills: skills,
|
||||
}
|
||||
b, _ := json.Marshal(addPlayerPacket)
|
||||
b, err := json.Marshal(addPlayerPacket)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.AddPlayer,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
@ -20,7 +21,10 @@ func CreateGenerateMapPacket(regionType d2enum.RegionIdType) NetPacket {
|
||||
generateMapPacket := GenerateMapPacket{
|
||||
RegionType: regionType,
|
||||
}
|
||||
b, _ := json.Marshal(generateMapPacket)
|
||||
b, err := json.Marshal(generateMapPacket)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.GenerateMap,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
)
|
||||
@ -21,7 +22,10 @@ func CreateSpawnItemPacket(x, y int, codes ...string) NetPacket {
|
||||
Y: y,
|
||||
Codes: codes,
|
||||
}
|
||||
b, _ := json.Marshal(spawnItemPacket)
|
||||
b, err := json.Marshal(spawnItemPacket)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.SpawnItem,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
)
|
||||
@ -27,7 +28,10 @@ func CreateMovePlayerPacket(playerID string, startX, startY, destX, destY float6
|
||||
DestX: destX,
|
||||
DestY: destY,
|
||||
}
|
||||
b, _ := json.Marshal(movePlayerPacket)
|
||||
b, err := json.Marshal(movePlayerPacket)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.MovePlayer,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
@ -19,7 +20,10 @@ func CreatePingPacket() NetPacket {
|
||||
ping := PingPacket{
|
||||
TS: time.Now(),
|
||||
}
|
||||
b, _ := json.Marshal(ping)
|
||||
b, err := json.Marshal(ping)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.Ping,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
)
|
||||
@ -28,7 +29,10 @@ func CreateCastPacket(entityID string, skillID int, targetX, targetY float64) Ne
|
||||
TargetY: targetY,
|
||||
TargetEntityID: "", // TODO implement targeting entities
|
||||
}
|
||||
b, _ := json.Marshal(castPacket)
|
||||
b, err := json.Marshal(castPacket)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.CastSkill,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
||||
|
||||
@ -22,7 +23,10 @@ func CreatePlayerConnectionRequestPacket(id string, playerState *d2hero.HeroStat
|
||||
ID: id,
|
||||
PlayerState: playerState,
|
||||
}
|
||||
b, _ := json.Marshal(playerConnectionRequest)
|
||||
b, err := json.Marshal(playerConnectionRequest)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.PlayerConnectionRequest,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
||||
|
||||
@ -21,7 +22,10 @@ func CreatePlayerDisconnectRequestPacket(id string) NetPacket {
|
||||
playerDisconnectRequest := PlayerDisconnectRequestPacket{
|
||||
ID: id,
|
||||
}
|
||||
b, _ := json.Marshal(playerDisconnectRequest)
|
||||
b, err := json.Marshal(playerDisconnectRequest)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.PlayerDisconnectionNotification,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
@ -21,7 +22,10 @@ func CreatePongPacket(id string) NetPacket {
|
||||
ID: id,
|
||||
TS: time.Now(),
|
||||
}
|
||||
b, _ := json.Marshal(pong)
|
||||
b, err := json.Marshal(pong)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.Pong,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
@ -19,7 +20,10 @@ func CreateServerClosedPacket() NetPacket {
|
||||
serverClosed := ServerClosedPacket{
|
||||
TS: time.Now(),
|
||||
}
|
||||
b, _ := json.Marshal(serverClosed)
|
||||
b, err := json.Marshal(serverClosed)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.ServerClosed,
|
||||
|
@ -2,6 +2,7 @@ package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
)
|
||||
@ -20,7 +21,10 @@ func CreateUpdateServerInfoPacket(seed int64, playerID string) NetPacket {
|
||||
Seed: seed,
|
||||
PlayerID: playerID,
|
||||
}
|
||||
b, _ := json.Marshal(updateServerInfo)
|
||||
b, err := json.Marshal(updateServerInfo)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.UpdateServerInfo,
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
||||
@ -60,7 +61,10 @@ func (u *UDPClientConnection) SendPacketToClient(packet d2netpacket.NetPacket) e
|
||||
|
||||
buff.WriteByte(byte(packet.PacketType))
|
||||
|
||||
writer, _ := gzip.NewWriterLevel(&buff, gzip.BestCompression)
|
||||
writer, err := gzip.NewWriterLevel(&buff, gzip.BestCompression)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
if written, writeErr := writer.Write(data); writeErr != nil {
|
||||
return writeErr
|
||||
|
@ -399,7 +399,10 @@ func OnClientDisconnected(client ClientConnection) {
|
||||
func OnPacketReceived(client ClientConnection, packet d2netpacket.NetPacket) error {
|
||||
switch packet.PacketType {
|
||||
case d2netpackettype.MovePlayer:
|
||||
movePacket, _ := d2netpacket.UnmarshalMovePlayer(packet.PacketData)
|
||||
movePacket, err := d2netpacket.UnmarshalMovePlayer(packet.PacketData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: This needs to be verified on the server (here) before sending to other clients....
|
||||
// TODO: Hacky, this should be updated in realtime ----------------
|
||||
// TODO: Verify player id
|
||||
|
Loading…
Reference in New Issue
Block a user