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

@ -13,8 +13,43 @@ import (
"lcthw.dev/go/ttarpit/config" "lcthw.dev/go/ttarpit/config"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"bufio" "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) { func LaunchLogger(in io.Reader, out io.Writer, err error) {
if err != nil { log.Fatal(err) } 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 { for _, reg := range config.Settings.TriggerRegex {
line := scan.Text() line := scan.Text()
matches := reg.FindStringSubmatch(line) errinfo, ok := ParseErrInfo(line, reg)
if len(matches) > 0 { if ok {
file, line, col, err_type, text := matches[1], matches[2], matches[3], matches[4], matches[5] fmt.Println("!!!!!!!!!!!!!!!!!", errinfo)
fmt.Printf("!!!!!!!!!!!!!! file=%s, line=%s, col=%s, type=%s, text=%s\n", config.Settings.Errors++
file, line, col, err_type, text) config.Settings.HP--
} }
} }
} }
@ -57,8 +92,6 @@ func LaunchProcess(proc *config.Process) {
fmt.Println("WAITING for", proc.Command) fmt.Println("WAITING for", proc.Command)
fmt.Println("SENDING READY on channel")
proc.ExecCmd.Wait() proc.ExecCmd.Wait()
fmt.Println("PROCESS", proc.Command, "EXITED") fmt.Println("PROCESS", proc.Command, "EXITED")
} }
@ -89,7 +122,16 @@ func RunBuild() {
fmt.Println("PROCESS:", name) fmt.Println("PROCESS:", name)
LaunchProcess(&proc) 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) time.Sleep(1000 * time.Millisecond)

Loading…
Cancel
Save