Skip to content

Commit

Permalink
Decompose states of objects
Browse files Browse the repository at this point in the history
Because object states are themselves full objects,
let them be pulled out and handled properly.
  • Loading branch information
argonui authored Nov 4, 2024
1 parent a9546b2 commit 768f869
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
68 changes: 68 additions & 0 deletions mod/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,74 @@ func TestGenerate(t *testing.T) {
"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
48 changes: 48 additions & 0 deletions mod/reverse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,54 @@ func TestReverse(t *testing.T) {
wantObjTexts: map[string]string{},
wantSrcTexts: map[string]string{},
},
{
name: "State tracking and sub objects",
input: map[string]interface{}{
"SaveName": "cool mod",
"ObjectStates": []map[string]interface{}{
{
"GUID": "parent",
"States": map[string]interface{}{
"2": map[string]interface{}{
"Autoraise": true,
"GUID": "state2",
},
},
"ContainedObjects": []any{
map[string]any{
"Description": "contained object",
"GUID": "co123",
},
},
},
},
},
wantRootConfig: map[string]interface{}{
"SaveName": "cool mod",
"ObjectStates_order": []interface{}{"parent"},
},
wantModSettings: map[string]types.J{},
wantObjs: map[string]types.J{
"parent.json": map[string]interface{}{
"GUID": "parent",
"States_path": map[string]string{
"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{}{
"GUID": "co123",
"Description": "contained object",
},
},
wantObjTexts: map[string]string{},
wantSrcTexts: map[string]string{},
},
{
name: "State tracking - checking recursion",
input: map[string]interface{}{
Expand Down

0 comments on commit 768f869

Please sign in to comment.