Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: major refactor of dc6 package #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/OpenDiablo2/dc6)](https://goreportcard.com/report/github.com/OpenDiablo2/dc6)
[![GoDoc](https://pkg.go.dev/badge/github.com/OpenDiablo2/dc6?utm_source=godoc)](https://pkg.go.dev/mod/github.com/OpenDiablo2/dc6)

## Description

This is a module used to decoding and encoding Diablo II animation files (DC6)

## Documentation

a documentation describing this fileformat can be found here:
- [MarkKoz/DC6.ksy](https://gist.github.com/MarkKoz/874052801d7eddd1bb4a9b69cd1e9ac8) [and here](./docs/dc6.ksy)
- [The Phrozen Keep: DC6 Format](https://d2mods.info/forum/viewtopic.php?t=724#p148076)
12 changes: 6 additions & 6 deletions cmd/dc6-convert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os"
"path/filepath"

dc6lib "github.com/gravestench/dc6/pkg"
dc6lib "github.com/OpenDiablo2/dc6/pkg"
gpl "github.com/gravestench/gpl/pkg"
)

Expand Down Expand Up @@ -59,8 +59,8 @@ func main() {
dc6.SetPalette(color.Palette(*gplInstance))
}

numDirections := len(dc6.Directions)
framesPerDir := len(dc6.Directions[0].Frames)
numDirections := dc6.Frames.NumberOfDirections()
framesPerDir := dc6.Frames.FramesPerDirection()
isMultiFrame := numDirections > 1 || framesPerDir > 1

outfilePath := *o.pngPath
Expand All @@ -69,8 +69,8 @@ func main() {
outfilePath = noExt + "_d%v_f%v.png"
}

for dirIdx := range dc6.Directions {
for frameIdx := range dc6.Directions[dirIdx].Frames {
for dirIdx := 0; dirIdx < numDirections; dirIdx++ {
for frameIdx := 0; frameIdx < framesPerDir; frameIdx++ {
outPath := outfilePath

if isMultiFrame {
Expand All @@ -82,7 +82,7 @@ func main() {
log.Fatal(err)
}

if err := png.Encode(f, dc6.Directions[dirIdx].Frames[frameIdx]); err != nil {
if err := png.Encode(f, dc6.Frames.Direction(dirIdx).Frame(frameIdx)); err != nil {
_ = f.Close()
log.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/dc6-view/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/AllenDang/giu"

pdc6lib "github.com/gravestench/dc6/pkg"
dc6widget "github.com/gravestench/dc6/pkg/giuwidget"
pdc6lib "github.com/OpenDiablo2/dc6/pkg"
dc6widget "github.com/OpenDiablo2/dc6/pkg/giuwidget"
gpl "github.com/gravestench/gpl/pkg"
)

Expand Down Expand Up @@ -63,7 +63,7 @@ func main() {
dc6.SetPalette(color.Palette(*gplInstance))
}

f0 := dc6.Directions[0].Frames[0]
f0 := dc6.Frames.Direction(0).Frame(0)

imgW := int(float64(f0.Width) * *o.scale)
imgH := int(float64(f0.Height) * *o.scale)
Expand Down
2 changes: 0 additions & 2 deletions doc.go

This file was deleted.

File renamed without changes.
7 changes: 4 additions & 3 deletions pkg/frame_header.go → docs/dc6_frame_header.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package pkg
package docs

// FrameHeader represents the header of a frame in a DC6.
type FrameHeader struct {
// DC6FrameHeader represents the header of a frame in a DC6.
// this structure is unused in this module and is only a documentation
type DC6FrameHeader struct {
Flipped int32 `struct:"int32"`
Width int32 `struct:"int32"`
Height int32 `struct:"int32"`
Expand Down
10 changes: 6 additions & 4 deletions pkg/header.go → docs/dc6_header.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package pkg
// Package docs contains a documentation files (unused in real module)
package docs

// Header represents the file header of a DC6 file.
type Header struct {
// DC6Header represents the file header of a DC6 file.
// this structure is unused in this module and is only a documentation
type DC6Header struct {
Termination []byte `struct:"[4]byte"`
Version int32 `struct:"int32"`
Flags uint32 `struct:"uint32"`
Encoding uint32 `struct:"uint32"`
Termination []byte `struct:"[4]byte"`
Directions int32 `struct:"int32"`
FramesPerDirection int32 `struct:"int32"`
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/gravestench/dc6
module github.com/OpenDiablo2/dc6

go 1.16

Expand Down
Loading