Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SHOW_ON_COUNTER during the cut action #86

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion culinaryFrontend/src/components/screens/MainActionsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,34 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr
blenderMap[arg]()
}

let cuttedMap: { [key: string]: string } = {
"FRESH_TOMATO": "CUT_TOMATO",
"FRESH_CUCUMBER": "CUT_CUCUMBER",
"FRESH_CARROT": "CUT_CARROT",
}

function cutOnCounter(arg: string | null){
console.log("cutOnCounter", arg)
if (!arg){
return
}
console.log("counter: ", counterProducts)
if (cuttedMap.hasOwnProperty(arg)) {
let cuttedArg = cuttedMap[arg];
console.log("counter: ", counterProducts)
console.log("filter: ", counterProducts.filter(item => JsItemType[item] !== arg))
counterProductsSetter((prevState) => {
const index = prevState.findIndex(item => JsItemType[item] === arg);
if (index > -1) {
const newState = [...prevState];
newState.splice(index, 1, JsItemType[cuttedArg as keyof typeof JsItemType]);
return newState;
}
return prevState;
});
}
}

function removeFromCounter(arg: string | null) {
console.log("removeFromCounter", arg)
if (!arg){
Expand Down Expand Up @@ -478,7 +505,7 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr
"BLEND": blend,
"ADD_TO_BLENDER": addToBlender,
"REMOVE_FROM_COUNTER": removeFromCounter,
"CUT_ON_COUNTER": removeFromCounter
"CUT_ON_COUNTER": cutOnCounter
};

function refill(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
5 changes: 1 addition & 4 deletions culinaryServer/culinaryServerAddSpices/test/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ class Test {
val expectedActions = buildList {
addAll(List(NUMBER_OF_TOMATOES) { Action(ActionType.SHOW_ON_COUNTER, ItemType.FRESH_TOMATO) })
repeat(NUMBER_OF_TOMATOES) {
addAll(listOf(
Action(ActionType.CUT_ON_COUNTER, ItemType.FRESH_TOMATO),
Action(ActionType.SHOW_ON_COUNTER, ItemType.CUT_TOMATO)
))
add(Action(ActionType.CUT_ON_COUNTER, ItemType.FRESH_TOMATO))
}
repeat(NUMBER_OF_TOMATOES) {
addAll(listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
3 changes: 1 addition & 2 deletions culinaryServer/culinaryServerCookSalad/test/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Test {
val expectedActions = buildList {
addAll(List(vegetables.size) { ActionType.SHOW_ON_COUNTER })
repeat(vegetables.size) {
addAll(listOf(ActionType.CUT_ON_COUNTER, ActionType.SHOW_ON_COUNTER))
add(ActionType.CUT_ON_COUNTER)
}
}
assert(expectedActions == actions.map{ it.type }) { "The ${cutMethod.name} method should take vegetables and cut them: take each of them from the fridge, and then cut" }
Expand Down Expand Up @@ -174,7 +174,6 @@ class Test {
repeat(NUMBER_OF_TOMATOES) {
addAll(listOf(
Action(ActionType.CUT_ON_COUNTER, ItemType.FRESH_TOMATO),
Action(ActionType.SHOW_ON_COUNTER, ItemType.CUT_TOMATO)
))
}
repeat(NUMBER_OF_TOMATOES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
9 changes: 2 additions & 7 deletions culinaryServer/culinaryServerCookSmoothie/test/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import org.jetbrains.academy.test.system.core.invokeWithoutArgs
import org.jetbrains.kotlin.course.culinary.converters.buildAction
import org.jetbrains.kotlin.course.culinary.game.actions
import org.jetbrains.kotlin.course.culinary.game.clearActions
import org.jetbrains.kotlin.course.culinary.game.fridge
import org.jetbrains.kotlin.course.culinary.game.kitchen
import org.jetbrains.kotlin.course.culinary.game.recipes.NUMBER_OF_TOMATOES
import org.jetbrains.kotlin.course.culinary.game.recipes.NUM_VEGETABLES_FOR_SALAD
import org.jetbrains.kotlin.course.culinary.implementation.storage.FridgeImpl
Expand Down Expand Up @@ -115,7 +113,7 @@ class Test {
val expectedActions = buildList {
addAll(List(vegetables.size) { ActionType.SHOW_ON_COUNTER })
repeat(vegetables.size) {
addAll(listOf(ActionType.CUT_ON_COUNTER, ActionType.SHOW_ON_COUNTER))
add(ActionType.CUT_ON_COUNTER)
}
}
assert(expectedActions == actions.map{ it.type }) { "The ${cutMethod.name} method should take vegetables and cut them: take each of them from the fridge, and then cut" }
Expand Down Expand Up @@ -213,10 +211,7 @@ class Test {
val expectedActions = buildList {
addAll(List(NUMBER_OF_TOMATOES) { Action(ActionType.SHOW_ON_COUNTER, ItemType.FRESH_TOMATO) })
repeat(NUMBER_OF_TOMATOES) {
addAll(listOf(
Action(ActionType.CUT_ON_COUNTER, ItemType.FRESH_TOMATO),
Action(ActionType.SHOW_ON_COUNTER, ItemType.CUT_TOMATO)
))
add(Action(ActionType.CUT_ON_COUNTER, ItemType.FRESH_TOMATO))
}
repeat(NUMBER_OF_TOMATOES) {
addAll(listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data object KitchenImpl : Kitchen {
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
return cut
}

Expand Down
5 changes: 1 addition & 4 deletions culinaryServer/culinaryServerTomatoSoup/test/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ class Test {
val expectedActions = buildList {
addAll(List(NUMBER_OF_TOMATOES) { Action(ActionType.SHOW_ON_COUNTER, ItemType.FRESH_TOMATO) })
repeat(NUMBER_OF_TOMATOES) {
addAll(listOf(
Action(ActionType.CUT_ON_COUNTER, ItemType.FRESH_TOMATO),
Action(ActionType.SHOW_ON_COUNTER, ItemType.CUT_TOMATO)
))
add(Action(ActionType.CUT_ON_COUNTER, ItemType.FRESH_TOMATO))
}
repeat(NUMBER_OF_TOMATOES) {
addAll(listOf(
Expand Down
Loading