2020-06-24 13:49:13 -04:00
|
|
|
package d2mapentity
|
|
|
|
|
|
|
|
import (
|
2020-06-27 23:15:20 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
2020-06-24 13:49:13 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
2020-06-27 15:44:28 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2020-06-27 23:15:20 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-06-24 13:49:13 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
2020-06-27 23:15:20 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
2020-06-24 13:49:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Object represents a composite of animations that can be projected onto the map.
|
|
|
|
type Object struct {
|
|
|
|
mapEntity
|
|
|
|
composite *d2asset.Composite
|
|
|
|
direction int
|
2020-06-27 18:58:41 -04:00
|
|
|
highlight bool
|
2020-06-27 23:15:20 -04:00
|
|
|
nameLabel d2ui.Label
|
2020-06-24 13:49:13 -04:00
|
|
|
objectRecord *d2datadict.ObjectRecord
|
|
|
|
objectLookup *d2datadict.ObjectLookupRecord
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateObject creates an instance of AnimatedComposite
|
|
|
|
func CreateObject(x, y int, object *d2datadict.ObjectLookupRecord, palettePath string) (*Object, error) {
|
|
|
|
composite, err := d2asset.LoadComposite(object, palettePath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
entity := &Object{
|
|
|
|
mapEntity: createMapEntity(x, y),
|
|
|
|
composite: composite,
|
|
|
|
objectLookup: object,
|
2020-06-27 23:15:20 -04:00
|
|
|
nameLabel: d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic),
|
2020-06-24 13:49:13 -04:00
|
|
|
}
|
|
|
|
entity.mapEntity.directioner = entity.rotate
|
|
|
|
entity.objectRecord = d2datadict.Objects[object.ObjectsTxtId]
|
2020-06-27 14:30:23 -04:00
|
|
|
entity.drawLayer = entity.objectRecord.OrderFlag[d2enum.AnimationModeObjectNeutral]
|
2020-06-24 13:49:13 -04:00
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMode changes the graphical mode of this animated entity
|
|
|
|
func (ob *Object) SetMode(animationMode, weaponClass string, direction int) error {
|
|
|
|
ob.composite.SetMode(animationMode, weaponClass, direction)
|
|
|
|
ob.direction = direction
|
|
|
|
ob.weaponClass = weaponClass
|
|
|
|
|
|
|
|
err := ob.composite.SetMode(animationMode, weaponClass, direction)
|
|
|
|
if err != nil {
|
|
|
|
err = ob.composite.SetMode(animationMode, "HTH", direction)
|
|
|
|
ob.weaponClass = "HTH"
|
|
|
|
}
|
2020-06-27 18:58:41 -04:00
|
|
|
|
|
|
|
mode := d2enum.ObjectAnimationModeFromString(animationMode)
|
|
|
|
ob.mapEntity.drawLayer = ob.objectRecord.OrderFlag[mode]
|
2020-06-27 15:44:28 -04:00
|
|
|
|
2020-06-27 14:30:23 -04:00
|
|
|
// For objects their txt record entry overrides animationdata
|
2020-06-27 18:58:41 -04:00
|
|
|
speed := ob.objectRecord.FrameDelta[mode]
|
2020-06-27 15:44:28 -04:00
|
|
|
if speed != 0 {
|
|
|
|
ob.composite.SetSpeed(speed)
|
|
|
|
}
|
2020-06-27 18:58:41 -04:00
|
|
|
|
2020-06-24 13:49:13 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:58:41 -04:00
|
|
|
func (ob *Object) Highlight() {
|
|
|
|
ob.highlight = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ob *Object) Selectable() bool {
|
|
|
|
mode := d2enum.ObjectAnimationModeFromString(ob.composite.GetAnimationMode())
|
|
|
|
return ob.objectRecord.Selectable[mode]
|
|
|
|
}
|
|
|
|
|
2020-06-24 13:49:13 -04:00
|
|
|
// Render draws this animated entity onto the target
|
|
|
|
func (ob *Object) Render(target d2render.Surface) {
|
|
|
|
target.PushTranslation(
|
|
|
|
ob.offsetX+int((ob.subcellX-ob.subcellY)*16),
|
|
|
|
ob.offsetY+int(((ob.subcellX+ob.subcellY)*8)-5),
|
|
|
|
)
|
2020-06-27 18:58:41 -04:00
|
|
|
if ob.highlight {
|
2020-06-27 23:15:20 -04:00
|
|
|
ob.nameLabel.SetText(d2common.TranslateString(ob.objectRecord.Name))
|
|
|
|
ob.nameLabel.SetPosition(-50, -50)
|
|
|
|
ob.nameLabel.Render(target)
|
2020-06-27 18:58:41 -04:00
|
|
|
target.PushBrightness(2)
|
|
|
|
defer target.Pop()
|
|
|
|
}
|
2020-06-24 13:49:13 -04:00
|
|
|
defer target.Pop()
|
|
|
|
ob.composite.Render(target)
|
2020-06-27 18:58:41 -04:00
|
|
|
ob.highlight = false
|
2020-06-24 13:49:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// rotate sets direction and changes animation
|
|
|
|
func (ob *Object) rotate(direction int) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ob *Object) Advance(elapsed float64) {
|
|
|
|
ob.composite.Advance(elapsed)
|
|
|
|
}
|