-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
104 lines (89 loc) · 2.26 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"image"
"log"
"net/http"
_ "net/http/pprof"
"os"
"github.com/itiky/goPixelWorld/engine"
"github.com/itiky/goPixelWorld/world"
"github.com/itiky/goPixelWorld/world/materials"
worldTypes "github.com/itiky/goPixelWorld/world/types"
)
func main() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
//monitorKeeper, err := monitor.NewKeeper(10 * time.Second)
//if err != nil {
// log.Fatalf("monitor.NewKeeper: %v", err)
//}
worldMap, err := world.NewMap(
world.WithWidth(250),
world.WithHeight(250),
world.WithNatureEffects(),
//world.WithMonitor(monitorKeeper),
)
if err != nil {
log.Fatalf("creating world.Map: %v", err)
}
imageData, err := parseImage()
if err != nil {
log.Fatalf("parsing image: %v", err)
}
if imageData != nil {
if err := worldMap.SetImageData(imageData); err != nil {
log.Fatalf("setting image data: %v", err)
}
}
materialsAll := []worldTypes.MaterialI{
materials.NewSand(), // 1
materials.NewWater(), // 2
materials.NewWood(), // 3
materials.NewGrass(), // 4
materials.NewFire(), // 5
materials.NewRock(), // 6
materials.NewMetal(), // 7
materials.NewBug(), // 8
materials.NewGraviton(), // 9
materials.NewAntiGraviton(), // 0
materials.NewSmoke(),
materials.NewSteam(),
}
runner, err := engine.NewRunner(
worldMap,
engine.WithScreenSize(1200, 1100),
engine.WithEditorUI(materialsAll...),
//engine.WithMonitor(monitorKeeper),
)
if err != nil {
log.Fatalf("creating engine.Runner: %v", err)
}
//ctx, ctxCancel := context.WithCancel(context.Background())
//defer ctxCancel()
//monitorKeeper.Start(ctx)
if err := runner.Run(); err != nil {
log.Fatalf("running engine.Runner: %v", err)
}
}
// parseImage parses an image by path (if the corresponding CLI args is provided).
func parseImage() (image.Image, error) {
var filePath string
if len(os.Args) > 1 {
filePath = os.Args[1]
}
if filePath == "" {
return nil, nil
}
f, err := os.Open(filePath)
if err != nil {
return nil, fmt.Errorf("opening file: %w", err)
}
defer f.Close()
imageData, _, err := image.Decode(f)
if err != nil {
return nil, fmt.Errorf("decoding image: %w", err)
}
return imageData, nil
}