main.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "path"
  6. "strings"
  7. door "git.red-green.com/RedGreen/doorgo"
  8. )
  9. var (
  10. d door.Door
  11. )
  12. func main() {
  13. d.Init("CyberRealms")
  14. defer d.Close()
  15. d.WriteS(door.Clrscr)
  16. w, err := LoadWorld(path.Join("data", "world"))
  17. if err != nil {
  18. fmt.Println("Err:", err)
  19. w = NewWorld("Overworld", NewVec2(100))
  20. err := w.Save(path.Join("data", "world"))
  21. if err != nil {
  22. d.WriteS(door.ColorTextS("BRI RED ON BLA") + "Err: " + err.Error() + door.Reset + door.CRNL)
  23. d.WaitKey(door.Inactivity)
  24. return
  25. }
  26. }
  27. editor := NewEditor(w, NewVec2(int64(door.Width-2), int64(door.Height-2)), NewVec2())
  28. if editor == nil {
  29. d.WriteS(door.ColorTextS("BRI RED ON BLA") + "Err: Failed initializing editor" + door.Reset + door.CRNL)
  30. d.WaitKey(door.Inactivity)
  31. return
  32. }
  33. p := door.Panel{
  34. X: 1,
  35. Y: 1,
  36. Width: door.Width - 2,
  37. Style: door.SINGLE,
  38. BorderColor: door.ColorText("WHI ON BLA"),
  39. }
  40. for range make([]byte, door.Height-2) {
  41. p.Lines = append(p.Lines, &door.Line{
  42. Text: bytes.NewBufferString(strings.Repeat(" ", door.Width-2)),
  43. })
  44. }
  45. tile_menu := editor.TileMenu()
  46. EDITOR_LOOP:
  47. for {
  48. d.Write(p.Output())
  49. d.WriteS(editor.Camera.View(editor.Pos, NewVec2(1, 2), editor.World) + door.GotoS(door.Width/2, door.Height/2))
  50. r, ext, err := d.WaitKey(door.Inactivity)
  51. if err != nil {
  52. d.WriteS(door.ColorTextS("BRI RED ON BLA") + "Err: " + err.Error() + door.Reset + door.CRNL)
  53. d.WaitKey(door.Inactivity)
  54. return
  55. }
  56. if ext != door.NOP {
  57. switch ext {
  58. case door.UP_ARROW:
  59. editor.Pos.Translate(0, -1)
  60. case door.DOWN_ARROW:
  61. editor.Pos.Translate(0, 1)
  62. case door.LEFT_ARROW:
  63. editor.Pos.Translate(-1, 0)
  64. case door.RIGHT_ARROW:
  65. editor.Pos.Translate(1, 0)
  66. }
  67. }
  68. if r != 0 {
  69. switch r {
  70. case 't':
  71. fmt.Println("Show the tile menu, and jump to handling options for it")
  72. d.Write(tile_menu.Output())
  73. d.WaitKey(door.Inactivity)
  74. case '5', '\r', '\n':
  75. fmt.Println("Allow selecting a tile index number to place a tile at current position")
  76. editor.World.Set(uint64(editor.Pos.X), uint64(editor.Pos.Y-1), 1)
  77. case 'q':
  78. break EDITOR_LOOP
  79. }
  80. }
  81. }
  82. err = editor.World.Save(path.Join("data", "world"))
  83. if err != nil {
  84. d.WriteS(door.ColorTextS("BRI RED ON BLA") + "Err: " + err.Error() + door.Reset + door.CRNL)
  85. d.WaitKey(door.Inactivity)
  86. return
  87. }
  88. }