Skip to content

Commit

Permalink
Merge pull request #132 from knoxfighter/0.17-fixes
Browse files Browse the repository at this point in the history
0.17-fixes
  • Loading branch information
mroote authored Feb 27, 2019
2 parents dd1f187 + 71a5ca6 commit 425e4ad
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/factorio_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func (h *SaveHeader) ReadFrom(r io.Reader) (err error) {

atLeast016 := !h.FactorioVersion.Less(Version{0, 16, 0, 0})

if h.FactorioVersion.Greater(Version{0, 17, 0, 0}) {
//FIXME correct naming
_, err = r.Read(scratch[:1])
if err != nil {
return fmt.Errorf("read first random 0.17 byte: %v", err)
}
}

h.Campaign, err = readString(r, Version(h.FactorioVersion), false)
if err != nil {
return fmt.Errorf("read Campaign: %v", err)
Expand Down
72 changes: 58 additions & 14 deletions src/factorio_save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,50 @@ import (
"testing"
)

func Test0_17(t *testing.T) {
file, err := OpenArchiveFile("factorio_save_testfiles/test_0_17.zip", "level.dat")
if err != nil {
t.Fatalf("Error opening level.dat: %s", err)
}
defer file.Close()

var header SaveHeader
err = header.ReadFrom(file)
if err != nil {
t.Fatalf("Error reading header: %s", err)
}

testHeader := SaveHeader{
FactorioVersion: Version{0,17,1,1},
Campaign: "transport-belt-madness",
Name: "level-01",
BaseMod: "base",
Difficulty: 0,
Finished: false,
PlayerWon: false,
NextLevel: "",
CanContinue: false,
FinishedButContinuing: false,
SavingReplay: true,
AllowNonAdminDebugOptions: true,
LoadedFrom: Version{0,17,1},
LoadedFromBuild: 43001,
AllowedCommands: 1,
Mods: []Mod {
{
Version: Version{0,2,0},
Name: "Warehousing",
},
{
Version: Version{0,17,1},
Name: "base",
},
},
}

header.Equals(testHeader, t)
}

func Test0_16(t *testing.T) {
file, err := OpenArchiveFile("factorio_save_testfiles/test_0_16.zip", "level.dat")
if err != nil {
Expand All @@ -19,16 +63,16 @@ func Test0_16(t *testing.T) {

testHeader := SaveHeader{
FactorioVersion: Version{0,16,51,0},
Campaign: "",
Name: "freeplay",
Campaign: "transport-belt-madness",
Name: "level-01",
BaseMod: "base",
Difficulty: 1,
Difficulty: 0,
Finished: false,
PlayerWon: false,
NextLevel: "",
CanContinue: false,
FinishedButContinuing: false,
SavingReplay: false,
SavingReplay: true,
AllowNonAdminDebugOptions: true,
LoadedFrom: Version{0,16,51},
LoadedFromBuild: 36654,
Expand Down Expand Up @@ -63,16 +107,16 @@ func Test0_15(t *testing.T) {

testHeader := SaveHeader{
FactorioVersion: Version{0,15,40,0},
Campaign: "",
Name: "freeplay",
Campaign: "transport-belt-madness",
Name: "level-01",
BaseMod: "base",
Difficulty: 1,
Difficulty: 0,
Finished: false,
PlayerWon: false,
NextLevel: "",
CanContinue: false,
FinishedButContinuing: false,
SavingReplay: false,
SavingReplay: true,
LoadedFrom: Version{0,15,40},
LoadedFromBuild: 30950,
AllowedCommands: 1,
Expand Down Expand Up @@ -106,16 +150,16 @@ func Test0_14(t *testing.T) {

testHeader := SaveHeader{
FactorioVersion: Version{0,14,23,0},
Campaign: "",
Name: "freeplay",
Campaign: "transport-belt-madness",
Name: "level-01",
BaseMod: "base",
Difficulty: 1,
Finished: false,
PlayerWon: false,
NextLevel: "",
CanContinue: false,
FinishedButContinuing: false,
SavingReplay: false,
SavingReplay: true,
LoadedFrom: Version{0,14,23},
LoadedFromBuild: 25374,
AllowedCommands: 1,
Expand Down Expand Up @@ -149,16 +193,16 @@ func Test0_13(t *testing.T) {

testHeader := SaveHeader{
FactorioVersion: Version{0,13,20,0},
Campaign: "",
Name: "freeplay",
Campaign: "transport-belt-madness",
Name: "level-01",
BaseMod: "base",
Difficulty: 1,
Finished: false,
PlayerWon: false,
NextLevel: "",
CanContinue: false,
FinishedButContinuing: false,
SavingReplay: false,
SavingReplay: true,
LoadedFrom: Version{0,13,20},
LoadedFromBuild: 24011,
AllowedCommands: 1,
Expand Down
Binary file modified src/factorio_save_testfiles/test_0_13.zip
Binary file not shown.
Binary file modified src/factorio_save_testfiles/test_0_14.zip
Binary file not shown.
Binary file modified src/factorio_save_testfiles/test_0_15.zip
Binary file not shown.
Binary file modified src/factorio_save_testfiles/test_0_16.zip
Binary file not shown.
Binary file added src/factorio_save_testfiles/test_0_17.zip
Binary file not shown.

0 comments on commit 425e4ad

Please sign in to comment.