This commit is contained in:
a.gurov 2018-07-31 18:15:49 +03:00
parent 25f5c388c9
commit 503af72b47
11 changed files with 51 additions and 28 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

58
main.go
View File

@ -5,43 +5,28 @@ import (
blt "bearlibterminal"
"ui"
"util"
"flag"
"io/ioutil"
"encoding/json"
"game"
)
var version = "0.0.0"
func main() {
defer shutdown()
log.Println("Starting...")
var configArg string = "./config.json"
flag.StringVar(&configArg, "cfg", configArg, "config file location")
flag.Parse()
// get config
data, err := ioutil.ReadFile(configArg)
if err != nil {
log.Fatalf("quoteCompressor can't read config at %s", configArg)
}
config := new(util.Config)
err = json.Unmarshal(data, config)
if err != nil {
log.Fatalln(err)
}
config := util.LoadConfig()
game.Init(config)
blt.Open()
//blt.Set("window: size=80x25, title="+config.Title+" v"+string(version)+"; font: ./fonts/Monaco-Linux.ttf, size=10")
blt.Set("window: size=100x47, title="+config.Title+" v"+string(version)+"; font: ./fonts/UbuntuMono-R.ttf, size=10;")
defer blt.Close()
blt.Set("window: size=100x47, title="+config.Title+" v"+string(version)+"; font: ./resources/fonts-bitmap/ibmnew8x12.png, size=8x12;")
blt.Print(1, 1, "Hello, [font=italic]world[/font]!")
blt.Print(1, 4, "Testing line-spacing")
blt.PrintExt(1, 6, 5, 4, 1, "Lorem ipsum dolor sit amet")
blt.Refresh()
mainLoop()
}
@ -50,16 +35,33 @@ func mainLoop () {
var exit = false
for !exit {
var key, keycode = ui.ReadKey();
if key != "" {
blt.Print( 1, 3, "Key: ")
var key, keycode = ui.ReadKey()
if key != "" {
blt.ClearArea(0,3, 80, 1)
}
blt.Print( 1, 3, "Key: " + key )
exit, _ = util.InArray(keycode, []int{blt.TK_CLOSE, blt.TK_ESCAPE})
if (!exit) {
exit = key == "Ctrl+q"
switch key {
case "F10":
blt.Set("window: size=100x47; font: ./resources/fonts-ttf/UbuntuMono-R.ttf, size=10;")
case "Ctrl+q":
fallthrough
case "Escape":
exit = true
default:
blt.Print( 1, 3, "Key: " + key )
}
if keycode ==blt.TK_CLOSE {
exit = true
}
blt.Refresh()
}
log.Println("Closing...")
}
func shutdown() {
log.Println("Here we must save state, but it is not done yet")
log.Println("Exiting application...")
blt.Close()
}

View File

@ -2,6 +2,10 @@ package util
import (
"reflect"
"flag"
"io/ioutil"
"log"
"encoding/json"
)
type Config struct {
@ -9,6 +13,23 @@ type Config struct {
FpsLimit int `json:"fpsLimit, omitempty" validate:"required"`
}
func LoadConfig () *Config {
var configArg string = "./config.json"
flag.StringVar(&configArg, "cfg", configArg, "config file location")
flag.Parse()
// get config
data, err := ioutil.ReadFile(configArg)
if err != nil {
log.Fatalf("Application couldn't read config at %s", configArg)
}
config := new(Config)
err = json.Unmarshal(data, config)
if err != nil {
log.Fatalln(err)
}
return config
}
func InArray(val interface{}, array interface{}) (exists bool, index int) {
exists = false