biome_info.gno
2.94 Kb · 118 lines
1package personal_world
2
3import (
4 "chain"
5 "strconv"
6
7 "gno.land/p/akkadia/v0/accesscontrol"
8 "gno.land/r/akkadia/v0/admin"
9)
10
11const (
12 SetBiomeInfoEvent = "SetBiomeInfo"
13 SetDefaultBiomeEvent = "SetDefaultBiome"
14)
15
16func init() {
17 worldConfigStore.SetBiomeInfo(map[string]string{
18 "biome": "everdawn_plains",
19 "cost": "100000000",
20 "priceMultiplierBPS": "10000",
21 "name": "Everdawn Plains",
22 "description": "The beginning of all things — a peaceful grassland bathed in eternal morning light.",
23 "theme": "origin,serenity",
24 })
25 worldConfigStore.SetDefaultBiome("everdawn_plains")
26}
27
28// SetBiomeInfo sets a single biome info (admin only).
29// priceMultiplierBPS uses 10_000 as 1x.
30func SetBiomeInfo(cur realm, propKeys string, propValues string) {
31 assertNotFrozen()
32 accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
33
34 props := parsePropertiesCSV(propKeys, propValues)
35
36 biomeInfoValidator.MustValidate(props)
37 assertBiomeName(props["biome"])
38 mustParseBiomeCost(props["cost"])
39 mustParseBiomePriceMultiplierBPS(props["priceMultiplierBPS"])
40
41 worldConfigStore.SetBiomeInfo(props)
42
43 chain.Emit(
44 SetBiomeInfoEvent,
45 "biome", props["biome"],
46 "cost", props["cost"],
47 "priceMultiplierBPS", props["priceMultiplierBPS"],
48 )
49}
50
51func GetBiomeInfo(biomeName string) map[string]string {
52 assertMigrationStateAvailable()
53 assertBiomeName(biomeName)
54 assertBiomeExists(biomeName)
55 return worldConfigStore.MustGetBiomeInfo(biomeName)
56}
57
58func HasBiomeInfo(biomeName string) bool {
59 assertMigrationStateAvailable()
60 return worldConfigStore.HasBiomeInfo(biomeName)
61}
62
63func ListBiomeInfos() []map[string]string {
64 assertMigrationStateAvailable()
65 return worldConfigStore.ListBiomeInfos()
66}
67
68// GetActualCreationCost returns the biome creation cost.
69func GetActualCreationCost(biome string) int64 {
70 assertMigrationStateAvailable()
71 assertBiomeName(biome)
72 assertBiomeExists(biome)
73 cost, ok := creationCost(biome)
74 if !ok {
75 panic("invalid creation cost")
76 }
77 return cost
78}
79
80func creationCost(biomeName string) (int64, bool) {
81 info, found := worldConfigStore.GetBiomeInfo(biomeName)
82 if !found {
83 return maxInt64, false
84 }
85 cost, err := strconv.ParseInt(info["cost"], 10, 64)
86 if err != nil {
87 return maxInt64, false
88 }
89 return cost, true
90}
91
92// SetDefaultBiome sets the default biome (admin only)
93func SetDefaultBiome(cur realm, biomeName string) {
94 assertNotFrozen()
95 accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
96 assertBiomeName(biomeName)
97 assertBiomeExists(biomeName)
98
99 oldDefault := worldConfigStore.SetDefaultBiome(biomeName)
100
101 chain.Emit(
102 SetDefaultBiomeEvent,
103 "oldDefault", oldDefault,
104 "newDefault", worldConfigStore.DefaultBiome(),
105 )
106}
107
108// GetDefaultBiome returns the current default biome name
109func GetDefaultBiome() string {
110 assertMigrationStateAvailable()
111 return worldConfigStore.DefaultBiome()
112}
113
114func assertBiomeExists(biomeName string) {
115 if !worldConfigStore.HasBiomeInfo(biomeName) {
116 panic("unknown biome")
117 }
118}