Skip to content

Commit

Permalink
fix handle food in second day
Browse files Browse the repository at this point in the history
  • Loading branch information
ImLeiSu committed Oct 16, 2024
1 parent d6b0b83 commit 13c3ea4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.csse3200.game.components.npc.CustomerManager;
import com.csse3200.game.components.ordersystem.OrderManager;
import com.csse3200.game.entities.configs.CustomerPersonalityConfig;
import com.csse3200.game.entities.configs.NPCConfigs;
import com.csse3200.game.entities.factories.NPCFactory;
import com.csse3200.game.files.FileLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -99,10 +102,7 @@ public void addListeners() {
ServiceLocator.getEntityService().getEvents().addListener("toggleEndDayScreen", this::toggleVisibility);
ServiceLocator.getEntityService().getEvents().addListener("customerPassed", this::handlePassedCustomer);

ServiceLocator.getDayNightService().getEvents().addListener("endOfDay", () -> {
logger.info("it is listened in end day");
ServiceLocator.getRandomComboService().deactivateUpgrade();
show();});
ServiceLocator.getDayNightService().getEvents().addListener("endOfDay", this::show);
}

/**
Expand Down Expand Up @@ -208,9 +208,9 @@ public void setupCustomerLists() {
// Customer lists
Table listTable = new Table();

Label passedLabel = new Label("Passed Customers", skin);
Label passedLabel = new Label("Served Customers", skin);
passedLabel.setFontScale(1.8f);
Label failedLabel = new Label("Failed Customers", skin);
Label failedLabel = new Label("Unserved Customers", skin);
failedLabel.setFontScale(1.8f);
listTable.add(passedLabel).pad(10).center();
listTable.add(failedLabel).pad(10).center().row();
Expand Down Expand Up @@ -266,6 +266,12 @@ public void handleGoldUpdate(int gold) {
goldLabel.setText(currentGold);
}

/**
* Handles the event when a customer has successfully completed their interaction, such as finishing an order.
* This method adds the customer's name in uppercase to the list of passed customers and logs the event.
*
* @param customerName The name of the customer who passed.
*/
public void handlePassedCustomer(String customerName) {
passedCustomerArray.add(customerName.toUpperCase());
logger.info("Customer passed: {}", customerName);
Expand Down Expand Up @@ -299,7 +305,6 @@ private void recalculateFailedCustomers() {
for (String failedName : failedCustomerArray) {
assertCustomerTexture(failedName, failedCustomerTable);
}
logger.info("Failed customers recalculated: {}", failedCustomerArray);
}

/**
Expand Down Expand Up @@ -328,19 +333,16 @@ private CustomerPersonalityConfig getCustomerConfig(String name) {
*/
private void assertCustomerTexture(String customerName, Table customerTable) {
CustomerPersonalityConfig config = getCustomerConfig(customerName);
try {
TextureAtlas atlas = ServiceLocator.getResourceService().getAsset(config.texture, TextureAtlas.class);
TextureRegion region = atlas.findRegion("default");
Image image = new Image(region);
Label label = new Label(customerName, skin);
label.setFontScale(1.5f);

customerTable.row().pad(10);
customerTable.add(image).size(70, 70);
customerTable.add(label);
} catch (Exception e) {
logger.error("Failed to load texture for customer {}", customerName, e);
}

TextureAtlas atlas = ServiceLocator.getResourceService().getAsset(config.texture, TextureAtlas.class);
TextureRegion region = atlas.findRegion("default");
Image image = new Image(region);
Label label = new Label(customerName, skin);
label.setFontScale(1.5f);

customerTable.row().pad(10);
customerTable.add(image).size(70, 70);
customerTable.add(label);
}

/**
Expand Down Expand Up @@ -390,7 +392,9 @@ public void run() {
* the current game state. It is usually called in response to a game event.
*/
public void show() {
// ServiceLocator.getRandomComboService().deactivateUpgrade();
ServiceLocator.getRandomComboService().deactivateUpgrade();
NPCFactory.reset();
CustomerManager.reset();
recalculateFailedCustomers();
setVisible(true);
getLayout().setVisible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ public static Entity getCustomerByOrder(String orderNumber) {
public static void removeCustomerByOrder(String orderNumber) {
orderToCustomerMap.remove(orderNumber);
}

/**
* Reset map
*/
public static void reset() {
orderToCustomerMap.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class EndDayDisplayTest {
DayNightService dayNightService;
LevelService levelService;
EndDayDisplay endDayDisplay;
@Mock
RandomComboService randomComboService;

/**
* Sets up the environment before each test by initializing services
Expand All @@ -90,6 +92,7 @@ void setUp() {
ServiceLocator.registerResourceService(resourceService);
ServiceLocator.registerLevelService(levelService);
ServiceLocator.registerTimeSource(gameTime);
ServiceLocator.registerRandomComboService(randomComboService);
dayNightService = new DayNightService();
ServiceLocator.registerDayNightService(dayNightService);
ServiceLocator.registerGameScreen(mainGameScreen);
Expand Down

0 comments on commit 13c3ea4

Please sign in to comment.