diff --git a/route/route.go b/data/data.go similarity index 94% rename from route/route.go rename to data/data.go index 3c4c1f6915d7c33f6e50905a8ff4fc17d6d0f071..76d60187efe1a8c0a0d1b9440cf7832e6bc17bd4 100644 --- a/route/route.go +++ b/data/data.go @@ -1,6 +1,7 @@ -package route +package data import ( + "embed" "github.com/google/uuid" "gopkg.in/yaml.v3" "io/ioutil" @@ -8,6 +9,9 @@ import ( "time" ) +//go:embed storyTemplates/* +var StoryTemplates embed.FS + type Station struct { Id string Name string diff --git a/data/storyTemplates/first.html b/data/storyTemplates/first.html new file mode 100644 index 0000000000000000000000000000000000000000..5ff35f66f3902e139ee71607c107ae04ac671fcd --- /dev/null +++ b/data/storyTemplates/first.html @@ -0,0 +1,6 @@ +<div> + <p> + Előveszed a mobilod, hogy PéK-en megnézd Feri telefonszámát. Megdöbbenve konstatálod, a telefonod nem lát semmilyen wifi hálózatot 😱,<br> + sőőőt, látod, hogy 20%-on vagy csak, pedig felraktad töltőre mielőtt lefeküdtél (bár az hajnal 4-kor volt). + </p> +</div> \ No newline at end of file diff --git a/data/storyTemplates/fourth.html b/data/storyTemplates/fourth.html new file mode 100644 index 0000000000000000000000000000000000000000..2e0b657530d7b27fe03e14828491efe7e69a4ec2 --- /dev/null +++ b/data/storyTemplates/fourth.html @@ -0,0 +1,5 @@ +<div> + <p> + 4 + </p> +</div> \ No newline at end of file diff --git a/data/storyTemplates/last.html b/data/storyTemplates/last.html new file mode 100644 index 0000000000000000000000000000000000000000..1883dbf88ec823dd06be62bb1f4d192f9dedbd95 --- /dev/null +++ b/data/storyTemplates/last.html @@ -0,0 +1,5 @@ +<div> + <p> + last + </p> +</div> \ No newline at end of file diff --git a/data/storyTemplates/second.html b/data/storyTemplates/second.html new file mode 100644 index 0000000000000000000000000000000000000000..f8e98ad3ad697df24c3016b6c59cffdd2f3c115d --- /dev/null +++ b/data/storyTemplates/second.html @@ -0,0 +1,5 @@ +<div> + <p> + 2 + </p> +</div> \ No newline at end of file diff --git a/data/storyTemplates/third.html b/data/storyTemplates/third.html new file mode 100644 index 0000000000000000000000000000000000000000..dfaf5a64e8f8eaa23feb6526450168ab4867ef0c --- /dev/null +++ b/data/storyTemplates/third.html @@ -0,0 +1,5 @@ +<div> + <p> + 3 + </p> +</div> \ No newline at end of file diff --git a/main.go b/main.go index c038ae874073e254a08ab0d750716fce71bedfb0..5b2a25c3e5ccdf43b4273f3ecac9a35f8e0ddc9e 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main import ( - "git.sch.bme.hu/blintmester/keresett-a-feri/route" + "git.sch.bme.hu/blintmester/keresett-a-feri/data" "git.sch.bme.hu/blintmester/keresett-a-feri/web" "log" "math/rand" @@ -10,7 +10,7 @@ import ( func main() { rand.Seed(time.Now().UnixNano()) - route.ReadFile() + data.ReadFile() e := web.Router.Run(":8080") if e != nil { diff --git a/stations.yaml b/stations.yaml index 9965d6238b02103853fd9af0885131c6e30768fe..ef0ffad9725363662388227290836b4ba181ec40 100644 --- a/stations.yaml +++ b/stations.yaml @@ -17,10 +17,8 @@ stations: # TODO: storikat html templatekben megirni, azokat kiszolgalni, nem igy, mert ez igy formazhatatlan stories: - 1: | - Előveszed a mobilod, hogy PéK-en megnézd Feri telefonszámát. Megdöbbenve konstatálod, a telefonod nem lát semmilyen wifi hálózatot 😱, - sőőőt, látod, hogy 20%-on vagy csak, pedig felraktad töltőre mielőtt lefeküdtél (bár az hajnal 4-kor volt). - 2: "masodik" - 3: "harmadik" - 4: "negyedik" - 5: "utolso" + 1: "first.html" + 2: "second.html" + 3: "third.html" + 4: "fourth.html" + 5: "last.html" diff --git a/web/router.go b/web/router.go index 2f3c3c9e28e4979cc8875da3a9162a4aac8c5bae..ee494c059ab06c80cb1d68a5ce7bb9b948ff6f25 100644 --- a/web/router.go +++ b/web/router.go @@ -3,9 +3,10 @@ package web import ( "errors" "fmt" - "git.sch.bme.hu/blintmester/keresett-a-feri/route" + "git.sch.bme.hu/blintmester/keresett-a-feri/data" "github.com/gin-gonic/gin" "github.com/google/uuid" + "html/template" "net/http" "time" ) @@ -34,7 +35,7 @@ func init() { func mainPage(c *gin.Context) { c.HTML(http.StatusOK, "index.html", gin.H{ - "Groups": []route.Group{ + "Groups": []data.Group{ { Id: uuid.New(), Name: "A legjobb csapat", @@ -47,7 +48,7 @@ func mainPage(c *gin.Context) { }) } -func getGroup(b string) (*route.Group, bool) { +func getGroup(b string) (*data.Group, bool) { for i, a := range groups { if a.Name == b { return groups[i], true @@ -56,7 +57,7 @@ func getGroup(b string) (*route.Group, bool) { return nil, false } -func getUser(cookie string) (*route.User, bool) { +func getUser(cookie string) (*data.User, bool) { if cookie != "" { for i, group := range groups { for j, member := range group.Members { @@ -69,7 +70,7 @@ func getUser(cookie string) (*route.User, bool) { return nil, false } -var groups []*route.Group +var groups []*data.Group func login(c *gin.Context) { @@ -79,16 +80,16 @@ func login(c *gin.Context) { groupName := c.PostForm("group") group, ok := getGroup(groupName) if !ok { - group = &route.Group{ + group = &data.Group{ Id: uuid.New(), Name: groupName, Point: 0, - Route: route.CreateNewRoute(), + Route: data.CreateNewRoute(), } groups = append(groups, group) } - user = &route.User{ + user = &data.User{ Id: uuid.New(), Name: c.PostForm("name"), Point: 0, @@ -100,7 +101,7 @@ func login(c *gin.Context) { c.SetCookie("uuid", user.Id.String(), 7200, "/", "", false, true) } - if user.StoryCounter >= len(route.Stories) { + if user.StoryCounter >= len(data.Stories) { _ = c.Error(errors.New("már megoldottad a feladatot")) return } @@ -126,22 +127,22 @@ func routeChooser(c *gin.Context) { return } - station, ok := route.Stations[stationUri.Id] + station, ok := data.Stations[stationUri.Id] if !ok { _ = c.Error(errors.New("wrong uuid")) return } story := "" - var next *route.Station + var next *data.Station for i, stat := range user.Group.Route { if user.StoryCounter < i { break } if stat == station { - story = route.Stories[i+1] - if stat.Id == route.Stations["last"].Id { + story = data.Stories[i+1] + if stat.Id == data.Stations["last"].Id { next = nil } else { next = user.Group.Route[i+1] @@ -156,9 +157,11 @@ func routeChooser(c *gin.Context) { fmt.Println(user.Name + " accessed" + station.Name + " station at " + user.Times[stationUri.Id].String()) } + storyTempl, _ := data.StoryTemplates.ReadFile("storyTemplates/" + story) + c.HTML(http.StatusOK, "station.html", gin.H{ "Name": station.Name, - "Story": story, + "Story": template.HTML(storyTempl), "Next": next, }) } else { diff --git a/web/templates/index.html b/web/templates/index.html index ac760301bf0972022cf15b51df4cef6133f027e8..d0d61366c4cd2fbb09f259cfdb484631c3e3b8fa 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -16,11 +16,11 @@ </p> <h3>Játék menete</h3> <ul> - <li>Olvasd be a QR kódot</li> - <li>Megkapod a történet egy részét</li> - <li>Megkapod, merre találod a következő állomást</li> - <li>Lehetséges, hogy lesznek opcionális állomások, természetesen plusz pontért</li> - <li>Élvezzétek</li> + <li>olvasd be a QR kódot</li> + <li>megkapod a történet egy részét</li> + <li>megkapod, merre találod a következő állomást</li> + <li>lehetséges, hogy lesznek opcionális állomások, természetesen plusz pontért</li> + <li>élvezzétek</li> </ul> <h3>Egyéb tudnivalók</h3> <ul>