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:
Ziemas 2020-07-03 16:38:22 +02:00 committed by GitHub
parent ec0bddc01e
commit 7ce01ab694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 20 deletions

View File

@ -20,9 +20,12 @@ type ObjectRecord struct {
Parm [8]int // unknown
Name 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?
TrapProbability int // unused
@ -132,8 +135,8 @@ func createObjectRecord(props []string) ObjectRecord {
result := ObjectRecord{
Name: props[inc()],
Description: props[inc()],
Id: d2common.StringToInt(props[inc()]),
Token: props[inc()],
id: d2common.StringToInt(props[inc()]),
token: props[inc()],
SpawnMax: d2common.StringToInt(props[inc()]),
Selectable: [8]bool{

View File

@ -17,28 +17,63 @@ type Object struct {
direction int
highlight bool
nameLabel d2ui.Label
objectRecord *d2datadict.ObjectRecord
objectLookup *d2datadict.ObjectLookupRecord
objectRecord *d2datadict.ObjectRecord
objectType *d2datadict.ObjectTypeRecord
}
// 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)
if err != nil {
return nil, err
}
entity := &Object{
mapEntity: createMapEntity(x, y),
composite: composite,
objectLookup: object,
nameLabel: d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic),
}
entity.composite = composite
entity.mapEntity.directioner = entity.rotate
entity.objectRecord = d2datadict.Objects[object.ObjectsTxtId]
entity.drawLayer = entity.objectRecord.OrderFlag[d2enum.AnimationModeObjectNeutral]
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
}
@ -81,6 +116,7 @@ func (ob *Object) Render(target d2interface.Surface) {
ob.offsetX+int((ob.subcellX-ob.subcellY)*16),
ob.offsetY+int(((ob.subcellX+ob.subcellY)*8)-5),
)
if ob.highlight {
ob.nameLabel.SetText(d2common.TranslateString(ob.objectRecord.Name))
ob.nameLabel.SetPosition(-50, -50)
@ -88,6 +124,7 @@ func (ob *Object) Render(target d2interface.Surface) {
target.PushBrightness(2)
defer target.Pop()
}
defer target.Pop()
ob.composite.Render(target)
ob.highlight = false

View File

@ -139,13 +139,7 @@ func (mr *Stamp) Entities(tileOffsetX, tileOffsetY int) []d2mapentity.MapEntity
objectRecord := d2datadict.Objects[lookup.ObjectsTxtId]
if objectRecord != nil {
// The lookup is used deeper in for crap without checking other sources :(
// 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)
entity, err := d2mapentity.CreateObject((tileOffsetX*5)+object.X, (tileOffsetY*5)+object.Y, objectRecord, d2resource.PaletteUnits)
if err != nil {
panic(err)