From 8b6b1f1ac0e44ee3a1a2be0ee1fbf48617d0552b Mon Sep 17 00:00:00 2001 From: Zhongheng Liu Date: Tue, 22 Oct 2024 21:08:43 +0300 Subject: [PATCH] feat: quick scaffolding for game window Init: Created initial NPC data structures UI: Created basic ncurses TUI for development Types: Created basic helper types --- main.go | 80 ++++++++++++++++++++++++++-- menu/menu.go | 22 ++++---- mknpcs.go | 18 +++++++ utils/types/menus.go | 10 ++++ utils/types/npcs.go | 12 +++++ utils/types/types.go | 20 +++++++ utils/window_helper.go | 6 --- utils/window_helper/window_helper.go | 13 +++++ 8 files changed, 159 insertions(+), 22 deletions(-) create mode 100644 mknpcs.go create mode 100644 utils/types/menus.go create mode 100644 utils/types/npcs.go create mode 100644 utils/types/types.go delete mode 100644 utils/window_helper.go create mode 100644 utils/window_helper/window_helper.go diff --git a/main.go b/main.go index 4629213..9e969ce 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,82 @@ package main import ( - "gitlab.com/stvnliu/ai_game/menu" + "time" + + . "github.com/gbin/goncurses" + "gitlab.com/stvnliu/ai_game/menu" + . "gitlab.com/stvnliu/ai_game/utils/types" + // "gitlab.com/stvnliu/ai_game/utils/window_helper" ) -func main() { - menu_items := []string{"New game", "Continue", "Exit"} - menu.CreateMenu(menu_items) +const ( + INPUT_PROMPT_LENGTH = 40 + INPUT_PROMPT_HEIGHT = 10 +) + +func InputPrompt(scr *Window) string { + my, mx := scr.MaxYX() + w, err := NewWindow(INPUT_PROMPT_HEIGHT, INPUT_PROMPT_LENGTH, (my/2)-(INPUT_PROMPT_HEIGHT/2), (mx/2)-(INPUT_PROMPT_LENGTH/2)) + if err != nil { + panic("Oh no sth went wrong in input!!") + } + w.Box(0, 0) + Echo(true) + msg := "Game name: " + w.MovePrint(0, 1, " New game information ") + w.MovePrint(2, 2, msg) + w.Move(2, 2+len(msg)) + input, err := w.GetString(16) // character input box + if err != nil { + panic("Oh no sth went wrong in input 2!!") + } + w.MovePrint(3, 2, input) + w.Refresh() + Echo(false) + for { + ch := w.GetChar() + switch Key(ch) { + case 'q': + return input + } + } +} +func NewGame(scr *Window) { + //_, _ := scr.MaxYX() + game_name := InputPrompt(scr) + // create new game state + // println("Creating new game %v...", game_name) + game := Game{ + SaveGame: game_name, + LastSaved: time.Now(), + } + my_npcs := MakeNpcs() + game.DataStored.Npcs = my_npcs + scr.MovePrintf(1, 2, "Created new game \"%v\"!", game.SaveGame) + for i:=0; i