forked from OpenDiablo2/OpenDiablo2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature pl2 asset manager (OpenDiablo2#319)
* adding pl2 as a fiel format and an asset manager for pl2 files * adding pl2 as a file format and an asset manager for pl2 files * pl2 asset manager and file format * added call in main.go to load palette transforms * removed incorrect PaletteTransformType declarations from main.go * removingn bad resource path for palette transform * PL2 file format added, added to asset management PL2 files are beside palette files in the mpq These files define palette transforms of their respective base palette. I've bound a command to d2term (in d2asset.go) load_pl2 <path> * Clean up PL2 asset stuff removed pl2 stuff from d2datadict, didn't belong in there removed d2term debug binding * minor cleanup for d2pl2
- Loading branch information
1 parent
664b841
commit 019bb92
Showing
5 changed files
with
142 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package d2pl2 | ||
|
||
import ( | ||
"encoding/binary" | ||
|
||
"github.com/go-restruct/restruct" | ||
) | ||
|
||
type PL2File struct { | ||
BasePalette PL2Palette | ||
|
||
LightLevelVariations [32]PL2PaletteTransform | ||
InvColorVariations [16]PL2PaletteTransform | ||
SelectedUintShift PL2PaletteTransform | ||
AlphaBlend [3][256]PL2PaletteTransform | ||
AdditiveBlend [256]PL2PaletteTransform | ||
MultiplicativeBlend [256]PL2PaletteTransform | ||
HueVariations [111]PL2PaletteTransform | ||
RedTones PL2PaletteTransform | ||
GreenTones PL2PaletteTransform | ||
BlueTones PL2PaletteTransform | ||
UnknownVariations [14]PL2PaletteTransform | ||
MaxComponentBlend [256]PL2PaletteTransform | ||
DarkendColorShift PL2PaletteTransform | ||
|
||
TextColors [13]PL2Color24Bits | ||
TextColorShifts [13]PL2PaletteTransform | ||
} | ||
|
||
type PL2Color struct { | ||
R uint8 | ||
G uint8 | ||
B uint8 | ||
_ uint8 | ||
} | ||
|
||
type PL2Color24Bits struct { | ||
R uint8 | ||
G uint8 | ||
B uint8 | ||
} | ||
|
||
type PL2Palette struct { | ||
Colors [256]PL2Color | ||
} | ||
|
||
type PL2PaletteTransform struct { | ||
Indices [256]uint8 | ||
} | ||
|
||
// uses restruct to read the binary dc6 data into structs | ||
func LoadPL2(data []byte) (*PL2File, error) { | ||
result := &PL2File{} | ||
|
||
restruct.EnableExprBeta() | ||
|
||
err := restruct.Unpack(data, binary.LittleEndian, &result) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package d2asset | ||
|
||
import ( | ||
"github.com/OpenDiablo2/OpenDiablo2/d2common" | ||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2pl2" | ||
) | ||
|
||
type paletteTransformManager struct { | ||
cache *d2common.Cache | ||
} | ||
|
||
const ( | ||
paletteTransformBudget = 64 | ||
) | ||
|
||
func createPaletteTransformManager() *paletteTransformManager { | ||
return &paletteTransformManager{d2common.CreateCache(paletteTransformBudget)} | ||
} | ||
|
||
func (pm *paletteTransformManager) loadPaletteTransform(path string) (*d2pl2.PL2File, error) { | ||
if pl2, found := pm.cache.Retrieve(path); found { | ||
return pl2.(*d2pl2.PL2File), nil | ||
} | ||
|
||
data, err := LoadFile(path); | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pl2, err := d2pl2.LoadPL2(data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pm.cache.Insert(path, pl2, 1) | ||
return pl2, nil | ||
} |