Skip to content

Commit

Permalink
Merge branch 'main' into saved-object
Browse files Browse the repository at this point in the history
  • Loading branch information
Chr1Z93 committed Nov 4, 2024
2 parents f567a5b + 2489e3b commit b37d510
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go-ossf-slsa3-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
id-token: write # To sign.
contents: write # To upload release assets.
actions: read # To read workflow path.
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v2.0.0
with:
go-version: 1.18
config-file: ".slsa-goreleaser.yml"
Expand All @@ -41,7 +41,7 @@ jobs:
id-token: write # To sign.
contents: write # To upload release assets.
actions: read # To read workflow path.
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.10.0
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v2.0.0
with:
go-version: 1.18
config-file: ".slsa-goreleaser-linux.yml"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TTSModManager.exe
bash.exe.stackdump
oryxBuildBinary
30 changes: 30 additions & 0 deletions file/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ func ForceParseIntoStrArray(m *types.J, k string, dest *[]string) error {
return nil
}

func TryParseIntoStrMap(m *types.J, k string, dest *map[string]string) {
_ = ForceParseIntoStrMap(m, k, dest)
}

func ForceParseIntoStrMap(m *types.J, k string, dest *map[string]string) error {
raw, ok := (*m)[k]
if !ok {
return fmt.Errorf("key %s not found", k)
}
if rawmapstrings, ok := raw.(map[string]string); ok {
*dest = rawmapstrings
delete((*m), k)
return nil
}
if rawmap, ok := raw.(map[string]any); ok {
massaged := map[string]string{}
for k, v := range rawmap {
vstr, ok := v.(string)
if !ok {
return fmt.Errorf("m[%s] of type %T, not string", k, v)
}
massaged[k] = vstr
}
*dest = massaged
delete((*m), k)
return nil
}
return fmt.Errorf("key %s was not type map[string]string, was %T", k, raw)
}

// TryParseIntoInt will not throw error
func TryParseIntoInt(m *types.J, k string, dest *int64) {
_ = ForceParseIntoInt(m, k, dest)
Expand Down
141 changes: 141 additions & 0 deletions mod/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,147 @@ func TestGenerate(t *testing.T) {
"DecalPallet": nil,
},
},
{
name: "Object State recursive",
inputRoot: map[string]interface{}{
"SaveName": "cool mod",
"ObjectStates_order": []interface{}{"parent"},
},
inputLuaSrc: map[string]string{
"parent/eda22b/childstate2.ttslua": "var foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\n",
},
inputOjbs: map[string]types.J{
"parent.json": map[string]interface{}{
"GUID": "parent",
"States_path": map[string]interface{}{
"2": "eda22b",
},
"ContainedObjects_path": "parent",
},
"parent/eda22b.json": map[string]interface{}{
"GUID": "eda22b",
"Autoraise": true,
"ContainedObjects_path": "eda22b",
"ContainedObjects_order": []string{"childstate2"},
},
"parent/eda22b/childstate2.json": map[string]interface{}{
"Description": "child of state 2",
"GUID": "childstate2",
"LuaScript_path": "parent/eda22b/childstate2.ttslua",
},
},
want: map[string]interface{}{
"SaveName": "cool mod",
"ObjectStates": []any{
map[string]any{
"GUID": "parent",
"States": map[string]interface{}{
"2": map[string]interface{}{
"Autoraise": true,
"GUID": "eda22b",
"ContainedObjects": []any{
map[string]any{
"Description": "child of state 2",
"GUID": "childstate2",
"LuaScript": "var foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\nvar foo = 42\n",
},
},
},
},
},
},
"CameraStates": nil,
"ComponentTags": nil,
"MusicPlayer": nil,
"Sky": "",
"TabStates": nil,
"Note": "",
"Table": "",
"LuaScript": "",
"LuaScriptState": "",
"SnapPoints": nil,
"XmlUI": "",
"Turns": nil,
"VersionNumber": "",
"GameMode": "",
"GameType": "",
"Hands": nil,
"Grid": nil,
"Lighting": nil,
"GameComplexity": "",
"Decals": nil,
"CustomUIAssets": nil,
"DecalPallet": nil,
},
},
{
name: "Object State and contained object generation",
inputRoot: map[string]interface{}{
"SaveName": "cool mod",
"ObjectStates_order": []interface{}{"parent"},
},
inputLuaSrc: map[string]string{},
inputOjbs: map[string]types.J{
"parent.json": map[string]interface{}{
"GUID": "parent",
"States_path": map[string]interface{}{
"2": "state2",
},
"ContainedObjects_path": "parent",
"ContainedObjects_order": []string{"co123"},
},
"parent/state2.json": map[string]interface{}{
"GUID": "state2",
"Autoraise": true,
},
"parent/co123.json": map[string]interface{}{
"Description": "contained object",
"GUID": "co123",
},
},
want: map[string]interface{}{
"SaveName": "cool mod",
"ObjectStates": []any{
map[string]any{
"GUID": "parent",
"States": map[string]interface{}{
"2": map[string]interface{}{
"Autoraise": true,
"GUID": "state2",
},
},
"ContainedObjects": []any{
map[string]any{
"GUID": "co123",
"Description": "contained object",
},
},
},
},
"CameraStates": nil,
"ComponentTags": nil,
"MusicPlayer": nil,
"Sky": "",
"TabStates": nil,
"Note": "",
"Table": "",
"LuaScript": "",
"LuaScriptState": "",
"SnapPoints": nil,
"XmlUI": "",
"Turns": nil,
"VersionNumber": "",
"GameMode": "",
"GameType": "",
"Hands": nil,
"Grid": nil,
"Lighting": nil,
"GameComplexity": "",
"Decals": nil,
"CustomUIAssets": nil,
"DecalPallet": nil,
},
},
} {
t.Run(tc.name, func(t *testing.T) {
rootff := &tests.FakeFiles{
Expand Down
Loading

0 comments on commit b37d510

Please sign in to comment.