Add more things

main
Jerry Aldrich 5 years ago
parent 76868519de
commit edbae31636
  1. 3
      TODO.md
  2. 2
      go.mod
  3. 6
      go.sum
  4. 7
      internal/handlers/handlers.go
  5. 67
      internal/handlers/magic.go
  6. 41
      internal/handlers/maze.go
  7. 19
      internal/handlers/spell.go
  8. 2
      internal/tables/city.go
  9. 76
      internal/tables/maze.go
  10. 150
      web/swagger/docs.go
  11. 150
      web/swagger/swagger.json
  12. 99
      web/swagger/swagger.yaml

@ -1,5 +1,4 @@
Things I'd like to do/fix:
- `go get -u github.com/swaggo/swag/cmd/swag` in Docker
- Search for "existing" in returned table text and replace with generated things
- NOTE: Faction may be easiest
- Replace 1d6 rolls with helper
@ -8,3 +7,5 @@ Things I'd like to do/fix:
- Figure out how to distribute web/ in binaryfile
- Add PORT env var/flag (super easy)
- Generate truly unique list of items (handle impossible requests, expensive computation)
- Pointer on MazeTable?
- Support rooms variable on City/Maze

@ -16,6 +16,6 @@ require (
github.com/urfave/cli/v2 v2.2.0 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/tools v0.0.0-20200711155855-7342f9734a7d // indirect
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)

@ -242,6 +242,12 @@ golang.org/x/tools v0.0.0-20200626171337-aa94e735be7f h1:JcoF/bowzCDI+MXu1yLqQGN
golang.org/x/tools v0.0.0-20200626171337-aa94e735be7f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200711155855-7342f9734a7d h1:F3OmlXCzYtG9YE6tXDnUOlJBzVzHF8EcmZ1yTJlcgIk=
golang.org/x/tools v0.0.0-20200711155855-7342f9734a7d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d h1:hYhnolbefSSt3WZp66sgmgnEOFv5PD6a5PIcnKJ8jdU=
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200715235423-130c9f19d3fe h1:q+DqTBqwpg3C8p5kTZ0WSLOmLxH57dKhWAieWmuFv7M=
golang.org/x/tools v0.0.0-20200715235423-130c9f19d3fe/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6 h1:nULzSsKgihxFGLnQFv2T7lE5vIhOtg8ZPpJHapEt7o0=
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=

@ -9,7 +9,11 @@ import (
func LoadHandlers(r *mux.Router) {
r.HandleFunc("/api/generate/name", GenName)
r.HandleFunc("/api/generate/spell", GenSpell)
r.HandleFunc("/api/generate/mutation", GenMutation)
r.HandleFunc("/api/generate/insanity", GenInsanity)
r.HandleFunc("/api/generate/catastrophe", GenCatastrophe)
r.HandleFunc("/api/generate/monster", GenMonster)
r.HandleFunc("/api/monster/{seed}", Monster)
@ -20,6 +24,9 @@ func LoadHandlers(r *mux.Router) {
r.HandleFunc("/api/generate/city", GenCity)
r.HandleFunc("/api/city/{seed}", City)
r.HandleFunc("/api/generate/dungeon", GenDungeon)
r.HandleFunc("/api/dungeon/{seed}", Dungeon)
r.HandleFunc("/api/roll/{xdy}", Roll)
}

@ -0,0 +1,67 @@
package handlers
import (
"mazeratsgen/internal/dice"
"mazeratsgen/internal/tables"
"net/http"
"time"
)
// @Summary Generate a spell
// @Tags magic
// @Produce application/json, text/plain
// @Method GET
// @Router /api/generate/spell [get]
// @Success 200
func GenSpell(w http.ResponseWriter, r *http.Request) {
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())}
WriteResponse(w, r, t.Generate(), t.Template())
}
// @Summary Generate a mutation
// @Tags magic
// @Produce application/json, text/plain
// @Method GET
// @Router /api/generate/mutation [get]
// @Success 200
func GenMutation(w http.ResponseWriter, r *http.Request) {
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())}
mutation := t.Mutation(t.Roller.TableRoll())
WriteResponse(w, r, mutation, "{{.}}")
}
// @Summary Generate a insanity
// @Tags magic
// @Produce application/json, text/plain
// @Method GET
// @Router /api/generate/insanity [get]
// @Success 200
func GenInsanity(w http.ResponseWriter, r *http.Request) {
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())}
i := t.Insanity(t.Roller.TableRoll())
WriteResponse(w, r, i, "{{.}}")
}
// @Summary Generate a catastrophe
// @Tags magic
// @Produce application/json, text/plain
// @Method GET
// @Router /api/generate/catastrophe [get]
// @Success 200
func GenCatastrophe(w http.ResponseWriter, r *http.Request) {
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())}
c := t.Catastrophe(t.Roller.TableRoll())
WriteResponse(w, r, c, "{{.}}")
}
// @Summary Generate a catastrophe
// @Tags magic
// @Produce application/json, text/plain
// @Method GET
// @Router /api/generate/catastrophe [get]
// @Success 200
func GenCatastophe(w http.ResponseWriter, r *http.Request) {
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())}
c := t.Catastrophe(t.Roller.TableRoll())
WriteResponse(w, r, c, "{{.}}")
}

@ -0,0 +1,41 @@
package handlers
import (
"fmt"
"github.com/gorilla/mux"
"mazeratsgen/internal/dice"
"mazeratsgen/internal/tables"
"net/http"
"strconv"
"time"
)
// @Summary Generate a dungeon
// @Tags dungeon
// @Produce application/json, text/plain
// @Method GET
// @Router /api/generate/dungeon [get]
// @Success 200 {object} tables.Maze
func GenDungeon(w http.ResponseWriter, r *http.Request) {
t := tables.MazeTable{Roller: dice.NewRoller((time.Now().UnixNano()))}
WriteResponse(w, r, t.Generate(), t.Template())
}
// @Summary Generate a specific dungeon using a seed
// @Tags dungeon
// @Produce application/json, text/plain
// @Method GET
// @Router /api/dungeon/{seed} [get]
// @Param seed path int64 true "Int64"
// @Success 200 {object} tables.Maze
func Dungeon(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
seed, err := strconv.ParseInt(vars["seed"], 10, 64)
if err != nil {
w.Write([]byte(fmt.Sprintf("Unable to parse '%v' as Int64", vars["seed"])))
return
}
t := tables.MazeTable{Roller: dice.NewRoller(seed)}
WriteResponse(w, r, t.Generate(), t.Template())
}

@ -1,19 +0,0 @@
package handlers
import (
"mazeratsgen/internal/dice"
"mazeratsgen/internal/tables"
"net/http"
"time"
)
// @Summary Generate a spell
// @Tags magic
// @Produce application/json, text/plain
// @Method GET
// @Router /api/generate/spell [get]
// @Success 200
func GenSpell(w http.ResponseWriter, r *http.Request) {
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())}
WriteResponse(w, r, t.Generate(), t.Template())
}

@ -38,7 +38,7 @@ type City struct {
func (t *CityTable) Generate() City {
upperClassBuildings := []Building{}
// Future Jerry...the weird for loops here are to add noise to seed
// Future Jerry...the weird `for` loops here are to add noise to the seed.
// This will break if more than 6 rooms are needed
for i := 0; i < 3; i++ {

@ -4,6 +4,7 @@ import (
"mazeratsgen/internal/data"
"mazeratsgen/internal/dice"
"mazeratsgen/internal/helpers"
"strings"
)
type MazeTable struct {
@ -22,43 +23,74 @@ type Maze struct {
Ruination string
Reward string
Activities []string
Rooms []Room
Rooms []string
Tricks []string
Hazards []string
TrapEffects []string
TrapTriggers []string
Seed int64
}
func GenMaze(seed int64) Maze {
roller := dice.NewRoller(seed)
mazeTable := MazeTable{Roller: roller}
func (t MazeTable) Generate() Maze {
total_rooms := 5
roomTypes := helpers.GenUniqueItems(total_rooms, mazeTable.DungeonRoom, seed)
roomDetails := helpers.GenUniqueItems(total_rooms, mazeTable.DungeonRoomDetail, seed)
rooms := []Room{}
roomTypes := helpers.GenUniqueItems(total_rooms, t.DungeonRoom, t.Roller.Seed)
roomDetails := helpers.GenUniqueItems(total_rooms, t.DungeonRoomDetail, t.Roller.Seed)
rooms := []string{}
for i := 0; i < total_rooms; i++ {
room := Room{
Type: roomTypes[i],
Detail: roomDetails[i],
}
room := roomTypes[i] + " with " + strings.ToLower(roomDetails[i])
rooms = append(rooms, room)
}
return Maze{
Form: mazeTable.DungeonForm(roller.TableRoll()),
Entrance: mazeTable.DungeonEntrance(roller.TableRoll()),
Layout: mazeTable.DungeonLayout(roller.TableRoll()),
Ruination: mazeTable.DungeonRuination(roller.TableRoll()),
Reward: mazeTable.DungeonReward(roller.TableRoll()),
Activities: helpers.GenUniqueItems(5, mazeTable.DungeonActivity, seed),
Form: t.DungeonForm(t.Roller.TableRoll()),
Entrance: t.DungeonEntrance(t.Roller.TableRoll()),
Layout: t.DungeonLayout(t.Roller.TableRoll()),
Ruination: t.DungeonRuination(t.Roller.TableRoll()),
Reward: t.DungeonReward(t.Roller.TableRoll()),
Activities: helpers.GenUniqueItems(5, t.DungeonActivity, t.Roller.Seed),
Rooms: rooms,
Hazards: helpers.GenUniqueItems(5, mazeTable.DungeonHazard, seed),
Tricks: helpers.GenUniqueItems(5, mazeTable.DungeonTrick, seed),
TrapEffects: helpers.GenUniqueItems(5, mazeTable.TrapEffect, seed),
TrapTriggers: helpers.GenUniqueItems(5, mazeTable.TrapTrigger, seed),
Hazards: helpers.GenUniqueItems(5, t.DungeonHazard, t.Roller.Seed),
Tricks: helpers.GenUniqueItems(5, t.DungeonTrick, t.Roller.Seed),
TrapEffects: helpers.GenUniqueItems(5, t.TrapEffect, t.Roller.Seed),
TrapTriggers: helpers.GenUniqueItems(5, t.TrapTrigger, t.Roller.Seed),
Seed: t.Roller.Seed,
}
}
func (t MazeTable) Template() string {
return strings.TrimSpace(`
Form: {{.Form}}
Entrance: {{.Entrance}}
Layout: {{.Layout}}
Ruination: {{.Ruination}}
Reward: {{.Reward}}
Activities:
{{- range $activity := .Activities}}
{{$activity}}
{{- end}}
Rooms:
{{- range $room := .Rooms}}
{{$room}}
{{- end}}
Tricks:
{{- range $trick := .Tricks}}
{{$trick}}
{{- end}}
Hazards:
{{- range $hazard := .Hazards}}
{{$hazard}}
{{- end}}
Trap Effects:
{{- range $trapEffect := .TrapEffects}}
{{$trapEffect}}
{{- end}}
Trap Triggers:
{{- range $trapTrigger := .TrapTriggers}}
{{$trapTrigger}}
{{- end}}
Seed: {{.Seed}}
`)
}
func (t MazeTable) DungeonEntrance(roll [2]int) string {
roll[0], roll[1] = roll[0]-1, roll[0]-1
return data.Tables.Maze.DungeonEntrances[roll[0]][roll[1]]

@ -83,6 +83,50 @@ var doc = `{
}
}
},
"/api/dungeon/{seed}": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"dungeon"
],
"summary": "Generate a specific dungeon using a seed",
"parameters": [
{
"type": "integer",
"description": "Int64",
"name": "seed",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/tables.Maze"
}
}
}
}
},
"/api/generate/catastrophe": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"magic"
],
"summary": "Generate a catastrophe",
"responses": {
"200": {}
}
}
},
"/api/generate/character": {
"get": {
"produces": [
@ -123,6 +167,41 @@ var doc = `{
}
}
},
"/api/generate/dungeon": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"dungeon"
],
"summary": "Generate a dungeon",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/tables.Maze"
}
}
}
}
},
"/api/generate/insanity": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"magic"
],
"summary": "Generate a insanity",
"responses": {
"200": {}
}
}
},
"/api/generate/monster": {
"get": {
"produces": [
@ -143,6 +222,21 @@ var doc = `{
}
}
},
"/api/generate/mutation": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"magic"
],
"summary": "Generate a mutation",
"responses": {
"200": {}
}
}
},
"/api/generate/name": {
"get": {
"produces": [
@ -380,6 +474,62 @@ var doc = `{
}
}
},
"tables.Maze": {
"type": "object",
"properties": {
"activities": {
"type": "array",
"items": {
"type": "string"
}
},
"entrance": {
"type": "string"
},
"form": {
"type": "string"
},
"hazards": {
"type": "array",
"items": {
"type": "string"
}
},
"layout": {
"type": "string"
},
"reward": {
"type": "string"
},
"rooms": {
"type": "array",
"items": {
"type": "string"
}
},
"ruination": {
"type": "string"
},
"trapEffects": {
"type": "array",
"items": {
"type": "string"
}
},
"trapTriggers": {
"type": "array",
"items": {
"type": "string"
}
},
"tricks": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"tables.Monster": {
"type": "object",
"properties": {

@ -65,6 +65,50 @@
}
}
},
"/api/dungeon/{seed}": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"dungeon"
],
"summary": "Generate a specific dungeon using a seed",
"parameters": [
{
"type": "integer",
"description": "Int64",
"name": "seed",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/tables.Maze"
}
}
}
}
},
"/api/generate/catastrophe": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"magic"
],
"summary": "Generate a catastrophe",
"responses": {
"200": {}
}
}
},
"/api/generate/character": {
"get": {
"produces": [
@ -105,6 +149,41 @@
}
}
},
"/api/generate/dungeon": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"dungeon"
],
"summary": "Generate a dungeon",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/tables.Maze"
}
}
}
}
},
"/api/generate/insanity": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"magic"
],
"summary": "Generate a insanity",
"responses": {
"200": {}
}
}
},
"/api/generate/monster": {
"get": {
"produces": [
@ -125,6 +204,21 @@
}
}
},
"/api/generate/mutation": {
"get": {
"produces": [
"application/json",
" text/plain"
],
"tags": [
"magic"
],
"summary": "Generate a mutation",
"responses": {
"200": {}
}
}
},
"/api/generate/name": {
"get": {
"produces": [
@ -362,6 +456,62 @@
}
}
},
"tables.Maze": {
"type": "object",
"properties": {
"activities": {
"type": "array",
"items": {
"type": "string"
}
},
"entrance": {
"type": "string"
},
"form": {
"type": "string"
},
"hazards": {
"type": "array",
"items": {
"type": "string"
}
},
"layout": {
"type": "string"
},
"reward": {
"type": "string"
},
"rooms": {
"type": "array",
"items": {
"type": "string"
}
},
"ruination": {
"type": "string"
},
"trapEffects": {
"type": "array",
"items": {
"type": "string"
}
},
"trapTriggers": {
"type": "array",
"items": {
"type": "string"
}
},
"tricks": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"tables.Monster": {
"type": "object",
"properties": {

@ -100,6 +100,43 @@ definitions:
type:
type: string
type: object
tables.Maze:
properties:
activities:
items:
type: string
type: array
entrance:
type: string
form:
type: string
hazards:
items:
type: string
type: array
layout:
type: string
reward:
type: string
rooms:
items:
type: string
type: array
ruination:
type: string
trapEffects:
items:
type: string
type: array
trapTriggers:
items:
type: string
type: array
tricks:
items:
type: string
type: array
type: object
tables.Monster:
properties:
ability:
@ -193,6 +230,35 @@ paths:
summary: Generate a specific city using a seed
tags:
- city
/api/dungeon/{seed}:
get:
parameters:
- description: Int64
in: path
name: seed
required: true
type: integer
produces:
- application/json
- ' text/plain'
responses:
"200":
description: OK
schema:
$ref: '#/definitions/tables.Maze'
summary: Generate a specific dungeon using a seed
tags:
- dungeon
/api/generate/catastrophe:
get:
produces:
- application/json
- ' text/plain'
responses:
"200": {}
summary: Generate a catastrophe
tags:
- magic
/api/generate/character:
get:
produces:
@ -219,6 +285,29 @@ paths:
summary: Generate a city
tags:
- city
/api/generate/dungeon:
get:
produces:
- application/json
- ' text/plain'
responses:
"200":
description: OK
schema:
$ref: '#/definitions/tables.Maze'
summary: Generate a dungeon
tags:
- dungeon
/api/generate/insanity:
get:
produces:
- application/json
- ' text/plain'
responses:
"200": {}
summary: Generate a insanity
tags:
- magic
/api/generate/monster:
get:
produces:
@ -232,6 +321,16 @@ paths:
summary: Generate a monster
tags:
- monster
/api/generate/mutation:
get:
produces:
- application/json
- ' text/plain'
responses:
"200": {}
summary: Generate a mutation
tags:
- magic
/api/generate/name:
get:
produces:

Loading…
Cancel
Save