This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/examples/flow/main.go

99 lines
2.7 KiB
Go
Raw Normal View History

package main
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/flow"
2023-03-31 03:19:04 +00:00
import "git.tebibyte.media/sashakoshka/tomo/elements"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
func main () {
tomo.Run(run)
}
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 192, 192))
window.SetTitle("adventure")
2023-04-18 20:18:30 +00:00
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
var world flow.Flow
world.Transition = container.DisownAll
world.Stages = map [string] func () {
"start": func () {
2023-04-18 20:18:30 +00:00
label := elements.NewLabelWrapped (
"you are standing next to a river.")
2023-03-31 03:19:04 +00:00
button0 := elements.NewButton("go in the river")
button0.OnClick(world.SwitchFunc("wet"))
2023-03-31 03:19:04 +00:00
button1 := elements.NewButton("walk along the river")
button1.OnClick(world.SwitchFunc("house"))
2023-03-31 03:19:04 +00:00
button2 := elements.NewButton("turn around")
button2.OnClick(world.SwitchFunc("bear"))
2023-04-18 20:18:30 +00:00
container.AdoptExpand(label)
container.Adopt(button0, button1, button2)
2023-04-16 02:23:08 +00:00
button0.Focus()
},
"wet": func () {
2023-04-18 20:18:30 +00:00
label := elements.NewLabelWrapped (
"you get completely soaked.\n" +
2023-04-18 20:18:30 +00:00
"you die of hypothermia.")
2023-03-31 03:19:04 +00:00
button0 := elements.NewButton("try again")
button0.OnClick(world.SwitchFunc("start"))
2023-03-31 03:19:04 +00:00
button1 := elements.NewButton("exit")
button1.OnClick(tomo.Stop)
2023-04-18 20:18:30 +00:00
container.AdoptExpand(label)
container.Adopt(button0, button1)
2023-04-16 02:23:08 +00:00
button0.Focus()
},
"house": func () {
2023-04-18 20:18:30 +00:00
label := elements.NewLabelWrapped (
"you are standing in front of a delapidated " +
2023-04-18 20:18:30 +00:00
"house.")
2023-03-31 03:19:04 +00:00
button1 := elements.NewButton("go inside")
button1.OnClick(world.SwitchFunc("inside"))
2023-03-31 03:19:04 +00:00
button0 := elements.NewButton("turn back")
button0.OnClick(world.SwitchFunc("start"))
2023-04-18 20:18:30 +00:00
container.AdoptExpand(label)
container.Adopt(button0, button1)
2023-04-16 02:23:08 +00:00
button1.Focus()
},
"inside": func () {
2023-04-18 20:18:30 +00:00
label := elements.NewLabelWrapped (
"you are standing inside of the house.\n" +
"it is dark, but rays of light stream " +
"through the window.\n" +
"there is nothing particularly interesting " +
2023-04-18 20:18:30 +00:00
"here.")
2023-03-31 03:19:04 +00:00
button0 := elements.NewButton("go back outside")
button0.OnClick(world.SwitchFunc("house"))
2023-04-18 20:18:30 +00:00
container.AdoptExpand(label)
container.Adopt(button0)
2023-04-16 02:23:08 +00:00
button0.Focus()
},
"bear": func () {
2023-04-18 20:18:30 +00:00
label := elements.NewLabelWrapped (
"you come face to face with a bear.\n" +
2023-04-18 20:18:30 +00:00
"it eats you (it was hungry).")
2023-03-31 03:19:04 +00:00
button0 := elements.NewButton("try again")
button0.OnClick(world.SwitchFunc("start"))
2023-03-31 03:19:04 +00:00
button1 := elements.NewButton("exit")
button1.OnClick(tomo.Stop)
2023-04-18 20:18:30 +00:00
container.AdoptExpand(label)
container.Adopt(button0, button1)
2023-04-16 02:23:08 +00:00
button0.Focus()
},
}
world.Switch("start")
window.OnClose(tomo.Stop)
window.Show()
}