aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Event.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-18 02:01:12 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-18 02:01:12 +0200
commitfe2543627bcec1ea0f7a429bede20ca293458ba9 (patch)
tree42c9630d65292c90bee37444fde14fcf99cc3ffe /src/scalevalapokalypsi/Model/Event.scala
parenta98f089035dbcc94c14c9cd6246c3150bee84241 (diff)
downloadscalevalapokalypsi-fe2543627bcec1ea0f7a429bede20ca293458ba9.tar.gz
scalevalapokalypsi-fe2543627bcec1ea0f7a429bede20ca293458ba9.zip
Major change! Changed Events to have multiple first persons & changed sending action results to clients using this. This improves code and made it easy to finally make arrival/leaving messages when going from one area to another!
This commit is too big indeed, and there are probably bugs. I'm annoyed we didn't set up unit testing during the course. I should've taken my time to set up IDEA myself for that. Now the bugs will just have to be fixed in future commits.
Diffstat (limited to 'src/scalevalapokalypsi/Model/Event.scala')
-rw-r--r--src/scalevalapokalypsi/Model/Event.scala36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/scalevalapokalypsi/Model/Event.scala b/src/scalevalapokalypsi/Model/Event.scala
index cba611d..9055fd8 100644
--- a/src/scalevalapokalypsi/Model/Event.scala
+++ b/src/scalevalapokalypsi/Model/Event.scala
@@ -1,28 +1,34 @@
package scalevalapokalypsi.Model
import scalevalapokalypsi.Model.Entities.Entity
+import scala.collection.immutable.Map
/** A description of an action.
- *
- * @param target the entity that was as a target in this event
- * @param inFirstPerson textual description of the event in first person
- * @param inThirdPerson textual description of the event in third person
- */
+ *
+ * @param inFirstPersons a Map of descriptions in first person for entities
+ * given as keys
+ * @param inThirdPerson textual description of the event in third person
+ */
class Event(
- val target: Entity,
- val inFirstPerson: String,
+ val inFirstPersons: Map[Entity, String],
val inThirdPerson: String
):
+ // And why are we not just using a map with a default value?
+ // Wrapping this in an Event creates a more specific abstraction.
+ // It indicates, that instances of this class are precisely descriptions
+ // of events, and it allows changing the private implementation without
+ // touching the public interface.
+ private val values = inFirstPersons.withDefaultValue(inThirdPerson)
+
/** Gets the description of this event as seen by the given
- * entity. Note that this method does no checks whether the given entity
- * could even see the event, only what it would have looked like to them.
- *
- * @param entity the entity whose perspective to use
- * @return a textual description of the event
- */
+ * entity. Note that this method does no checks whether the given entity
+ * could even see the event, only what it would have looked like to them.
+ *
+ * @param entity the entity whose perspective to use
+ * @return a textual description of the event
+ */
def descriptionFor(entity: Entity): String =
- if entity == target then inFirstPerson
- else inThirdPerson
+ this.values.apply(entity)
end Event \ No newline at end of file