commit 4d0d7a2c9b92677084d47824650e0419509f4ebd from: Witcher01 date: Tue Jun 8 16:42:02 2021 UTC initial commit commit - /dev/null commit + 4d0d7a2c9b92677084d47824650e0419509f4ebd blob - /dev/null blob + 60deaacd27faa69db151ad1c1bd76584ee34c9f5 (mode 644) --- /dev/null +++ args.go @@ -0,0 +1,30 @@ +package main + +import ( + "os" + + "github.com/mkideal/cli" + log "github.com/sirupsen/logrus" +) + +type argT struct { + cli.Helper + File string `cli:"*f,file" usage:"livesplit split file for mirrors edge to analyze"` +} + +var ParsedArgs *argT = new(argT) + +func parseArgs(args []string) { + // parse arguments + ret := cli.Run(ParsedArgs, func(ctx *cli.Context) error { + return nil + }) + + if ret != 0 { + log.Fatal("Parsing commandline arguments failed, aborting") + } + + if ParsedArgs.Helper.Help { + os.Exit(0) + } +} blob - /dev/null blob + ecc8c9870c8a9585fcd0d7b49b8e1554f70ea5fa (mode 644) --- /dev/null +++ go.mod @@ -0,0 +1,8 @@ +module github.com/Witcher01/medge_best + +go 1.16 + +require ( + github.com/mkideal/cli v0.2.5 + github.com/sirupsen/logrus v1.8.1 +) blob - /dev/null blob + 65d50af7c1ea38f7b7b83f75f16285b7b30705a9 (mode 644) --- /dev/null +++ go.sum @@ -0,0 +1,47 @@ +github.com/comail/colog v0.0.0-20160416085026-fba8e7b1f46c/go.mod h1:1WwgAwMKQLYG5I2FBhpVx94YTOAuB2W59IZ7REjSE6Y= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= +github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mkideal/cli v0.2.5 h1:Lc2v2bijpYbl4TUAbstLx9X7o90agDWk7Z3I8AZTJ1Y= +github.com/mkideal/cli v0.2.5/go.mod h1:XaQYNUpBxFxm15Gs9HILpG6bRuTKMWvuW3bSc+M8p0g= +github.com/mkideal/expr v0.1.0 h1:fzborV9TeSUmLm0aEQWTWcexDURFFo4v5gHSc818Kl8= +github.com/mkideal/expr v0.1.0/go.mod h1:vL1DsSb87ZtU6IEjOtUfxw98z0FQbzS8xlGtnPkKdzg= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= +golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= blob - /dev/null blob + b9dcb07d607f7c5674213270350365da94fd2f3d (mode 644) --- /dev/null +++ main.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + "os" + "strings" + "time" +) + +// whatever you do, don't read this code + +func main() { + splits, err := UnmarshalFile(os.Args[1]) + if err != nil { + panic(err) + } + + splitTimes := make([]time.Duration, 11) + for i, segment := range splits.Segments { + for _, times := range segment.SplitTimes { + if times.Key == "Personal Best" { + dur, err := ParseDuration(times.GameTime) + if err != nil { + panic("lol") + } + splitTimes[i] = dur + } + } + } + + segmentTimes := make([]time.Duration, 11) + copy(segmentTimes, splitTimes) + for i := len(segmentTimes) - 1; i > 0; i-- { + segmentTimes[i] = segmentTimes[i] - segmentTimes[i-1] + } + + // merge 2 + 3 + splitTimes = append(splitTimes[:3], splitTimes[4:]...) + segmentTimes[2] = segmentTimes[2] + segmentTimes[3] + segmentTimes = append(segmentTimes[:3], segmentTimes[4:]...) + + fmt.Println("Split Times:") + for _, v := range splitTimes { + seconds := int(v.Seconds()) % 60 + ms := v.Milliseconds() % 1000 + fmt.Printf("%.f:%02d.%d\n", v.Minutes(), seconds, ms) + } + + fmt.Println("Segment Times:") + for _, v := range segmentTimes { + seconds := int(v.Seconds()) % 60 + ms := v.Milliseconds() % 1000 + fmt.Printf("%.f:%02d.%d\n", v.Minutes(), seconds, ms) + } +} + +func ParseDuration(str string) (time.Duration, error) { + toParse := strings.Replace(str, ":", "h", 1) + toParse = strings.Replace(toParse, ":", "m", 1) + toParse = strings.Replace(toParse, ".", "s", 1) + out := []rune(toParse) + out[12] = 'm' + out[13] = 's' + + t, err := time.ParseDuration(string(out[:14])) + if err != nil { + return t, err + } + + return t, nil +} blob - /dev/null blob + d6ca20a61b801a52ad099c50fe6099705307a52c (mode 644) --- /dev/null +++ xml.go @@ -0,0 +1,45 @@ +package main + +import ( + "encoding/xml" + "io/ioutil" + "os" +) + +type SplitSegments struct { + GameName string `xml:"GameName"` + CategoryName string `xml:"CategoryName"` + Segments []Segment `xml:"Segments>Segment"` +} + +type Segment struct { + Name string `xml:"Name"` + SplitTimes []SplitTime `xml:"SplitTimes>SplitTime"` +} + +type SplitTime struct { + Key string `xml:"name,attr"` + RealTime string `xml:"RealTime"` + GameTime string `xml:"GameTime"` +} + +func UnmarshalFile(path string) (SplitSegments, error) { + var splits SplitSegments + + f, err := os.Open(path) + if err != nil { + return splits, err + } + + bytes, err := ioutil.ReadAll(f) + if err != nil { + return splits, err + } + + err = xml.Unmarshal(bytes, &splits) + if err != nil { + return splits, err + } + + return splits, nil +}