latest
Branches > facts > latest > files
Add chat messages and facts
Commit: 89e82524fa0ce4f4835c30eecb984168d43e91dc
Parent: 9a69ad5
4 changed files:
src/net/bowmap/protocol/handle.clj view file
@@ -155,3 +155,8 @@ (defmethod handle-packet ::serverbound/set-player-movement-flags [client pk] (handle-player-update-movement-packet client pk))++(defmethod handle-packet ::serverbound/chat-message [{::player/keys! [uuid]} {:keys! [message]}]+ {:facts [{::fact/attribute ::fact/player-sent-chat-message+ ::fact/entity uuid+ ::fact/value message}]})src/net/bowmap/protocol/packet/serverbound.clj view file
@@ -149,6 +149,8 @@ ; Play + ; there are a bunch of other fields but idrgaf about any of them lol.+ ::chat-message [:message ->string] ::confirm-teleportation [:teleport-id ->varint] #_::query-block-entity-tag #_::bundle-item-selectedsrc/net/bowmap/server/logic.clj view file
@@ -51,6 +51,12 @@ ; Called when the player actually moves, not just when a position is sent (defmethod handle-fact ::fact/player-moved [_ _]) +(defmethod handle-fact ::fact/player-sent-chat-message [{::fact/keys! [entity value]}]+ [{::fact/attribute ::fact/message+ ::fact/entity (random-uuid)+ ::fact/value {:message value+ :author entity}}])+ (defn apply-rules "Applies rules recursively, returns a map containing :facts and :effects. :facts being the seqs of all facts that were asserted/retracted,src/net/bowmap/stormbow/fact.clj view file
@@ -4,14 +4,17 @@ (s/def ::fact (s/keys :opt [::attribute ::entity ::value])) -(defonce attributes->entity-value-pairs (ref {}))+(defonce aev (ref {})) ; These are all ephemeral right now ofc :p+; Registers an ephemeral attribute+; For ephemeral stuff, I don't think this is a good way to go about this :p+; Makes sense for persistent information, but this is just terrible concurrency. (defn register-attribute! [attribute cardinality] (case cardinality ::one (dosync- (commute attributes->entity-value-pairs assoc attribute (ref {}))))+ (commute aev assoc attribute (ref {})))) attribute) (register-attribute! ::playing ::one)@@ -19,13 +22,13 @@ (defn assert-fact [attribute entity value] (dosync ; Can only have one value- (alter (@attributes->entity-value-pairs attribute) assoc entity value)))+ (alter (@aev attribute) assoc entity value))) (defn retract-fact [attribute entity] (dosync- (alter (req! @attributes->entity-value-pairs attribute) dissoc entity)))+ (alter (req! @aev attribute) dissoc entity))) (defn fact "Returns the current transactional value of the fact given its attribute" [attribute]- (some-> (@attributes->entity-value-pairs attribute) deref))+ (some-> (@aev attribute) deref))