Extract scanning ASCII files into a util package
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"ur.gs/chaos-gate/internal/util/asciiscan"
|
||||
)
|
||||
|
||||
type ActionPointEnum int
|
||||
type SettingEnum int
|
||||
type TransitionFrameEnum int
|
||||
@@ -205,10 +209,11 @@ type Generic struct {
|
||||
|
||||
// TODO: consume these values from the file
|
||||
func LoadGeneric(filename string) (*Generic, error) {
|
||||
scanLines, err := fileToScanner(filename)
|
||||
s, err := asciiscan.New(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
out := &Generic{
|
||||
ActionPoints: make(map[ActionPointEnum]int),
|
||||
@@ -224,7 +229,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
|
||||
// Various action point values, first to last
|
||||
for ap := ActionPointEnum(0); ap < APMax; ap++ {
|
||||
val, err := consumeInt(scanLines)
|
||||
val, err := s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -234,7 +239,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
|
||||
// Other miscellaneous data fields, first to last
|
||||
for setting := SettingEnum(0); setting < SettingMax; setting++ {
|
||||
val, err := consumeInt(scanLines)
|
||||
val, err := s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -244,7 +249,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
|
||||
// Vehicle walk transition frames. Whatever they are.
|
||||
for tf := TransitionFrameEnum(0); tf < TFMax; tf++ {
|
||||
val, err := consumeCompassPoints(scanLines)
|
||||
val, err := consumeCompassPoints(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -253,7 +258,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
}
|
||||
|
||||
for st := SquadTypeEnum(0); st < SquadMax; st++ {
|
||||
val, err := consumeInt(scanLines)
|
||||
val, err := s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -262,7 +267,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
}
|
||||
|
||||
for vt := VehicleTypeEnum(0); vt < VehicleMax; vt++ {
|
||||
val, err := consumeInt(scanLines)
|
||||
val, err := s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -271,7 +276,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
}
|
||||
|
||||
for op := OptionEnum(0); op < OptionMax; op++ {
|
||||
val, err := consumeInt(scanLines)
|
||||
val, err := s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -280,7 +285,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
}
|
||||
|
||||
for i := 0; i < NumCampaignScenarios; i++ {
|
||||
val, err := consumeString(scanLines)
|
||||
val, err := s.ConsumeString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -289,7 +294,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
}
|
||||
|
||||
for i := 0; i < NumCampaignScenarios; i++ {
|
||||
val, err := consumeString(scanLines)
|
||||
val, err := s.ConsumeString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -298,13 +303,13 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
out.CampaignEndMissionWavs = append(out.CampaignEndMissionWavs, val)
|
||||
}
|
||||
|
||||
out.AICoherentForce, err = consumeInt(scanLines)
|
||||
out.AICoherentForce, err = s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for sp := SpellEnum(0); sp < SpellMax; sp++ {
|
||||
val, err := consumeInt(scanLines)
|
||||
val, err := s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -313,7 +318,7 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
}
|
||||
|
||||
for ai := AIPriorityEnum(0); ai < AIPriorityMax; ai++ {
|
||||
val, err := consumeInt(scanLines)
|
||||
val, err := s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -321,13 +326,13 @@ func LoadGeneric(filename string) (*Generic, error) {
|
||||
out.AIPriority[ai] = val
|
||||
}
|
||||
|
||||
out.AICommandInfiniteLoopCounterWatermark, err = consumeInt(scanLines)
|
||||
out.AICommandInfiniteLoopCounterWatermark, err = s.ConsumeInt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for rg := RngRangeEnum(0); rg < RngRangeMax; rg++ {
|
||||
val, err := consumeRange(scanLines)
|
||||
val, err := consumeRange(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user