aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Event.scala
blob: 9055fd8ec657eb5d150446eed84b93d139b039c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package scalevalapokalypsi.Model

import scalevalapokalypsi.Model.Entities.Entity
import scala.collection.immutable.Map

/** A description of an action.
  *
  * @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 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
	  */
	def descriptionFor(entity: Entity): String =
		this.values.apply(entity)

end Event