Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
check-latest: true
go-version: '1.22'
check-latest: false
cache-dependency-path: go.sum

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ app
# Go workspace file
go.work

morphology.json
.saves/

main/main
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main"
}
]
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Maps
## How to move around
Zoom in: ctrl + wheel up
Zoom out: ctrl + wheel down

## How to draw
Enter in pencil mode: p
- Rubber: r
- Fill: f
Draw pixel by pixel: left click
23 changes: 12 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
module github.com/luca-patrignani/maps

go 1.20
go 1.22.0

require (
github.com/deckarep/golang-set/v2 v2.6.0
github.com/spf13/afero v1.11.0
)
toolchain go1.22.2

require github.com/deckarep/golang-set/v2 v2.6.0

require (
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8 // indirect
github.com/ebitengine/gomobile v0.0.0-20240911145611-4856209ac325 // indirect
github.com/ebitengine/hideconsole v1.0.0 // indirect
github.com/ebitengine/purego v0.7.0 // indirect
github.com/ebitengine/purego v0.8.0 // indirect
github.com/go-text/typesetting v0.2.0 // indirect
github.com/jezek/xgb v1.1.1 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/image v0.20.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
)

require (
github.com/hajimehoshi/ebiten/v2 v2.7.2
golang.org/x/text v0.14.0 // indirect
github.com/hajimehoshi/ebiten/v2 v2.8.6
golang.org/x/text v0.18.0 // indirect
)
37 changes: 22 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM=
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8 h1:5e8X7WEdOWrjrKvgaWF6PRnDvJicfrkEnwAkWtMN74g=
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8/go.mod h1:tWboRRNagZwwwis4QIgEFG1ZNFwBJ3LAhSLAXAAxobQ=
github.com/ebitengine/gomobile v0.0.0-20240911145611-4856209ac325 h1:Gk1XUEttOk0/hb6Tq3WkmutWa0ZLhNn/6fc6XZpM7tM=
github.com/ebitengine/gomobile v0.0.0-20240911145611-4856209ac325/go.mod h1:ulhSQcbPioQrallSuIzF8l1NKQoD7xmMZc5NxzibUMY=
github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE=
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
github.com/ebitengine/purego v0.7.0 h1:HPZpl61edMGCEW6XK2nsR6+7AnJ3unUxpTZBkkIXnMc=
github.com/ebitengine/purego v0.7.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/hajimehoshi/ebiten/v2 v2.7.2 h1:5HcWAjxhGMBocJh0jH/61Kx4QJ91HkzYtSeSucvVg7o=
github.com/hajimehoshi/ebiten/v2 v2.7.2/go.mod h1:1vjyPw+h3n30rfTOpIsbWRXSxZ0Oz1cYc6Tq/2DKoQg=
github.com/ebitengine/purego v0.8.0 h1:JbqvnEzRvPpxhCJzJJ2y0RbiZ8nyjccVUrSM3q+GvvE=
github.com/ebitengine/purego v0.8.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/go-text/typesetting v0.2.0 h1:fbzsgbmk04KiWtE+c3ZD4W2nmCRzBqrqQOvYlwAOdho=
github.com/go-text/typesetting v0.2.0/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I=
github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=
github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0 h1:0DISQM/rseKIJhdF29AkhvdzIULqNIIlXAGWit4ez1Q=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0/go.mod h1:8gLqGatKVu0pwcNCJguW3Igg9WQqVXF0zg/RvrGQWyg=
github.com/hajimehoshi/ebiten/v2 v2.8.6 h1:Dkd/sYI0TYyZRCE7GVxV59XC+WCi2BbGAbIBjXeVC1U=
github.com/hajimehoshi/ebiten/v2 v2.8.6/go.mod h1:cCQ3np7rdmaJa1ZnvslraVlpxNb3wCjEnAP1LHNyXNA=
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4=
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
golang.org/x/image v0.20.0 h1:7cVCUjQwfL18gyBJOmYvptfSHS8Fb3YUDtfLIZ7Nbpw=
golang.org/x/image v0.20.0/go.mod h1:0a88To4CYVBAHp5FXJm8o7QbUl37Vd85ply1vyD8auM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
44 changes: 44 additions & 0 deletions main/drawFillMode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/luca-patrignani/maps/geometry"
)

type DrawFillMode[T any] struct {
*State
geography geography[T]
foreground, background *T
label string
}

func (g *DrawFillMode[T]) Update() error {
if ebiten.IsMouseButtonPressed(ebiten.MouseButton0) {
x, y := ebiten.CursorPosition()
p := g.Unscaled(geometry.Point{X: x, Y: y})
g.geography.FillWith(p, *g.foreground, *g.background)
}
if inpututil.IsKeyJustPressed(ebiten.KeyF) {
Game.Wrapped = &DrawModePencil[T]{
g.State,
g.geography,
g.foreground,
g.background,
g.label,
}
}
return nil
}

func (g *DrawFillMode[T]) Draw(screen *ebiten.Image) {
normalMode.Draw(screen)
}

func (g *DrawFillMode[T]) Layout(outsideWidth, outsideHeight int) (int, int) {
return outsideWidth, outsideHeight
}

func (g DrawFillMode[T]) Name() string {
return g.label + ": Draw fill"
}
68 changes: 68 additions & 0 deletions main/drawPencilMode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"fmt"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/luca-patrignani/maps/geometry"
)

type DrawModePencil[T any] struct {
*State
geography geography[T]
foreground, background *T
label string
}

func (g *DrawModePencil[T]) Update() error {
x, y := ebiten.CursorPosition()
p := g.Unscaled(geometry.Point{X: x, Y: y})
if ebiten.IsMouseButtonPressed(ebiten.MouseButton0) {
if g.pendingPoint != nil {
g.geography.DrawLine(p, *g.pendingPoint, *g.foreground)
}
g.pendingPoint = &p
} else {
g.pendingPoint = nil
}
if ebiten.IsMouseButtonPressed(ebiten.MouseButton2) {
t, _ := g.geography.At(p)
g.foreground = &t
fmt.Println("You picked ", t)
}
if inpututil.IsKeyJustPressed(ebiten.KeyR) {
Game.Wrapped = &DrawModeRubber{
State: g.State,
}
}

if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
Game.Wrapped = &normalMode
}
if inpututil.IsKeyJustPressed(ebiten.KeyS) {
g.foreground, g.background = g.background, g.foreground
}
if inpututil.IsKeyJustPressed(ebiten.KeyF) {
Game.Wrapped = &DrawFillMode[T]{
State: g.State,
geography: g.geography,
foreground: g.foreground,
background: g.background,
label: g.label,
}
}
return nil
}

func (g *DrawModePencil[T]) Draw(screen *ebiten.Image) {
normalMode.Draw(screen)
}

func (g *DrawModePencil[T]) Layout(outsideWidth, outsideHeight int) (int, int) {
return outsideWidth, outsideHeight
}

func (g *DrawModePencil[T]) Name() string {
return g.label + ": Draw pencil"
}
52 changes: 52 additions & 0 deletions main/drawRubberMode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"image/color"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/vector"
"github.com/luca-patrignani/maps/geometry"
"github.com/luca-patrignani/maps/morphology"
)

type DrawModeRubber struct {
*State
}

func (g *DrawModeRubber) Update() error {
if ebiten.IsMouseButtonPressed(ebiten.MouseButton0) {
x, y := ebiten.CursorPosition()
p := g.Unscaled(geometry.Point{X: x, Y: y})
g.morph.DrawSquare(p, g.rubberSize, g.morphForeground)
}
_, wheelDy := ebiten.Wheel()
g.rubberSize += int(wheelDy)
if g.rubberSize < 1 {
g.rubberSize = 1
}
if inpututil.IsKeyJustPressed(ebiten.KeyR) {
Game.Wrapped = &DrawModePencil[morphology.MorphType]{
State: g.State,
geography: g.morph,
label: "morphology",
}
}
return nil
}

func (g *DrawModeRubber) Draw(screen *ebiten.Image) {
normalMode.Draw(screen)
ebiten.SetCursorMode(ebiten.CursorModeHidden)
x, y := ebiten.CursorPosition()
vector.StrokeRect(screen, float32(x), float32(y), float32(g.rubberSize*g.viewScale), float32(g.rubberSize*g.viewScale), float32(g.viewScale), color.Black, true)
ebiten.SetCursorMode(ebiten.CursorModeVisible)
}

func (g *DrawModeRubber) Layout(outsideWidth, outsideHeight int) (int, int) {
return outsideWidth, outsideHeight
}

func (g *DrawModeRubber) Name() string {
return "Draw rubber"
}
9 changes: 9 additions & 0 deletions main/geography.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import "github.com/luca-patrignani/maps/geometry"

type geography[T any] interface {
DrawLine(p1, p2 geometry.Point, t T)
FillWith(p geometry.Point, foreground, background T)
At(p geometry.Point) (T, bool)
}
34 changes: 34 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package main

import (
"bytes"
"image/color"
"log"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
"github.com/hajimehoshi/ebiten/v2/text/v2"
"github.com/luca-patrignani/maps/geometry"
"github.com/luca-patrignani/maps/morphology"
"github.com/luca-patrignani/maps/politics"
)

var (
Expand All @@ -16,6 +22,34 @@ func init() {
}

func main() {
faceSource, err := text.NewGoTextFaceSource(bytes.NewReader(fonts.MPlus1pRegular_ttf))
if err != nil {
log.Fatal(err)
}
morph := &morphology.Morphology{
Data: map[geometry.Point]morphology.MorphType{},
MinX: 0,
MinY: 0,
MaxX: 2000,
MaxY: 2000,
}
normalMode = NormalMode{State: &State{
morph: morph,
politics: &politics.PoliticalMap{
Data: make(map[geometry.Point]politics.PoliticalEntity),
Morphology: morph,
},
pendingPoint: &geometry.Point{},
morphForeground: morphology.Land,
morphBackground: morphology.Sea,
politicalForeground: politics.None,
politicalBackground: politics.None,
rubberSize: 40,
viewScale: 15,
viewOrigin: geometry.Point{X: 0, Y: 0},
faceSource: faceSource,
}}
Game = gameWrapper{Wrapped: &normalMode}
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
if err := ebiten.RunGame(&Game); err != nil {
log.Fatal(err)
Expand Down
Loading
Loading