package main import ( "bytes" "fmt" "path" "strings" door "git.red-green.com/RedGreen/doorgo" ) var ( d door.Door ) func main() { d.Init("CyberRealms") defer d.Close() d.WriteS(door.Clrscr) w, err := LoadWorld(path.Join("data", "world")) if err != nil { fmt.Println("Err:", err) w = NewWorld("Overworld", NewVec2(100)) err := w.Save(path.Join("data", "world")) if err != nil { d.WriteS(door.ColorTextS("BRI RED ON BLA") + "Err: " + err.Error() + door.Reset + door.CRNL) d.WaitKey(door.Inactivity) return } } editor := NewEditor(w, NewVec2(int64(door.Width-2), int64(door.Height-2)), NewVec2()) if editor == nil { d.WriteS(door.ColorTextS("BRI RED ON BLA") + "Err: Failed initializing editor" + door.Reset + door.CRNL) d.WaitKey(door.Inactivity) return } p := door.Panel{ X: 1, Y: 1, Width: door.Width - 2, Style: door.SINGLE, BorderColor: door.ColorText("WHI ON BLA"), } for range make([]byte, door.Height-2) { p.Lines = append(p.Lines, &door.Line{ Text: bytes.NewBufferString(strings.Repeat(" ", door.Width-2)), }) } tile_menu := editor.TileMenu() EDITOR_LOOP: for { d.Write(p.Output()) d.WriteS(editor.Camera.View(editor.Pos, NewVec2(1, 2), editor.World) + door.GotoS(door.Width/2, door.Height/2)) r, ext, err := d.WaitKey(door.Inactivity) if err != nil { d.WriteS(door.ColorTextS("BRI RED ON BLA") + "Err: " + err.Error() + door.Reset + door.CRNL) d.WaitKey(door.Inactivity) return } if ext != door.NOP { switch ext { case door.UP_ARROW: editor.Pos.Translate(0, -1) case door.DOWN_ARROW: editor.Pos.Translate(0, 1) case door.LEFT_ARROW: editor.Pos.Translate(-1, 0) case door.RIGHT_ARROW: editor.Pos.Translate(1, 0) } } if r != 0 { switch r { case 't': fmt.Println("Show the tile menu, and jump to handling options for it") d.Write(tile_menu.Output()) d.WaitKey(door.Inactivity) case '5', '\r', '\n': fmt.Println("Allow selecting a tile index number to place a tile at current position") editor.World.Set(uint64(editor.Pos.X), uint64(editor.Pos.Y-1), 1) case 'q': break EDITOR_LOOP } } } err = editor.World.Save(path.Join("data", "world")) if err != nil { d.WriteS(door.ColorTextS("BRI RED ON BLA") + "Err: " + err.Error() + door.Reset + door.CRNL) d.WaitKey(door.Inactivity) return } }