Documentation ¶
Index ¶
- Variables
- type EngineConfig
- type Exit
- type GameManager
- func (gm *GameManager) ConstructSpeculativeStates(gameState GameState, currentRoom Room) ([]SpeculativeState, error)
- func (gm *GameManager) ConstructStartingState(story StoryMetadata) (SpeculativeState, error)
- func (gm *GameManager) DeserializeState(stateToken string) (GameState, error)
- func (gm *GameManager) GetRoomByID(storyID string, roomID string) (Room, error)
- func (gm *GameManager) GetStories() []StoryMetadata
- func (gm *GameManager) SerializeState(gameState GameState) (string, error)
- func (gm *GameManager) StartGame(storyID string) (GameState, error)
- type GameState
- type Room
- type SerializationFormat
- type SpeculativeState
- type StateToken
- func (*StateToken) Descriptor() ([]byte, []int)deprecated
- func (x *StateToken) GetConditions() []string
- func (x *StateToken) GetCurrentRoom() string
- func (x *StateToken) GetStoryID() string
- func (*StateToken) ProtoMessage()
- func (x *StateToken) ProtoReflect() protoreflect.Message
- func (x *StateToken) Reset()
- func (x *StateToken) String() string
- type Story
- type StoryBook
- type StoryMetadata
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRoomNotFound occurs when the room doesn't exist in the given story. ErrRoomNotFound = errors.New("room not found") // ErrExitNotFound occurs when the exit doesn't exit in the given room. ErrExitNotFound = errors.New("exit not found") )
var ErrInvalidSerializationFormat = errors.New("invalid serialization format")
ErrInvalidSerializationFormat occurs when engine config specifies a unsupported format.
var ErrInvalidStoryDirectory = errors.New("story directory does not exist")
ErrInvalidStoryDirectory occurs when the config specifies a nonexistent story directory.
var File_gamemanager_statetoken_proto protoreflect.FileDescriptor
Functions ¶
This section is empty.
Types ¶
type EngineConfig ¶
type EngineConfig struct { RenderDescriptions bool StateTokenFormat SerializationFormat }
EngineConfig contains settings information for driving the engine.
func NewEngineConfig ¶
func NewEngineConfig(renderDesc bool, tokenFormat string) (EngineConfig, error)
NewEngineConfig news up an EngineConfig based on passed in values.
type Exit ¶
type Exit struct { Description string `yaml:"exit_description" json:"exit_description"` Destination string `yaml:"destination_id" json:"destination_id" binding:"uuid"` SetCondition string `yaml:"set_condition,omitempty" json:"set_condition"` IfCondition string `yaml:"if_condition,omitempty" json:"if_condition"` NotCondition string `yaml:"not_condition,omitempty" json:"not_condition"` UnsetCondition string `yaml:"unset_condition,omitempty" json:"unset_condition"` }
Exit describes actions applied to GameState as part of leaving a Room.
type GameManager ¶
type GameManager struct { Book StoryBook EngineConfig EngineConfig }
GameManager contains configuration info about stories and managed GameState objects.
func NewGameManager ¶
func NewGameManager(book StoryBook, config EngineConfig) (*GameManager, error)
NewGameManager creates a new GameManager, using Stories in the Config.
func (*GameManager) ConstructSpeculativeStates ¶
func (gm *GameManager) ConstructSpeculativeStates(gameState GameState, currentRoom Room) ([]SpeculativeState, error)
ConstructSpeculativeStates makes a SpeculativeState from the active GameState and actions available in currentRoom.
func (*GameManager) ConstructStartingState ¶
func (gm *GameManager) ConstructStartingState(story StoryMetadata) (SpeculativeState, error)
ConstructStartingState generates a starting stateToken for each loaded story.
func (*GameManager) DeserializeState ¶
func (gm *GameManager) DeserializeState(stateToken string) (GameState, error)
DeserializeState converts a stateToken into a GameState.
func (*GameManager) GetRoomByID ¶
func (gm *GameManager) GetRoomByID(storyID string, roomID string) (Room, error)
GetRoomByID finds Room information based on room and story IDs.
func (*GameManager) GetStories ¶
func (gm *GameManager) GetStories() []StoryMetadata
GetStories lists all StoryMetadata for stories tracked by GameManager.
func (*GameManager) SerializeState ¶
func (gm *GameManager) SerializeState(gameState GameState) (string, error)
SerializeState generates a stateToken based on the given GameState.
type GameState ¶
type GameState struct { StoryID string `json:"si"` CurrentRoom string `json:"cr"` Conditions []string `json:"cn"` }
GameState contains state information about an active game in progress.
func (GameState) ConditionMet ¶
ConditionMet checks to see if a condition has been met.
func (*GameState) MeetCondition ¶
MeetCondition adds a condtition to the list of met conditions if not already met.
func (*GameState) RemoveCondition ¶
RemoveCondition removes a condtition from the list of met conditions if it exists.
type Room ¶
type Room struct { ID string `yaml:"room_id" json:"room_id" binding:"uuid"` Name string `yaml:"room_name" json:"room_name"` Description string `yaml:"room_description,omitempty" json:"room_description"` Exits []Exit `yaml:"exits,omitempty" json:"exits"` }
Room contains information about a room and its Exits.
type SerializationFormat ¶
type SerializationFormat int
SerializationFormat determines which format StateTokens are serialized as.
const ( // JSON describes the json serilization format. JSON SerializationFormat = iota + 1 // Protobuf describes the protobuf serilization format. Protobuf )
func GetSerDeFormat ¶
func GetSerDeFormat(format string) SerializationFormat
GetSerDeFormat translates format type strings to SerializationFormat.
type SpeculativeState ¶
SpeculativeState is used to provide "what if" GameStates for next available actions.
type StateToken ¶
type StateToken struct { StoryID string `protobuf:"bytes,1,opt,name=StoryID,json=sid,proto3" json:"StoryID,omitempty"` CurrentRoom string `protobuf:"bytes,2,opt,name=CurrentRoom,json=cr,proto3" json:"CurrentRoom,omitempty"` Conditions []string `protobuf:"bytes,3,rep,name=Conditions,json=cn,proto3" json:"Conditions,omitempty"` // contains filtered or unexported fields }
func (*StateToken) Descriptor
deprecated
func (*StateToken) Descriptor() ([]byte, []int)
Deprecated: Use StateToken.ProtoReflect.Descriptor instead.
func (*StateToken) GetConditions ¶
func (x *StateToken) GetConditions() []string
func (*StateToken) GetCurrentRoom ¶
func (x *StateToken) GetCurrentRoom() string
func (*StateToken) GetStoryID ¶
func (x *StateToken) GetStoryID() string
func (*StateToken) ProtoMessage ¶
func (*StateToken) ProtoMessage()
func (*StateToken) ProtoReflect ¶
func (x *StateToken) ProtoReflect() protoreflect.Message
func (*StateToken) Reset ¶
func (x *StateToken) Reset()
func (*StateToken) String ¶
func (x *StateToken) String() string
type Story ¶
type Story struct { Metadata StoryMetadata `yaml:"metadata" json:"metadata"` Rooms []Room `yaml:"rooms" json:"rooms"` }
Story contains all information about a loaded story.
type StoryBook ¶
StoryBook contains information on all of the stories loaded from disk.
func NewStoryBook ¶
NewStoryBook makes a new Config object and loads in all of the stories from the given path.
type StoryMetadata ¶
type StoryMetadata struct { ID string `yaml:"id"` Name string `yaml:"name"` Description string `yaml:"description"` ContentWarnings []string `yaml:"cw"` StartingScene string `yaml:"starting_scene"` Author string `yaml:"author"` }
StoryMetadata contains story metadata - authorship information, etc.