Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
feat: Add dungeon state to Root state
Browse files Browse the repository at this point in the history
  • Loading branch information
upa-r-upa committed Mar 11, 2024
1 parent 6db8990 commit d613778
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions backend/app/Savor22b.Tests/Action/CancelFoodActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class CancelFoodActionTests : ActionTests

RootState beforeRootState = new RootState(
beforeInventoryState,
new DungeonState(),
new VillageState(new HouseState(1, 1, 1, beforeKitchenState))
);

Expand Down
1 change: 1 addition & 0 deletions backend/app/Savor22b.Tests/Action/CreateFoodActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ ImmutableList<int> FoodIDList

RootState rootState = new RootState(
inventoryState,
new DungeonState(),
new VillageState(new HouseState(1, 1, 1, resultKitchenState))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void Execute_Success_Normal()
IAccountStateDelta beforeState = new DummyState();
RootState beforeRootState = new RootState(
new InventoryState(),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
Expand Down Expand Up @@ -70,6 +71,7 @@ public void Execute_Success_AfterRemoveWeed()
IAccountStateDelta beforeState = new DummyState();
RootState beforeRootState = new RootState(
new InventoryState(),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void Execute_Success_NormalCase(int spaceNumber)
ImmutableList<KitchenEquipmentState>.Empty.Add(new KitchenEquipmentState(Guid.NewGuid(), 1, 1)),
ImmutableList<ItemState>.Empty
),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
Expand Down Expand Up @@ -99,6 +100,7 @@ public void Execute_Failure_NotHaveKitchenEquipment()
ImmutableList<KitchenEquipmentState>.Empty,
ImmutableList<ItemState>.Empty
),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
Expand Down Expand Up @@ -138,6 +140,7 @@ public void Execute_Failure_NotPlacedHouse()
ImmutableList<KitchenEquipmentState>.Empty,
ImmutableList<ItemState>.Empty
),
new DungeonState(),
null
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private IAccountStateDelta createStateForRelocationHouse()
prevGlobalUserHouseState.UserHouse.Add("1,0,0", SignerAddress());

VillageState villageState = new VillageState(new HouseState(1, 0, 0, new KitchenState()));
RootState prevRootState = new RootState(new InventoryState(), villageState);
RootState prevRootState = new RootState(new InventoryState(), new DungeonState(), villageState);

state = state.MintAsset(
SignerAddress(),
Expand Down Expand Up @@ -141,6 +141,7 @@ private IAccountStateDelta createStateForInProgressReplaceHouse()
VillageState villageState = new VillageState(new HouseState(1, 0, 0, new KitchenState()));
RootState prevRootState = new RootState(
new InventoryState(),
new DungeonState(),
villageState,
new RelocationState(1, 90, 1, 0, 0)
);
Expand Down
3 changes: 2 additions & 1 deletion backend/app/Savor22b.Tests/Action/PlantingSeedActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public void Execute_InvalidVillageState()

InventoryState inventoryState = getInventoryState();
RootState beforeRootState = new RootState(
inventoryState
inventoryState,
new DungeonState()
);

beforeState = beforeState.SetState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void Execute_Success_Normal()
IAccountStateDelta beforeState = new DummyState();
RootState beforeRootState = new RootState(
new InventoryState(),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
Expand Down
1 change: 1 addition & 0 deletions backend/app/Savor22b.Tests/Action/RemoveWeedActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public RootState createRootStatePreset()
{
RootState beforeRootState = new RootState(
new InventoryState(),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
Expand Down
40 changes: 20 additions & 20 deletions backend/app/Savor22b/States/RootState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Savor22b.States;
public class RootState : State
{
public InventoryState InventoryState { get; private set; }
public DungeonState DungeonState { get; private set; }

public RelocationState? RelocationState { get; private set; }

Expand All @@ -13,31 +14,15 @@ public class RootState : State
public RootState()
{
InventoryState = new InventoryState();
DungeonState = new DungeonState();
VillageState = null;
RelocationState = null;
}

public RootState(InventoryState inventoryState)
public RootState(InventoryState inventoryState, DungeonState dungeonState, VillageState? villageState = null, RelocationState? relocationState = null)
{
InventoryState = inventoryState;
VillageState = null;
RelocationState = null;
}

public RootState(InventoryState inventoryState, VillageState villageState)
{
InventoryState = inventoryState;
VillageState = villageState;
RelocationState = null;
}

public RootState(
InventoryState inventoryState,
VillageState villageState,
RelocationState relocationState
)
{
InventoryState = inventoryState;
InventoryState = inventoryState ?? new InventoryState();
DungeonState = dungeonState ?? new DungeonState();
VillageState = villageState;
RelocationState = relocationState;
}
Expand All @@ -55,6 +40,17 @@ public RootState(Bencodex.Types.Dictionary encoded)
InventoryState = new InventoryState();
}

if (encoded.ContainsKey((Text)nameof(DungeonState)))
{
DungeonState = new DungeonState(
(Bencodex.Types.Dictionary)encoded[nameof(DungeonState)]
);
}
else
{
DungeonState = new DungeonState();
}

if (encoded.ContainsKey((Text)nameof(VillageState)))
{
VillageState = new VillageState(
Expand Down Expand Up @@ -101,6 +97,10 @@ public IValue Serialize()
(Text)nameof(InventoryState),
InventoryState.Serialize()
),
new KeyValuePair<IKey, IValue>(
(Text)nameof(DungeonState),
DungeonState.Serialize()
),
};

if (RelocationState is not null)
Expand Down

0 comments on commit d613778

Please sign in to comment.