Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
weqqr committed Apr 28, 2024
1 parent 94ccf61 commit 0b3f4c2
Show file tree
Hide file tree
Showing 24 changed files with 287 additions and 169 deletions.
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ linters:
- goconst
- gosec
- nilerr
- nilnil
- nolintlint
- varnamelen
# - varnamelen
- wastedassign
- wsl
4 changes: 4 additions & 0 deletions cmd/panorama/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func fullrender(config config.Config) error {
slog.Error("unable to load game description", "error", err)
return err
}

backend, err := world.NewPostgresBackend(config.System.WorldDSN)
if err != nil {
slog.Error("unable to connect to world DB", "error", err)
Expand All @@ -56,6 +57,7 @@ func run(config config.Config) error {
quit := make(chan bool)

slog.Info("starting web server", "address", config.Web.ListenAddress)

go func() {
web.Serve(&config)
quit <- true
Expand All @@ -76,13 +78,15 @@ func main() {

commonFlags := flag.NewFlagSet("common flags", flag.ExitOnError)
commonFlags.StringVar(&args.ConfigPath, "config", "config.toml", "Path to config file")

err := commonFlags.Parse(os.Args[2:])
if err != nil {
slog.Error("unable to parse flags")
os.Exit(1)
}

slog.Info("loading config", "config_path", args.ConfigPath)

config, err := config.LoadConfig(args.ConfigPath)
if err != nil {
slog.Error("unable to load config", "error", err)
Expand Down
5 changes: 5 additions & 0 deletions internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func makeMeshNode(model *mesh.Model, tiles []*image.NRGBA) NodeDefinition {
if i >= len(tiles) {
break
}

textures[i] = tiles[i]
}

Expand Down Expand Up @@ -152,6 +153,7 @@ func LoadGame(desc string, path string, modpath string) (Game, error) {
}

var descriptor gameDescriptor

err = json.Unmarshal(descJSON, &descriptor)
if err != nil {
return Game{}, err
Expand All @@ -163,12 +165,14 @@ func LoadGame(desc string, path string, modpath string) (Game, error) {
if err != nil {
return Game{}, err
}

err = mediaCache.fetchMedia(modpath)
if err != nil {
return Game{}, err
}

nodes := make(map[string]NodeDefinition)

for name, gameNode := range descriptor.Nodes {
node := ResolveNode(gameNode, mediaCache)

Expand All @@ -190,5 +194,6 @@ func (g *Game) NodeDef(node string) NodeDefinition {
if def, ok := g.Nodes[node]; ok {
return def
}

return g.unknown
}
5 changes: 5 additions & 0 deletions internal/game/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type MediaCache struct {

func NewMediaCache() *MediaCache {
dummyImage := image.NewNRGBA(image.Rect(0, 0, 2, 2))

dummyImage.SetNRGBA(0, 0, color.NRGBA{255, 0, 255, 255})
dummyImage.SetNRGBA(0, 1, color.NRGBA{0, 0, 0, 255})
dummyImage.SetNRGBA(1, 0, color.NRGBA{0, 0, 0, 255})
Expand All @@ -39,15 +40,18 @@ func (m *MediaCache) fetchMedia(path string) error {
}

basePath := filepath.Base(path)

switch filepath.Ext(path) {
case ".png":
img, _ := raster.LoadPNG(path)
m.images[basePath] = img

case ".obj":
model, err := mesh.LoadOBJ(path)
if err != nil {
return err
}

m.models[basePath] = &model
}

Expand All @@ -72,6 +76,7 @@ func (m *MediaCache) Mesh(name string) *mesh.Model {
return model
} else {
slog.Warn("unknown image", "name", name)

return nil
}
}
10 changes: 10 additions & 0 deletions internal/game/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (t DrawType) IsLiquid() bool {

func (t *DrawType) UnmarshalJSON(data []byte) error {
var name string

err := json.Unmarshal(data, &name)
if err != nil {
return err
Expand Down Expand Up @@ -83,6 +84,7 @@ var ParamTypeNames = map[string]ParamType{

func (t *ParamType) UnmarshalJSON(data []byte) error {
name := "light"

err := json.Unmarshal(data, &name)
if err != nil {
return err
Expand Down Expand Up @@ -133,6 +135,7 @@ var ParamType2Names = map[string]ParamType2{

func (t *ParamType2) UnmarshalJSON(data []byte) error {
name := "none"

err := json.Unmarshal(data, &name)
if err != nil {
return err
Expand All @@ -157,13 +160,15 @@ func (n *NodeBox) UnmarshalJSON(data []byte) error {
Type string `json:"type"`
Fixed []interface{} `json:"fixed"`
}

inner := &nodeBox{}
if err := json.Unmarshal(data, inner); err != nil {
return err
}

n.Type = inner.Type
n.Fixed = make([][]float64, 0)

if inner.Type != "fixed" {
return nil
}
Expand All @@ -174,21 +179,25 @@ func (n *NodeBox) UnmarshalJSON(data []byte) error {

if _, ok := inner.Fixed[0].(float64); ok {
box := make([]float64, 0)

for i := 0; i < 6; i++ {
v, _ := inner.Fixed[i].(float64)
box = append(box, v)
}

n.Fixed = append(n.Fixed, box)
}

if _, ok := inner.Fixed[0].([]interface{}); ok {
for _, boxInterface := range inner.Fixed {
boxFloat64 := boxInterface.([]interface{})
box := make([]float64, 0)

for i := 0; i < 6; i++ {
v, _ := boxFloat64[i].(float64)
box = append(box, v)
}

n.Fixed = append(n.Fixed, box)
}
}
Expand All @@ -207,6 +216,7 @@ type NodeDescriptor struct {

func (n *NodeDescriptor) UnmarshalJSON(data []byte) error {
type nodeDescriptor NodeDescriptor

inner := &nodeDescriptor{
DrawType: DrawTypeNormal,
Tiles: []string{},
Expand Down
1 change: 1 addition & 0 deletions internal/lm/matrix3.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ func (lhs *Matrix3) MulVec(rhs Vector3) Vector3 {
x := lhs.m[0]*rhs.X + lhs.m[1]*rhs.Y + lhs.m[2]*rhs.Z
y := lhs.m[3]*rhs.X + lhs.m[4]*rhs.Y + lhs.m[5]*rhs.Z
z := lhs.m[6]*rhs.X + lhs.m[7]*rhs.Y + lhs.m[8]*rhs.Z

return Vec3(x, y, z)
}
6 changes: 6 additions & 0 deletions internal/lm/vector2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,41 @@ func Vec2(x, y float64) Vector2 {
func (lhs Vector2) Add(rhs Vector2) Vector2 {
x := lhs.X + rhs.X
y := lhs.Y + rhs.Y

return Vec2(x, y)
}

func (lhs Vector2) Sub(rhs Vector2) Vector2 {
x := lhs.X - rhs.X
y := lhs.Y - rhs.Y

return Vec2(x, y)
}

func (lhs Vector2) Mul(rhs Vector2) Vector2 {
x := lhs.X * rhs.X
y := lhs.Y * rhs.Y

return Vec2(x, y)
}

func (lhs Vector2) MulScalar(rhs float64) Vector2 {
x := lhs.X * rhs
y := lhs.Y * rhs

return Vec2(x, y)
}

func (lhs Vector2) Min(rhs Vector2) Vector2 {
x := math.Min(lhs.X, rhs.X)
y := math.Min(lhs.Y, rhs.Y)

return Vec2(x, y)
}

func (lhs Vector2) Max(rhs Vector2) Vector2 {
x := math.Max(lhs.X, rhs.X)
y := math.Max(lhs.Y, rhs.Y)

return Vec2(x, y)
}
9 changes: 9 additions & 0 deletions internal/lm/vector3.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ func (lhs Vector3) Add(rhs Vector3) Vector3 {
x := lhs.X + rhs.X
y := lhs.Y + rhs.Y
z := lhs.Z + rhs.Z

return Vec3(x, y, z)
}

func (lhs Vector3) MulScalar(rhs float64) Vector3 {
x := lhs.X * rhs
y := lhs.Y * rhs
z := lhs.Z * rhs

return Vec3(x, y, z)
}

Expand All @@ -33,20 +35,23 @@ func (lhs Vector3) DivScalar(rhs float64) Vector3 {
x := lhs.X * reciprocal
y := lhs.Y * reciprocal
z := lhs.Z * reciprocal

return Vec3(x, y, z)
}

func (lhs Vector3) PowScalar(power float64) Vector3 {
x := math.Pow(lhs.X, power)
y := math.Pow(lhs.Y, power)
z := math.Pow(lhs.Z, power)

return Vec3(x, y, z)
}

func (lhs Vector3) Cross(rhs Vector3) Vector3 {
x := lhs.Y*rhs.Z - lhs.Z*rhs.Y
y := lhs.Z*rhs.X - lhs.X*rhs.Z
z := lhs.X*rhs.Y - lhs.Y*rhs.X

return Vec3(x, y, z)
}

Expand All @@ -66,6 +71,7 @@ func (lhs Vector3) ClampScalar(min, max float64) Vector3 {
x := Clamp(lhs.X, min, max)
y := Clamp(lhs.Y, min, max)
z := Clamp(lhs.Z, min, max)

return Vec3(x, y, z)
}

Expand All @@ -80,17 +86,20 @@ func (lhs Vector3) MaxComponent() float64 {
func (lhs Vector3) RotateXY(angle float64) Vector3 {
cos := math.Cos(angle)
sin := math.Sin(angle)

return Vec3(lhs.X*cos-lhs.Y*sin, lhs.X*sin+lhs.Y*cos, lhs.Z)
}

func (lhs Vector3) RotateXZ(angle float64) Vector3 {
cos := math.Cos(angle)
sin := math.Sin(angle)

return Vec3(lhs.X*cos-lhs.Z*sin, lhs.Y, lhs.X*sin+lhs.Z*cos)
}

func (lhs Vector3) RotateYZ(angle float64) Vector3 {
cos := math.Cos(angle)
sin := math.Sin(angle)

return Vec3(lhs.X, lhs.Y*cos-lhs.Z*sin, lhs.Y*sin+lhs.Z*cos)
}
2 changes: 2 additions & 0 deletions internal/lm/vector4.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (lhs Vector4) MulScalar(rhs float64) Vector4 {
y := lhs.Y * rhs
z := lhs.Z * rhs
w := lhs.W * rhs

return Vec4(x, y, z, w)
}

Expand All @@ -26,6 +27,7 @@ func (lhs Vector4) ClampScalar(min, max float64) Vector4 {
y := Clamp(lhs.Y, min, max)
z := Clamp(lhs.Z, min, max)
w := Clamp(lhs.W, min, max)

return Vec4(x, y, z, w)
}

Expand Down
Loading

0 comments on commit 0b3f4c2

Please sign in to comment.