Skip to content

Commit

Permalink
Use Seed description configured in xml
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Nov 9, 2023
1 parent c4dc602 commit e381415
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/games/stendhal/server/entity/item/Seed.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.Map;

import games.stendhal.common.grammar.Grammar;
import games.stendhal.server.core.engine.StendhalRPZone;
import games.stendhal.server.core.events.TurnNotifier;
import games.stendhal.server.entity.Entity;
Expand Down Expand Up @@ -105,14 +106,14 @@ public boolean onUsed(final RPEntity user) {

@Override
public String describe() {
final String flowerName = getItemData();

if (flowerName != null) {
return "You see a " + flowerName + " " + this.getName()
+ ". It can be planted in fertile ground where it will thrive.";
} else {
return "You see a seed. It can be planted in fertile ground where it will thrive.";
String seed_desc = getDescription();
final String flower_name = getItemData();
if (flower_name != null) {
final String seed_type = getName();
final String seed_name = flower_name + " " + seed_type;
seed_desc = seed_desc.replaceFirst(Grammar.a_noun(seed_type), Grammar.a_noun(seed_name));
}
return seed_desc;
}

/**
Expand Down
49 changes: 48 additions & 1 deletion tests/games/stendhal/server/entity/item/SeedTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2010 - Stendhal *
* (C) Copyright 2003-2023 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -12,13 +12,17 @@
***************************************************************************/
package games.stendhal.server.entity.item;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;

import org.junit.BeforeClass;
import org.junit.Test;

import games.stendhal.common.grammar.Grammar;
import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.core.engine.StendhalRPZone;
import games.stendhal.server.entity.Entity;
Expand Down Expand Up @@ -164,4 +168,47 @@ public void testExecuteDaisiesSeed() {
assertFalse(player.getZone().getEntitiesAt(1, 0).contains(flg));
assertTrue("player has daisies", player.isEquipped("daisies"));
}

@Test
public void testSeedInfo() {
// seeds
final Seed base_seed = (Seed) SingletonRepository.getEntityManager().getItem("seed");
assertNotNull(base_seed);
assertEquals("You see a seed. It can be planted in fertile ground where it will thrive.",
base_seed.describe());
assertEquals("seed", base_seed.get("subclass"));

for (final String flower_name: Arrays.asList("daisies", "lilia", "pansy")) {
final Seed seed = new Seed(base_seed);
seed.setItemData(flower_name);
final String seed_name = flower_name + " seed";
assertEquals("You see " + Grammar.a_noun(seed_name)
+ ". It can be planted in fertile ground where it will thrive.", seed.describe());
if ("daisies".equals(flower_name)) {
assertEquals("seed", seed.get("subclass"));
} else {
assertEquals("seed_" + flower_name, seed.get("subclass"));
}
}

// bulbs
final Seed base_bulb = (Seed) SingletonRepository.getEntityManager().getItem("bulb");
assertNotNull(base_bulb);
assertEquals("You see a bulb. It can be planted in fertile ground where it will thrive.",
base_bulb.describe());
assertEquals("bulb", base_bulb.get("subclass"));

for (final String flower_name: Arrays.asList("zantedeschia")) {
final Seed bulb = new Seed(base_bulb);
bulb.setItemData(flower_name);
final String bulb_name = flower_name + " bulb";
assertEquals("You see " + Grammar.a_noun(bulb_name)
+ ". It can be planted in fertile ground where it will thrive.", bulb.describe());
if ("zantedeschia".equals(flower_name)) {
assertEquals("bulb", bulb.get("subclass"));
} else {
assertEquals("bulb_" + flower_name, bulb.get("subclass"));
}
}
}
}

0 comments on commit e381415

Please sign in to comment.