realm.gno
0.92 Kb ยท 53 lines
1package tamagotchi
2
3import (
4 "std"
5
6 "gno.land/p/demo/tamagotchi"
7 "gno.land/p/demo/ufmt"
8)
9
10var t *tamagotchi.Tamagotchi
11
12func init(cur realm) {
13 Reset(cur, "gnome#0")
14}
15
16func Reset(cur realm, optionalName string) string {
17 name := optionalName
18 if name == "" {
19 height := std.ChainHeight()
20 name = ufmt.Sprintf("gnome#%d", height)
21 }
22
23 t = tamagotchi.New(name)
24
25 return ufmt.Sprintf("A new tamagotchi is born. Their name is %s %s.", t.Name(), t.Face())
26}
27
28func Feed(cur realm) string {
29 t.Feed()
30 return t.Markdown()
31}
32
33func Play(cur realm) string {
34 t.Play()
35 return t.Markdown()
36}
37
38func Heal(cur realm) string {
39 t.Heal()
40 return t.Markdown()
41}
42
43func Render(path string) string {
44 tama := t.Markdown()
45 links := `Actions:
46* [Feed](/r/demo/tamagotchi$help&func=Feed)
47* [Play](/r/demo/tamagotchi$help&func=Play)
48* [Heal](/r/demo/tamagotchi$help&func=Heal)
49* [Reset](/r/demo/tamagotchi$help&func=Reset)
50`
51
52 return tama + "\n\n" + links
53}