gochoose

package module
v0.0.0-...-639724c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

README

gochoose

A very simple engine for web-based CYOA games. To install the example application, do:

$ go get -d
$ go run example/example.go

The example application is commented and is a good place to start for guidance on how to use this module.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHandler

func GetHandler(w http.ResponseWriter, r *http.Request, db *bolt.DB, tp *template.Template, user User)

func InitDB

func InitDB(path string) error

func OpenDB

func OpenDB(path string) (*bolt.DB, error)

func ProgressHandler

func ProgressHandler(db *bolt.DB, user User, params url.Values)

func SaveStage

func SaveStage(db *bolt.DB, stage Stage) error

func SaveUser

func SaveUser(db *bolt.DB, user User) error

Types

type CYOAFields

type CYOAFields struct {
	Body  template.HTML
	Links template.HTML
}

type CYOAServer

type CYOAServer struct {
	Server   *http.Server
	DB       *bolt.DB
	Template *template.Template
}

func NewCYOAServer

func NewCYOAServer(host string, port int, db *bolt.DB, template_path string) (*CYOAServer, error)

func (*CYOAServer) CYOAHandler

func (s *CYOAServer) CYOAHandler(w http.ResponseWriter, r *http.Request)

type Stage

type Stage struct {
	ID    uuid.UUID  // The unique UUID for this stage. The "progress" value of the User struct acts as a foreign key for this identified.
	Body  string     // The contents of this stage's HTML body.
	Links [][]string // A slice of slices, containing the possible options to progress from this stage. Each element contains ["text", "uuid"].
}

func LoadStage

func LoadStage(db *bolt.DB, id uuid.UUID) (Stage, error)

func NewStage

func NewStage() Stage

func NewStartStage

func NewStartStage() Stage
func (s *Stage) AddLink(destination Stage, text string)

func (*Stage) FromJSON

func (s *Stage) FromJSON(j []byte) error
func (s Stage) GenerateLinks() string

func (Stage) ToJSON

func (s Stage) ToJSON() ([]byte, error)

type User

type User struct {
	ID       uuid.UUID // The unique UUID for this user, sent as a cookie by the browser.
	Progress uuid.UUID // A UUID representing the user's current progress in the game. Acts as a "foreign key" to the Stages bucket.
}

func CookieHandler

func CookieHandler(w http.ResponseWriter, r *http.Request, db *bolt.DB) User

func LoadUser

func LoadUser(db *bolt.DB, id uuid.UUID) (User, error)

func NewUser

func NewUser() User

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL