From 7ce01ab694bf38a1cfad1272e3b525ead3e29399 Mon Sep 17 00:00:00 2001 From: Ziemas Date: Fri, 3 Jul 2020 16:38:22 +0200 Subject: [PATCH] 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. --- d2common/d2data/d2datadict/objects.go | 11 ++++-- d2core/d2map/d2mapentity/object.go | 55 ++++++++++++++++++++++----- d2core/d2map/d2mapstamp/stamp.go | 8 +--- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/d2common/d2data/d2datadict/objects.go b/d2common/d2data/d2datadict/objects.go index 5d14a37f..3b9dc9fb 100644 --- a/d2common/d2data/d2datadict/objects.go +++ b/d2common/d2data/d2datadict/objects.go @@ -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{ diff --git a/d2core/d2map/d2mapentity/object.go b/d2core/d2map/d2mapentity/object.go index 2455e704..f6962756 100644 --- a/d2core/d2map/d2mapentity/object.go +++ b/d2core/d2map/d2mapentity/object.go @@ -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 diff --git a/d2core/d2map/d2mapstamp/stamp.go b/d2core/d2map/d2mapstamp/stamp.go index 685a34b7..760d76a9 100644 --- a/d2core/d2map/d2mapstamp/stamp.go +++ b/d2core/d2map/d2mapstamp/stamp.go @@ -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)