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 all 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
89 changes: 89 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/gucio321/d2dc6
govet:
enable-all: true
check-shadowing: true
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- errorlint
- exportloopref
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ifshort
- ineffassign
- lll
- makezero
- misspell
- nakedret
- nolintlint
- prealloc
- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- wrapcheck
- wsl

run:
timeout: 5m
skip-dirs:
- .github
- build
- web

issues:
max-same-issues: 0
exclude-use-default: false
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

Documentation describing this file format 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)
16 changes: 9 additions & 7 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 All @@ -32,6 +32,7 @@ func main() {
dc6Data, err := ioutil.ReadFile(*o.dc6Path)
if err != nil {
const fmtErr = "could not read file, %v"

fmt.Print(fmt.Errorf(fmtErr, err))

return
Expand Down Expand Up @@ -59,8 +60,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 +70,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,8 +83,9 @@ 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 All @@ -95,7 +97,7 @@ func main() {
}

func parseOptions(o *options) (terminate bool) {
o.dc6Path = flag.String("dc6lib", "", "input dc6lib file (required)")
o.dc6Path = flag.String("dc6", "", "input dc6lib file (required)")
o.palPath = flag.String("pal", "", "input pal file (optional)")
o.pngPath = flag.String("png", "", "path to png file (optional)")

Expand Down
11 changes: 6 additions & 5 deletions cmd/dc6-view/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"image/color"
"io/ioutil"
"path"
"path/filepath"

"github.com/AllenDang/giu"

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

Expand All @@ -32,7 +33,7 @@ func main() {

srcPath := *o.dc6Path

fileContents, err := ioutil.ReadFile(srcPath)
fileContents, err := ioutil.ReadFile(filepath.Clean(srcPath))
if err != nil {
const fmtErr = "could not read file, %w"

Expand All @@ -41,7 +42,7 @@ func main() {
return
}

dc6, err := pdc6lib.FromBytes(fileContents)
dc6, err := dc6lib.FromBytes(fileContents)
if err != nil {
fmt.Print(err)
return
Expand All @@ -63,7 +64,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"`
}
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module github.com/gravestench/dc6
module github.com/OpenDiablo2/dc6

go 1.16

require (
github.com/AllenDang/giu v0.5.4
github.com/OpenDiablo2/bitstream v0.0.0-20210818234514-9fca7e40e2b3
github.com/enriquebris/goconcurrentqueue v0.6.0
github.com/go-resty/resty/v2 v2.6.0 // indirect
github.com/gravestench/bitstream v0.0.0-20210602033510-6e018ddc185f
github.com/gravestench/gpl v0.0.0-20210615232229-779e263cf91e // indirect
github.com/gravestench/gpl v0.0.0-20210615232229-779e263cf91e
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
)
Loading