summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--biome_infos.go367
-rw-r--r--colbuf.go17
-rw-r--r--main.go88
-rw-r--r--mapwidget.go10
-rw-r--r--region_wrapper.go16
-rw-r--r--test.biomes3
6 files changed, 264 insertions, 237 deletions
diff --git a/biome_infos.go b/biome_infos.go
index c45294c..b552328 100644
--- a/biome_infos.go
+++ b/biome_infos.go
@@ -1,206 +1,185 @@
package main
import (
+ "bufio"
+ "fmt"
"github.com/kch42/gomcmap/mcmap"
"github.com/mattn/go-gtk/gdk"
+ "io"
+ "strconv"
+ "strings"
)
-var bioList = []mcmap.Biome{
- mcmap.BioOcean,
- mcmap.BioPlains,
- mcmap.BioDesert,
- mcmap.BioExtremeHills,
- mcmap.BioForest,
- mcmap.BioTaiga,
- mcmap.BioSwampland,
- mcmap.BioRiver,
- mcmap.BioHell,
- mcmap.BioSky,
- mcmap.BioFrozenOcean,
- mcmap.BioFrozenRiver,
- mcmap.BioIcePlains,
- mcmap.BioIceMountains,
- mcmap.BioMushroomIsland,
- mcmap.BioMushroomIslandShore,
- mcmap.BioBeach,
- mcmap.BioDesertHills,
- mcmap.BioForestHills,
- mcmap.BioTaigaHills,
- mcmap.BioExtremeHillsEdge,
- mcmap.BioJungle,
- mcmap.BioJungleHills,
- mcmap.BioJungleEdge,
- mcmap.BioDeepOcean,
- mcmap.BioStoneBeach,
- mcmap.BioColdBeach,
- mcmap.BioBirchForest,
- mcmap.BioBirchForestHills,
- mcmap.BioRoofedForest,
- mcmap.BioColdTaiga,
- mcmap.BioColdTaigaHills,
- mcmap.BioMegaTaiga,
- mcmap.BioMegaTaigaHills,
- mcmap.BioExtremeHillsPlus,
- mcmap.BioSavanna,
- mcmap.BioSavannaPlateau,
- mcmap.BioMesa,
- mcmap.BioMesaPlateauF,
- mcmap.BioMesaPlateau,
- mcmap.BioSunflowerPlains,
- mcmap.BioDesertM,
- mcmap.BioExtremeHillsM,
- mcmap.BioFlowerForest,
- mcmap.BioTaigaM,
- mcmap.BioSwamplandM,
- mcmap.BioIcePlainsSpikes,
- mcmap.BioIceMountainsSpikes,
- mcmap.BioJungleM,
- mcmap.BioJungleEdgeM,
- mcmap.BioBirchForestM,
- mcmap.BioBirchForestHillsM,
- mcmap.BioRoofedForestM,
- mcmap.BioColdTaigaM,
- mcmap.BioMegaSpruceTaiga,
- mcmap.BioMegaSpruceTaigaHills,
- mcmap.BioExtremeHillsPlusM,
- mcmap.BioSavannaM,
- mcmap.BioSavannaPlateauM,
- mcmap.BioMesaBryce,
- mcmap.BioMesaPlateauFM,
- mcmap.BioMesaPlateauM,
- mcmap.BioUncalculated,
+type BiomeInfo struct {
+ ID mcmap.Biome
+ SnowLine int
+ Color string
+ Name string
}
-var bioColors = map[mcmap.Biome]*gdk.Color{
- mcmap.BioOcean: gdk.NewColor("#0000ff"),
- mcmap.BioPlains: gdk.NewColor("#9fe804"),
- mcmap.BioDesert: gdk.NewColor("#f5ff58"),
- mcmap.BioExtremeHills: gdk.NewColor("#a75300"),
- mcmap.BioForest: gdk.NewColor("#006f2a"),
- mcmap.BioTaiga: gdk.NewColor("#05795a"),
- mcmap.BioSwampland: gdk.NewColor("#6a7905"),
- mcmap.BioRiver: gdk.NewColor("#196eff"),
- mcmap.BioHell: gdk.NewColor("#d71900"),
- mcmap.BioSky: gdk.NewColor("#871eb3"),
- mcmap.BioFrozenOcean: gdk.NewColor("#d6f0ff"),
- mcmap.BioFrozenRiver: gdk.NewColor("#8fb6cd"),
- mcmap.BioIcePlains: gdk.NewColor("#fbfbfb"),
- mcmap.BioIceMountains: gdk.NewColor("#c6bfb1"),
- mcmap.BioMushroomIsland: gdk.NewColor("#9776a4"),
- mcmap.BioMushroomIslandShore: gdk.NewColor("#9e8ebc"),
- mcmap.BioBeach: gdk.NewColor("#fffdc9"),
- mcmap.BioDesertHills: gdk.NewColor("#adb354"),
- mcmap.BioForestHills: gdk.NewColor("#40694f"),
- mcmap.BioTaigaHills: gdk.NewColor("#5b8578"),
- mcmap.BioExtremeHillsEdge: gdk.NewColor("#a77748"),
- mcmap.BioJungle: gdk.NewColor("#22db04"),
- mcmap.BioJungleHills: gdk.NewColor("#63bf54"),
- mcmap.BioJungleEdge: gdk.NewColor("#40ba2c"),
- mcmap.BioDeepOcean: gdk.NewColor("#0000b3"),
- mcmap.BioStoneBeach: gdk.NewColor("#9292a6"),
- mcmap.BioColdBeach: gdk.NewColor("#c7c7e8"),
- mcmap.BioBirchForest: gdk.NewColor("#1d964b"),
- mcmap.BioBirchForestHills: gdk.NewColor("#498045"),
- mcmap.BioRoofedForest: gdk.NewColor("#075a26"),
- mcmap.BioColdTaiga: gdk.NewColor("#1b948e"),
- mcmap.BioColdTaigaHills: gdk.NewColor("#1d7a76"),
- mcmap.BioMegaTaiga: gdk.NewColor("#1f8f68"),
- mcmap.BioMegaTaigaHills: gdk.NewColor("#217a5c"),
- mcmap.BioExtremeHillsPlus: gdk.NewColor("#d76a00"),
- mcmap.BioSavanna: gdk.NewColor("#b2bc0f"),
- mcmap.BioSavannaPlateau: gdk.NewColor("#aba60e"),
- mcmap.BioMesa: gdk.NewColor("#ff6c00"),
- mcmap.BioMesaPlateauF: gdk.NewColor("#d9691e"),
- mcmap.BioMesaPlateau: gdk.NewColor("#d95b07"),
- mcmap.BioSunflowerPlains: gdk.NewColor("#ffd504"),
- mcmap.BioDesertM: gdk.NewColor("#f4ff3f"),
- mcmap.BioExtremeHillsM: gdk.NewColor("#8c4500"),
- mcmap.BioFlowerForest: gdk.NewColor("#e02f4a"),
- mcmap.BioTaigaM: gdk.NewColor("#0a6148"),
- mcmap.BioSwamplandM: gdk.NewColor("#58630e"),
- mcmap.BioIcePlainsSpikes: gdk.NewColor("#ace8e8"),
- mcmap.BioIceMountainsSpikes: gdk.NewColor("#91cccc"),
- mcmap.BioJungleM: gdk.NewColor("#30ba07"),
- mcmap.BioJungleEdgeM: gdk.NewColor("#3e9130"),
- mcmap.BioBirchForestM: gdk.NewColor("#228548"),
- mcmap.BioBirchForestHillsM: gdk.NewColor("#2b7547"),
- mcmap.BioRoofedForestM: gdk.NewColor("#1a5428"),
- mcmap.BioColdTaigaM: gdk.NewColor("#0f706b"),
- mcmap.BioMegaSpruceTaiga: gdk.NewColor("#198058"),
- mcmap.BioMegaSpruceTaigaHills: gdk.NewColor("#156e4c"),
- mcmap.BioExtremeHillsPlusM: gdk.NewColor("#ba5c00"),
- mcmap.BioSavannaM: gdk.NewColor("#858111"),
- mcmap.BioSavannaPlateauM: gdk.NewColor("#87830b"),
- mcmap.BioMesaBryce: gdk.NewColor("#ff5100"),
- mcmap.BioMesaPlateauFM: gdk.NewColor("#ba5a1a"),
- mcmap.BioMesaPlateauM: gdk.NewColor("#ba4e06"),
- mcmap.BioUncalculated: gdk.NewColor("#333333"),
+func ReadBiomeInfos(r io.Reader) ([]BiomeInfo, error) {
+ var biomes []BiomeInfo
+
+ sc := bufio.NewScanner(r)
+ for i := 1; sc.Scan(); i++ {
+ line := sc.Text()
+ if line == "" {
+ continue
+ }
+ parts := strings.SplitN(line, "\t", 4)
+
+ if len(parts) != 4 {
+ return nil, fmt.Errorf("Line %d corrupted: Not enough parts", i)
+ }
+
+ id, err := strconv.ParseUint(parts[0], 10, 8)
+ if err != nil {
+ return nil, fmt.Errorf("Line %d corrupted: %s", i, err)
+ }
+
+ snow, err := strconv.ParseInt(parts[1], 10, 32)
+ if err != nil {
+ return nil, fmt.Errorf("Line %d corrupted: %s", i, err)
+ }
+ if (snow >= mcmap.ChunkSizeY) || (snow < 0) {
+ snow = mcmap.ChunkSizeY
+ }
+
+ info := BiomeInfo{
+ ID: mcmap.Biome(id),
+ SnowLine: int(snow),
+ Color: parts[2],
+ Name: parts[3],
+ }
+ fmt.Println(info)
+ biomes = append(biomes, info)
+ }
+
+ if err := sc.Err(); err != nil {
+ return nil, err
+ }
+
+ return biomes, nil
}
-// snowLines maps a biome to the lowest y coordinate that can have snow naturally.
-// TODO: Get the actual values that Minecraft uses (could not find them).
-var snowLines = map[mcmap.Biome]int{
- mcmap.BioOcean: mcmap.ChunkSizeY,
- mcmap.BioPlains: mcmap.ChunkSizeY,
- mcmap.BioDesert: mcmap.ChunkSizeY,
- mcmap.BioExtremeHills: 95,
- mcmap.BioForest: mcmap.ChunkSizeY,
- mcmap.BioTaiga: mcmap.ChunkSizeY,
- mcmap.BioSwampland: mcmap.ChunkSizeY,
- mcmap.BioRiver: mcmap.ChunkSizeY,
- mcmap.BioHell: mcmap.ChunkSizeY,
- mcmap.BioSky: mcmap.ChunkSizeY,
- mcmap.BioFrozenOcean: 0,
- mcmap.BioFrozenRiver: 0,
- mcmap.BioIcePlains: 0,
- mcmap.BioIceMountains: 0,
- mcmap.BioMushroomIsland: mcmap.ChunkSizeY,
- mcmap.BioMushroomIslandShore: mcmap.ChunkSizeY,
- mcmap.BioBeach: mcmap.ChunkSizeY,
- mcmap.BioDesertHills: mcmap.ChunkSizeY,
- mcmap.BioForestHills: mcmap.ChunkSizeY,
- mcmap.BioTaigaHills: 0,
- mcmap.BioExtremeHillsEdge: 95,
- mcmap.BioJungle: mcmap.ChunkSizeY,
- mcmap.BioJungleHills: mcmap.ChunkSizeY,
- mcmap.BioJungleEdge: mcmap.ChunkSizeY,
- mcmap.BioDeepOcean: mcmap.ChunkSizeY,
- mcmap.BioStoneBeach: mcmap.ChunkSizeY,
- mcmap.BioColdBeach: 0,
- mcmap.BioBirchForest: mcmap.ChunkSizeY,
- mcmap.BioBirchForestHills: mcmap.ChunkSizeY,
- mcmap.BioRoofedForest: mcmap.ChunkSizeY,
- mcmap.BioColdTaiga: 0,
- mcmap.BioColdTaigaHills: 0,
- mcmap.BioMegaTaiga: mcmap.ChunkSizeY,
- mcmap.BioMegaTaigaHills: mcmap.ChunkSizeY,
- mcmap.BioExtremeHillsPlus: 95,
- mcmap.BioSavanna: mcmap.ChunkSizeY,
- mcmap.BioSavannaPlateau: mcmap.ChunkSizeY,
- mcmap.BioMesa: mcmap.ChunkSizeY,
- mcmap.BioMesaPlateauF: mcmap.ChunkSizeY,
- mcmap.BioMesaPlateau: mcmap.ChunkSizeY,
- mcmap.BioSunflowerPlains: mcmap.ChunkSizeY,
- mcmap.BioDesertM: mcmap.ChunkSizeY,
- mcmap.BioExtremeHillsM: 95,
- mcmap.BioFlowerForest: mcmap.ChunkSizeY,
- mcmap.BioTaigaM: mcmap.ChunkSizeY,
- mcmap.BioSwamplandM: mcmap.ChunkSizeY,
- mcmap.BioIcePlainsSpikes: 0,
- mcmap.BioIceMountainsSpikes: 0,
- mcmap.BioJungleM: mcmap.ChunkSizeY,
- mcmap.BioJungleEdgeM: mcmap.ChunkSizeY,
- mcmap.BioBirchForestM: mcmap.ChunkSizeY,
- mcmap.BioBirchForestHillsM: mcmap.ChunkSizeY,
- mcmap.BioRoofedForestM: mcmap.ChunkSizeY,
- mcmap.BioColdTaigaM: 0,
- mcmap.BioMegaSpruceTaiga: mcmap.ChunkSizeY,
- mcmap.BioMegaSpruceTaigaHills: mcmap.ChunkSizeY,
- mcmap.BioExtremeHillsPlusM: 95,
- mcmap.BioSavannaM: mcmap.ChunkSizeY,
- mcmap.BioSavannaPlateauM: mcmap.ChunkSizeY,
- mcmap.BioMesaBryce: mcmap.ChunkSizeY,
- mcmap.BioMesaPlateauFM: mcmap.ChunkSizeY,
- mcmap.BioMesaPlateauM: mcmap.ChunkSizeY,
- mcmap.BioUncalculated: mcmap.ChunkSizeY,
+func WriteBiomeInfos(biomes []BiomeInfo, w io.Writer) error {
+ for _, bio := range biomes {
+ if _, err := fmt.Fprintf(w, "%d\t%d\t%s\t%s\n", bio.ID, bio.SnowLine, bio.Color, bio.Name); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+type BiomeLookup map[mcmap.Biome]BiomeInfo
+
+var colBlack = gdk.NewColor("#000000")
+var colBuf = make(ColorBuffer)
+
+func (bl BiomeLookup) Color(bio mcmap.Biome) *gdk.Color {
+ if info, ok := bl[bio]; ok {
+ return colBuf.Color(info.Color)
+ }
+
+ fmt.Println("FAIL")
+ return colBlack
+}
+
+func (bl BiomeLookup) SnowLine(bio mcmap.Biome) int {
+ if info, ok := bl[bio]; ok {
+ return info.SnowLine
+ }
+
+ return mcmap.ChunkSizeY
+}
+
+func (bl BiomeLookup) Name(bio mcmap.Biome) string {
+ if info, ok := bl[bio]; ok {
+ return info.Name
+ }
+
+ return "?"
+}
+
+func MkBiomeLookup(biomes []BiomeInfo) BiomeLookup {
+ lookup := make(BiomeLookup)
+ for _, biome := range biomes {
+ lookup[biome.ID] = biome
+ }
+ return lookup
+}
+
+var defaultBiomes = `0 -1 #0000ff Ocean
+1 -1 #9fe804 Plains
+2 -1 #f5ff58 Desert
+3 95 #a75300 Extreme Hills
+4 -1 #006f2a Forest
+5 -1 #05795a Taiga
+6 -1 #6a7905 Swampland
+7 -1 #196eff River
+8 -1 #d71900 Hell
+9 -1 #871eb3 Sky
+10 0 #d6f0ff Frozen Ocean
+11 0 #8fb6cd Frozen River
+12 0 #fbfbfb Ice Plains
+13 0 #c6bfb1 Ice Mountains
+14 -1 #9776a4 Mushroom Island
+15 -1 #9e8ebc Mushroom Island Shore
+16 -1 #fffdc9 Beach
+17 -1 #adb354 Desert Hills
+18 -1 #40694f Forest Hills
+19 0 #5b8578 Taiga Hills
+20 95 #a77748 Extreme Hills Edge
+21 -1 #22db04 Jungle
+22 -1 #63bf54 Jungle Hills
+23 -1 #40ba2c Jungle Edge
+24 -1 #0000b3 Deep Ocean
+25 -1 #9292a6 Stone Beach
+26 0 #c7c7e8 Cold Beach
+27 -1 #1d964b Birch Forest
+28 -1 #498045 Birch Forest Hills
+29 -1 #075a26 Roofed Forest
+30 0 #1b948e Cold Taiga
+31 0 #1d7a76 Cold Taiga Hills
+32 -1 #1f8f68 Mega Taiga
+33 -1 #217a5c Mega Taiga Hills
+34 95 #d76a00 Extreme Hills+
+35 -1 #b2bc0f Savanna
+36 -1 #aba60e Savanna Plateau
+37 -1 #ff6c00 Mesa
+38 -1 #d9691e Mesa Plateau F
+39 -1 #d95b07 Mesa Plateau
+40 -1 #ffd504 Sunflower Plains
+41 -1 #f4ff3f Desert M
+42 95 #8c4500 Extreme Hills M
+43 -1 #e02f4a Flower Forest
+44 -1 #0a6148 Taiga M
+45 -1 #58630e Swampland M
+46 0 #ace8e8 Ice Plains Spikes
+47 0 #91cccc Ice Mountains Spikes
+48 -1 #30ba07 Jungle M
+49 -1 #3e9130 JungleEdge M
+50 -1 #228548 Birch Forest M
+51 -1 #2b7547 Birch Forest Hills M
+52 -1 #1a5428 Roofed Forest M
+53 0 #0f706b Cold Taiga M
+54 -1 #198058 Mega Spruce Taiga
+55 -1 #156e4c Mega Spruce Taiga Hills
+56 95 #ba5c00 Extreme Hills+ M
+57 -1 #858111 Savanna M
+58 -1 #87830b Savanna Plateau M
+59 -1 #ff5100 Mesa (Bryce)
+60 -1 #ba5a1a Mesa Plateau F M
+61 -1 #ba4e06 Mesa Plateau M
+255 -1 #333333 (Uncalculated)
+`
+
+func ReadDefaultBiomes() []BiomeInfo {
+ r := strings.NewReader(defaultBiomes)
+ biomes, err := ReadBiomeInfos(r)
+ if err != nil {
+ panic(err)
+ }
+ return biomes
}
diff --git a/colbuf.go b/colbuf.go
new file mode 100644
index 0000000..429bf6c
--- /dev/null
+++ b/colbuf.go
@@ -0,0 +1,17 @@
+package main
+
+import (
+ "github.com/mattn/go-gtk/gdk"
+)
+
+type ColorBuffer map[string]*gdk.Color
+
+func (cb ColorBuffer) Color(name string) *gdk.Color {
+ if col, ok := cb[name]; ok {
+ return col
+ }
+
+ col := gdk.NewColor(name)
+ cb[name] = col
+ return col
+}
diff --git a/main.go b/main.go
index 1351c27..11468b8 100644
--- a/main.go
+++ b/main.go
@@ -21,6 +21,11 @@ type GUI struct {
statusContext uint
lastStatus string
+ sbVBox *gtk.VBox
+
+ biomes []BiomeInfo
+ bioVBox *gtk.VBox
+
mapw *MapWidget
}
@@ -99,20 +104,23 @@ func (g *GUI) mkMenuBar() *gtk.MenuBar {
quit.Connect("activate", g.exitApp)
fileMenu.Append(quit)
+ foo := gtk.NewMenuItemWithLabel("Foo")
+ foo.Connect("activate", func() {
+ f, _ := os.Open("test.biomes")
+ defer f.Close()
+ biomes, err := ReadBiomeInfos(f)
+ if err != nil {
+ panic(err)
+ }
+ g.biomes = biomes
+ g.updateBiomeInfo()
+ })
+ fileMenu.Append(foo)
+
fileMenuItem := gtk.NewMenuItemWithLabel("File")
fileMenuItem.SetSubmenu(fileMenu)
menubar.Append(fileMenuItem)
- /*editMenu := gtk.NewMenu()
-
- undo := gtk.NewMenuItemWithLabel("Undo")
- undo.Connect("activate", g.undo)
- editMenu.Append(undo)
-
- editMenuItem := gtk.NewMenuItemWithLabel("Edit")
- editMenuItem.SetSubmenu(editMenu)
- menubar.Append(editMenuItem)*/
-
helpMenu := gtk.NewMenu()
controls := gtk.NewMenuItemWithLabel("Controls")
@@ -174,19 +182,19 @@ func labelCustomFont(text, font string) *gtk.Label {
}
func (g *GUI) mkSidebar() *gtk.ScrolledWindow {
- vbox := gtk.NewVBox(false, 0)
+ g.sbVBox = gtk.NewVBox(false, 0)
- vbox.PackStart(labelCustomFont("Tools", "Sans Bold 14"), false, false, 3)
+ g.sbVBox.PackStart(labelCustomFont("Tools", "Sans Bold 14"), false, false, 3)
g.showbiomes = gtk.NewCheckButtonWithLabel("Show Biomes")
g.showbiomes.SetActive(true)
g.showbiomes.Connect("toggled", g.showbiomesToggled)
- vbox.PackStart(g.showbiomes, false, false, 3)
+ g.sbVBox.PackStart(g.showbiomes, false, false, 3)
g.fixSnowIce = gtk.NewCheckButtonWithLabel("Fix Snow/Ice")
g.fixSnowIce.SetTooltipText("Add Snow/Ice for Taiga/Ice Plains. Remove Snow/Ice for other biomes.")
g.fixSnowIce.Connect("toggled", g.fixSnowIceToggled)
- vbox.PackStart(g.fixSnowIce, false, false, 3)
+ g.sbVBox.PackStart(g.fixSnowIce, false, false, 3)
fill := gtk.NewRadioButtonWithLabel(nil, "Fill")
fill.SetActive(true)
@@ -200,32 +208,50 @@ func (g *GUI) mkSidebar() *gtk.ScrolledWindow {
drawHBox.PackEnd(drawRadius, false, false, 3)
draw.Connect("toggled", g.mkUpdateToolFx(draw, NewDrawTool(func() int { return drawRadius.GetValueAsInt() })))
- vbox.PackStart(fill, false, false, 3)
- vbox.PackStart(drawHBox, false, false, 3)
+ g.sbVBox.PackStart(fill, false, false, 3)
+ g.sbVBox.PackStart(drawHBox, false, false, 3)
- vbox.PackStart(gtk.NewHSeparator(), false, false, 3)
- vbox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), false, false, 3)
+ g.sbVBox.PackStart(gtk.NewHSeparator(), false, false, 3)
+ g.sbVBox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), false, false, 3)
+
+ g.bioVBox = gtk.NewVBox(false, 0)
+ g.sbVBox.PackStart(g.bioVBox, true, false, 3)
+ g.updateBiomeInfo()
+
+ scrolled := gtk.NewScrolledWindow(nil, nil)
+ scrolled.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ scrolled.AddWithViewPort(g.sbVBox)
+ return scrolled
+}
+func (g *GUI) updateBiomeInfo() {
+ vbox := gtk.NewVBox(false, 0)
var grp *glib.SList
- for _, bio := range bioList {
+
+ for _, biome := range g.biomes {
biohbox := gtk.NewHBox(false, 0)
- cbox := colorBox(bioColors[bio])
+ cbox := colorBox(gdk.NewColor(biome.Color))
cbox.SetSizeRequest(20, 20)
biohbox.PackStart(cbox, false, false, 3)
- rbutton := gtk.NewRadioButtonWithLabel(grp, bio.String())
+ rbutton := gtk.NewRadioButtonWithLabel(grp, biome.Name)
grp = rbutton.GetGroup()
- rbutton.Connect("toggled", g.mkUpdateBiomeFx(rbutton, bio))
+ rbutton.Connect("toggled", g.mkUpdateBiomeFx(rbutton, biome.ID))
biohbox.PackEnd(rbutton, true, true, 3)
vbox.PackStart(biohbox, false, false, 3)
}
- scrolled := gtk.NewScrolledWindow(nil, nil)
- scrolled.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
- scrolled.AddWithViewPort(vbox)
- return scrolled
+ g.sbVBox.Remove(g.bioVBox)
+ g.bioVBox.Destroy()
+
+ g.sbVBox.PackStart(vbox, true, false, 3)
+ g.bioVBox = vbox
+
+ // TODO: Update mapwidget
}
func (g *GUI) Init() {
+ g.biomes = ReadDefaultBiomes()
+
g.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
g.window.SetTitle("biomed")
@@ -235,7 +261,7 @@ func (g *GUI) Init() {
hbox := gtk.NewHBox(false, 0)
- g.mapw = NewMapWidget(GUICallbacks{g.reportError, g.updateInfo, g.setBusy})
+ g.mapw = NewMapWidget(GUICallbacks{g.reportError, g.updateInfo, g.setBusy}, MkBiomeLookup(g.biomes))
hbox.PackStart(g.mapw.DArea(), true, true, 3)
sidebar := g.mkSidebar()
@@ -273,8 +299,8 @@ func (g *GUI) reportError(msg string) {
os.Exit(1)
}
-func (g *GUI) updateInfo(x, z int, bio mcmap.Biome) {
- g.lastStatus = fmt.Sprintf("X:%d, Z:%d, Biome:%s", x, z, bio)
+func (g *GUI) updateInfo(x, z int, bio mcmap.Biome, name string) {
+ g.lastStatus = fmt.Sprintf("X:%d, Z:%d, Biome: %s(%d)", x, z, name, bio)
g.statusbar.Pop(g.statusContext)
g.statusbar.Push(g.statusContext, g.lastStatus)
}
@@ -311,10 +337,6 @@ func (g *GUI) fixSnowIceToggled() {
g.mapw.SetFixSnowIce(g.fixSnowIce.GetActive())
}
-/*func (g *GUI) undo() {
- fmt.Println("Undo")
-}*/
-
func (g *GUI) Show() {
g.window.ShowAll()
g.betaWarning()
diff --git a/mapwidget.go b/mapwidget.go
index cb8c874..116f069 100644
--- a/mapwidget.go
+++ b/mapwidget.go
@@ -16,7 +16,7 @@ const (
type GUICallbacks struct {
reportFail func(msg string)
- updateInfo func(x, z int, bio mcmap.Biome)
+ updateInfo func(x, z int, bio mcmap.Biome, name string)
setBusy func(bool)
}
@@ -41,6 +41,8 @@ type MapWidget struct {
bg *gdk.Pixmap
regWrap *RegionWrapper
+
+ bioLookup BiomeLookup
}
func (mw *MapWidget) calcChunkRect() {
@@ -89,7 +91,7 @@ func (mw *MapWidget) movement(ctx *glib.CallbackContext) {
if _bio, ok := mw.regWrap.GetBiomeAt(x, z); ok {
bio = _bio
}
- mw.guicbs.updateInfo(x, z, bio)
+ mw.guicbs.updateInfo(x, z, bio, mw.bioLookup.Name(bio))
if mw.panning {
if (mw.mx1 != -1) && (mw.my1 != -1) {
@@ -231,7 +233,7 @@ func (mw *MapWidget) updateGUI() {
mw.dArea.GetWindow().Invalidate(nil, false)
}
-func NewMapWidget(guicbs GUICallbacks) *MapWidget {
+func NewMapWidget(guicbs GUICallbacks, bioLookup BiomeLookup) *MapWidget {
dArea := gtk.NewDrawingArea()
mw := &MapWidget{
@@ -240,9 +242,11 @@ func NewMapWidget(guicbs GUICallbacks) *MapWidget {
showBiomes: true,
mx1: -1,
my1: -1,
+ bioLookup: bioLookup,
}
mw.regWrap = NewRegionWrapper(mw.updateGUI, guicbs)
+ mw.regWrap.bioLookup = bioLookup
dArea.Connect("configure-event", mw.configure)
dArea.Connect("expose-event", mw.expose)
diff --git a/region_wrapper.go b/region_wrapper.go
index bf23913..9a4d958 100644
--- a/region_wrapper.go
+++ b/region_wrapper.go
@@ -28,9 +28,11 @@ type RegionWrapper struct {
bio mcmap.Biome
startX, startZ, endX, endZ int
+
+ bioLookup BiomeLookup
}
-func renderTile(chunk *mcmap.Chunk) (maptile, biotile *gdk.Pixmap, biocache []mcmap.Biome) {
+func (rw *RegionWrapper) renderTile(chunk *mcmap.Chunk) (maptile, biotile *gdk.Pixmap, biocache []mcmap.Biome) {
maptile = emptyPixmap(tileSize, tileSize, 24)
mtDrawable := maptile.GetDrawable()
mtGC := gdk.NewGC(mtDrawable)
@@ -46,7 +48,7 @@ func renderTile(chunk *mcmap.Chunk) (maptile, biotile *gdk.Pixmap, biocache []mc
scanX:
for x := 0; x < mcmap.ChunkSizeXZ; x++ {
bio := chunk.Biome(x, z)
- btGC.SetRgbFgColor(bioColors[bio])
+ btGC.SetRgbFgColor(rw.bioLookup.Color(bio))
btDrawable.DrawRectangle(btGC, true, x*zoom, z*zoom, zoom, zoom)
biocache[i] = bio
@@ -115,7 +117,7 @@ func (rw *RegionWrapper) tileUpdater() {
return
}
- rw.Maptiles[pos], rw.Biotiles[pos], rw.bioCache[pos] = renderTile(chunk)
+ rw.Maptiles[pos], rw.Biotiles[pos], rw.bioCache[pos] = rw.renderTile(chunk)
chunk.MarkUnused()
rw.redraw()
@@ -242,8 +244,8 @@ func (rw *RegionWrapper) GetBiomeAt(x, z int) (mcmap.Biome, bool) {
return chunk.Biome(bx, bz), true
}
-func fixWeather(bio mcmap.Biome, bx, bz int, chunk *mcmap.Chunk) (newcol *gdk.Color) {
- snowLine := snowLines[bio]
+func (rw *RegionWrapper) fixWeather(bio mcmap.Biome, bx, bz int, chunk *mcmap.Chunk) (newcol *gdk.Color) {
+ snowLine := rw.bioLookup.SnowLine(bio)
for y := mcmap.ChunkSizeY; y >= 0; y-- {
blk := chunk.Block(bx, y, bz)
@@ -306,7 +308,7 @@ func (rw *RegionWrapper) SetBiomeAt(x, z int, bio mcmap.Biome) {
var newcol *gdk.Color
if rw.fixSnowIce {
- newcol = fixWeather(bio, bx, bz, chunk)
+ newcol = rw.fixWeather(bio, bx, bz, chunk)
}
chunk.MarkModified()
@@ -322,7 +324,7 @@ func (rw *RegionWrapper) SetBiomeAt(x, z int, bio mcmap.Biome) {
drawable := biotile.GetDrawable()
gc := gdk.NewGC(drawable)
- gc.SetRgbFgColor(bioColors[bio])
+ gc.SetRgbFgColor(rw.bioLookup.Color(bio))
drawable.DrawRectangle(gc, true, bx*zoom, bz*zoom, zoom, zoom)
if newcol != nil {
diff --git a/test.biomes b/test.biomes
new file mode 100644
index 0000000..07dcf6f
--- /dev/null
+++ b/test.biomes
@@ -0,0 +1,3 @@
+0 10 #ff0000 Foo
+1 20 #00ff00 Bar
+2 30 #0000ff Baz