From 26d7dadded04cfb278765ed0b4479c471f9eb412 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 13 Jun 2021 10:37:43 -0400 Subject: [PATCH] feat(xanthous): Store language on creatures Add a new "language" field to the CreatureType raw type, which references the *name* of the language that creature speaks (this is so that different creatures can speak the same language without having to duplicate the language definition in the raws). At some point this should change to not hardcode the sets of languages and instead define them in data files like we do for creatures, but this is fine as a start. Change-Id: I6708570175e23472cb37e0061a329e54e8eac9c0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3205 Reviewed-by: grfn Tested-by: BuildkiteCI --- .../src/Xanthous/Entities/RawTypes.hs | 29 ++++++++++++++++++- .../src/Xanthous/Entities/Raws/gormlak.yaml | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs b/users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs index d280136ae..a650a4f78 100644 --- a/users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs +++ b/users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs @@ -10,6 +10,9 @@ module Xanthous.Entities.RawTypes -- * Creatures , CreatureType(..) , hostile + -- ** Language + , LanguageName(..) + , getLanguage -- * Items , ItemType(..) @@ -30,6 +33,7 @@ module Xanthous.Entities.RawTypes , HasEdible(..) , HasFriendly(..) , HasHitpointsHealed(..) + , HasLanguage(..) , HasLongDescription(..) , HasMaxHitpoints(..) , HasName(..) @@ -46,8 +50,28 @@ import Xanthous.Messages (Message(..)) import Xanthous.Data (TicksPerTile, Hitpoints) import Xanthous.Data.EntityChar import Xanthous.Util.QuickCheck +import Xanthous.Generators.Speech (Language, gormlak, english) -------------------------------------------------------------------------------- +-- | Identifiers for languages that creatures can speak. +-- +-- Non-verbal or non-sentient creatures have Nothing as their language +-- +-- At some point, we will likely want to make languages be defined in data files +-- somewhere, and reference them that way instead. +data LanguageName = Gormlak | English + deriving stock (Show, Eq, Ord, Generic, Enum, Bounded) + deriving anyclass (NFData, CoArbitrary, Function) + deriving Arbitrary via GenericArbitrary LanguageName + deriving (ToJSON, FromJSON) + via WithOptions '[ AllNullaryToStringTag 'True ] + LanguageName + +-- | Resolve a 'LanguageName' into an actual 'Language' +getLanguage :: LanguageName -> Language +getLanguage Gormlak = gormlak +getLanguage English = english + data CreatureType = CreatureType { _name :: !Text , _description :: !Text @@ -55,12 +79,15 @@ data CreatureType = CreatureType , _maxHitpoints :: !Hitpoints , _friendly :: !Bool , _speed :: !TicksPerTile + , _language :: !(Maybe LanguageName) } deriving stock (Show, Eq, Ord, Generic) deriving anyclass (NFData, CoArbitrary, Function) deriving Arbitrary via GenericArbitrary CreatureType deriving (ToJSON, FromJSON) - via WithOptions '[ FieldLabelModifier '[Drop 1] ] + via WithOptions '[ FieldLabelModifier '[Drop 1] + , OmitNothingFields 'True + ] CreatureType makeFieldsNoPrefix ''CreatureType diff --git a/users/grfn/xanthous/src/Xanthous/Entities/Raws/gormlak.yaml b/users/grfn/xanthous/src/Xanthous/Entities/Raws/gormlak.yaml index 2eac89519..41247532f 100644 --- a/users/grfn/xanthous/src/Xanthous/Entities/Raws/gormlak.yaml +++ b/users/grfn/xanthous/src/Xanthous/Entities/Raws/gormlak.yaml @@ -11,3 +11,4 @@ Creature: maxHitpoints: 5 speed: 125 friendly: false + language: Gormlak