Now the basic game is there. It tracks your errors, you lose HPon an error, and you can die and try again.

master
Zed A. Shaw 10 months ago
parent 1302a6d3e0
commit bf170962bd
  1. 4
      .ttarpit.json
  2. 14
      config/settings.go
  3. 58
      main.go

@ -1,4 +1,5 @@
{
"StartingHP": 10,
"Includes": [
"^.*.go$"
],
@ -9,6 +10,7 @@
}
},
"Triggers": [
"(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*"
"(?<File>.*):(?<Line>[0-9]+):(?<Col>[0-9]+):\\s*(?<ErrType>.*):\\s*(?<Message>.*)",
"(?<File>.*):(?<Line>[0-9]+):(?<Col>[0-9]+):\\s*(?<Message>.*)"
]
}

@ -15,26 +15,30 @@ type Process struct {
ExecCmd *exec.Cmd
}
type config struct {
type Config struct {
Triggers []string
Includes []string
Processes map[string]Process
StartingHP int
ConfigPath string
BuildRunning bool
TriggerRegex []*regexp.Regexp
IncludeRegex []*regexp.Regexp
HP int
Errors int
}
var Settings config
var Settings Config
func parseFlags(c *config) {
func ParseFlags(c *Config) {
flag.StringVar(&c.ConfigPath, "config", ".ttarpit.json", ".ttarpit.json to load")
flag.Parse()
}
func Load() {
parseFlags(&Settings)
ParseFlags(&Settings)
data, err := os.ReadFile(Settings.ConfigPath)
if err != nil { log.Fatal(err) }
@ -49,4 +53,6 @@ func Load() {
for _, reg := range Settings.Includes {
Settings.IncludeRegex = append(Settings.IncludeRegex, regexp.MustCompile(reg))
}
Settings.HP = Settings.StartingHP
}

@ -13,8 +13,43 @@ import (
"lcthw.dev/go/ttarpit/config"
"github.com/fsnotify/fsnotify"
"bufio"
"regexp"
"strconv"
)
type ErrInfo struct {
File string
Line int
Col int
ErrType string
Message string
}
func ParseErrInfo(line string, reg *regexp.Regexp) (ErrInfo, bool) {
var info ErrInfo
matches := reg.FindStringSubmatch(line)
if matches == nil {
return info, false
}
et_index := reg.SubexpIndex("ErrType")
if et_index != -1 {
info.ErrType = matches[et_index]
}
// BUG: use reflect
info.File = matches[reg.SubexpIndex("File")]
info.Line, _ = strconv.Atoi(matches[reg.SubexpIndex("Line")])
info.Col, _ = strconv.Atoi(matches[reg.SubexpIndex("Col")])
info.Message = matches[reg.SubexpIndex("Message")]
return info, true
}
func LaunchLogger(in io.Reader, out io.Writer, err error) {
if err != nil { log.Fatal(err) }
@ -25,11 +60,11 @@ func LaunchLogger(in io.Reader, out io.Writer, err error) {
for _, reg := range config.Settings.TriggerRegex {
line := scan.Text()
matches := reg.FindStringSubmatch(line)
if len(matches) > 0 {
file, line, col, err_type, text := matches[1], matches[2], matches[3], matches[4], matches[5]
fmt.Printf("!!!!!!!!!!!!!! file=%s, line=%s, col=%s, type=%s, text=%s\n",
file, line, col, err_type, text)
errinfo, ok := ParseErrInfo(line, reg)
if ok {
fmt.Println("!!!!!!!!!!!!!!!!!", errinfo)
config.Settings.Errors++
config.Settings.HP--
}
}
}
@ -57,8 +92,6 @@ func LaunchProcess(proc *config.Process) {
fmt.Println("WAITING for", proc.Command)
fmt.Println("SENDING READY on channel")
proc.ExecCmd.Wait()
fmt.Println("PROCESS", proc.Command, "EXITED")
}
@ -89,7 +122,16 @@ func RunBuild() {
fmt.Println("PROCESS:", name)
LaunchProcess(&proc)
fmt.Println("=================== PROCESS EXIT")
fmt.Println("============== PROCESS EXIT")
fmt.Printf("==== HP: %d Errors: %d =====\n",
config.Settings.HP, config.Settings.Errors)
if config.Settings.HP <= 0 {
fmt.Println("!!!!!! YOU DIED !!!!!!!")
config.Settings.HP = config.Settings.StartingHP
}
fmt.Println("===========================")
}
time.Sleep(1000 * time.Millisecond)

Loading…
Cancel
Save