mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-19 21:55:24 +00:00
Create objects by passing the object record to CreateObject (#530)
* Create object by Objects.txt entry Get graphics token from objectType * Unexport some unused ObjectRecord stuff.
This commit is contained in:
parent
ec0bddc01e
commit
7ce01ab694
|
@ -20,9 +20,12 @@ type ObjectRecord struct {
|
||||||
Parm [8]int // unknown
|
Parm [8]int // unknown
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
Token string // refers to what graphics this object uses
|
|
||||||
|
|
||||||
Id int //nolint:golint it's ok that it's called Id, unused indexed by line number instead
|
// Don't use, get token from objtypes
|
||||||
|
token string // refers to what graphics this object uses
|
||||||
|
|
||||||
|
// Don't use, index by line number
|
||||||
|
id int //nolint:golint it's ok that it's called Id, unused indexed by line number instead
|
||||||
SpawnMax int // unused?
|
SpawnMax int // unused?
|
||||||
TrapProbability int // unused
|
TrapProbability int // unused
|
||||||
|
|
||||||
|
@ -132,8 +135,8 @@ func createObjectRecord(props []string) ObjectRecord {
|
||||||
result := ObjectRecord{
|
result := ObjectRecord{
|
||||||
Name: props[inc()],
|
Name: props[inc()],
|
||||||
Description: props[inc()],
|
Description: props[inc()],
|
||||||
Id: d2common.StringToInt(props[inc()]),
|
id: d2common.StringToInt(props[inc()]),
|
||||||
Token: props[inc()],
|
token: props[inc()],
|
||||||
|
|
||||||
SpawnMax: d2common.StringToInt(props[inc()]),
|
SpawnMax: d2common.StringToInt(props[inc()]),
|
||||||
Selectable: [8]bool{
|
Selectable: [8]bool{
|
||||||
|
|
|
@ -17,28 +17,63 @@ type Object struct {
|
||||||
direction int
|
direction int
|
||||||
highlight bool
|
highlight bool
|
||||||
nameLabel d2ui.Label
|
nameLabel d2ui.Label
|
||||||
objectRecord *d2datadict.ObjectRecord
|
|
||||||
objectLookup *d2datadict.ObjectLookupRecord
|
objectLookup *d2datadict.ObjectLookupRecord
|
||||||
|
objectRecord *d2datadict.ObjectRecord
|
||||||
|
objectType *d2datadict.ObjectTypeRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateObject creates an instance of AnimatedComposite
|
// CreateObject creates an instance of AnimatedComposite
|
||||||
func CreateObject(x, y int, object *d2datadict.ObjectLookupRecord, palettePath string) (*Object, error) {
|
func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath string) (*Object, error) {
|
||||||
|
entity := &Object{
|
||||||
|
mapEntity: createMapEntity(x, y),
|
||||||
|
objectRecord: objectRec,
|
||||||
|
objectType: &d2datadict.ObjectTypes[objectRec.Index],
|
||||||
|
nameLabel: d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic),
|
||||||
|
}
|
||||||
|
|
||||||
|
object := &d2datadict.ObjectLookupRecord{
|
||||||
|
Base: "/Data/Global/Objects",
|
||||||
|
Token: entity.objectType.Token,
|
||||||
|
Mode: "NU",
|
||||||
|
Class: "HTH",
|
||||||
|
HD: "LIT",
|
||||||
|
TR: "LIT",
|
||||||
|
LG: "LIT",
|
||||||
|
RA: "LIT",
|
||||||
|
LA: "LIT",
|
||||||
|
RH: "LIT",
|
||||||
|
LH: "LIT",
|
||||||
|
SH: "LIT",
|
||||||
|
S1: "LIT",
|
||||||
|
S2: "LIT",
|
||||||
|
S3: "LIT",
|
||||||
|
S4: "LIT",
|
||||||
|
S5: "LIT",
|
||||||
|
S6: "LIT",
|
||||||
|
S7: "LIT",
|
||||||
|
S8: "LIT",
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.objectLookup = object
|
||||||
|
|
||||||
composite, err := d2asset.LoadComposite(object, palettePath)
|
composite, err := d2asset.LoadComposite(object, palettePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
entity := &Object{
|
entity.composite = composite
|
||||||
mapEntity: createMapEntity(x, y),
|
|
||||||
composite: composite,
|
|
||||||
objectLookup: object,
|
|
||||||
nameLabel: d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic),
|
|
||||||
}
|
|
||||||
entity.mapEntity.directioner = entity.rotate
|
entity.mapEntity.directioner = entity.rotate
|
||||||
entity.objectRecord = d2datadict.Objects[object.ObjectsTxtId]
|
|
||||||
entity.drawLayer = entity.objectRecord.OrderFlag[d2enum.AnimationModeObjectNeutral]
|
entity.drawLayer = entity.objectRecord.OrderFlag[d2enum.AnimationModeObjectNeutral]
|
||||||
|
|
||||||
entity.SetMode(object.Mode, object.Class, 0)
|
entity.SetMode(object.Mode, object.Class, 0)
|
||||||
|
|
||||||
|
// stop torches going crazy for now
|
||||||
|
// need initFunc handling to set objects up properly
|
||||||
|
if objectRec.HasAnimationMode[d2enum.AnimationModeObjectOpened] {
|
||||||
|
entity.SetMode("ON", "HTH", 0)
|
||||||
|
}
|
||||||
|
|
||||||
return entity, nil
|
return entity, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +116,7 @@ func (ob *Object) Render(target d2interface.Surface) {
|
||||||
ob.offsetX+int((ob.subcellX-ob.subcellY)*16),
|
ob.offsetX+int((ob.subcellX-ob.subcellY)*16),
|
||||||
ob.offsetY+int(((ob.subcellX+ob.subcellY)*8)-5),
|
ob.offsetY+int(((ob.subcellX+ob.subcellY)*8)-5),
|
||||||
)
|
)
|
||||||
|
|
||||||
if ob.highlight {
|
if ob.highlight {
|
||||||
ob.nameLabel.SetText(d2common.TranslateString(ob.objectRecord.Name))
|
ob.nameLabel.SetText(d2common.TranslateString(ob.objectRecord.Name))
|
||||||
ob.nameLabel.SetPosition(-50, -50)
|
ob.nameLabel.SetPosition(-50, -50)
|
||||||
|
@ -88,6 +124,7 @@ func (ob *Object) Render(target d2interface.Surface) {
|
||||||
target.PushBrightness(2)
|
target.PushBrightness(2)
|
||||||
defer target.Pop()
|
defer target.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
defer target.Pop()
|
defer target.Pop()
|
||||||
ob.composite.Render(target)
|
ob.composite.Render(target)
|
||||||
ob.highlight = false
|
ob.highlight = false
|
||||||
|
|
|
@ -139,13 +139,7 @@ func (mr *Stamp) Entities(tileOffsetX, tileOffsetY int) []d2mapentity.MapEntity
|
||||||
objectRecord := d2datadict.Objects[lookup.ObjectsTxtId]
|
objectRecord := d2datadict.Objects[lookup.ObjectsTxtId]
|
||||||
|
|
||||||
if objectRecord != nil {
|
if objectRecord != nil {
|
||||||
// The lookup is used deeper in for crap without checking other sources :(
|
entity, err := d2mapentity.CreateObject((tileOffsetX*5)+object.X, (tileOffsetY*5)+object.Y, objectRecord, d2resource.PaletteUnits)
|
||||||
// Bail out here for now
|
|
||||||
if !objectRecord.Draw || lookup.Base == "" || objectRecord.Token == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
entity, err := d2mapentity.CreateObject((tileOffsetX*5)+object.X, (tileOffsetY*5)+object.Y, lookup, d2resource.PaletteUnits)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user