示例#1
0
文件: parser.go 项目: glacials/tugnut
func (p *parser) parseBasicInfo(ctx context.Context, input *RunTag, output *run.Run) {
	output.Game = run.Game{
		Names: []string{input.Game},
		SRLInfo: run.SRLGameInfo{
			ID: "",
		},
		SRDCInfo: run.SRDCGameInfo{
			ID: "",
		},
	}

	output.Category = run.Category{
		Names: []string{input.Category},
		SRLInfo: run.SRLCategoryInfo{
			ID: "",
		},
		SRDCInfo: run.SRDCCategoryInfo{
			ID: "",
		},
	}

	output.Attempts = input.Attempts
}
示例#2
0
文件: parser.go 项目: glacials/tugnut
func (p *parser) parseSegments(ctx context.Context, input *RunTag, output *run.Run) error {
	output.Segments = make([]run.Segment, len(input.Segments.Segments))
	for i, s := range input.Segments.Segments {

		// The current segment's start time is equal to the previous segment's end time
		var start, end run.Duration
		if i == 0 {
			start = run.Duration{
				RealTime: time.Duration(0),
				GameTime: time.Duration(0),
			}
		} else {
			start = output.Segments[i-1].End
		}

		realEnd, err := parseTime(
			s.SplitTimes.SplitTimes[0].RealTime,
		)
		if err != nil {
			return fmt.Errorf("can't parse segment real time: %s", err)
		}
		gameEnd, err := parseTime(
			s.SplitTimes.SplitTimes[0].GameTime,
		)
		if err != nil {
			return fmt.Errorf("can't parse segment game time: %s", err)
		}

		end = run.Duration{
			RealTime: realEnd,
			GameTime: gameEnd,
		}

		var realDuration time.Duration
		if end.RealTime == 0 {
			realDuration = 0
		} else {
			realDuration = end.RealTime - start.RealTime
		}

		var gameDuration time.Duration
		if end.GameTime == 0 {
			gameDuration = 0
		} else {
			gameDuration = end.GameTime - start.GameTime
		}

		duration := run.Duration{
			RealTime: realDuration,
			GameTime: gameDuration,
		}

		output.Segments[i] = run.Segment{
			Name:     s.Name,
			Start:    start,
			End:      end,
			Duration: duration,
		}
	}
	return nil
}