-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
option_gen.go
167 lines (152 loc) · 4.76 KB
/
option_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Code generated from "enum.go.tmpl" - DO NOT EDIT.
/*
* Copyright ©1998-2023 by Richard A. Wilkes. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, version 2.0. If a copy of the MPL was not distributed with
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, version 2.0.
*/
package progression
import (
"strings"
"github.com/richardwilkes/toolbox/i18n"
)
// Possible values.
const (
BasicSet Option = iota
KnowingYourOwnStrength
NoSchoolGrognardDamage
ThrustEqualsSwingMinus2
SwingEqualsThrustPlus2
Tbone1
Tbone1Clean
Tbone2
Tbone2Clean
PhoenixFlameD3
)
// LastOption is the last valid value.
const LastOption Option = PhoenixFlameD3
// Options holds all possible values.
var Options = []Option{
BasicSet,
KnowingYourOwnStrength,
NoSchoolGrognardDamage,
ThrustEqualsSwingMinus2,
SwingEqualsThrustPlus2,
Tbone1,
Tbone1Clean,
Tbone2,
Tbone2Clean,
PhoenixFlameD3,
}
// Option controls how Thrust and Swing are calculated.
type Option byte
// EnsureValid ensures this is of a known value.
func (enum Option) EnsureValid() Option {
if enum <= PhoenixFlameD3 {
return enum
}
return 0
}
// Key returns the key used in serialization.
func (enum Option) Key() string {
switch enum {
case BasicSet:
return "basic_set"
case KnowingYourOwnStrength:
return "knowing_your_own_strength"
case NoSchoolGrognardDamage:
return "no_school_grognard_damage"
case ThrustEqualsSwingMinus2:
return "thrust_equals_swing_minus_2"
case SwingEqualsThrustPlus2:
return "swing_equals_thrust_plus_2"
case Tbone1:
return "tbone_1"
case Tbone1Clean:
return "tbone_1_clean"
case Tbone2:
return "tbone_2"
case Tbone2Clean:
return "tbone_2_clean"
case PhoenixFlameD3:
return "phoenix_flame_d3"
default:
return Option(0).Key()
}
}
// String implements fmt.Stringer.
func (enum Option) String() string {
switch enum {
case BasicSet:
return i18n.Text("Basic Set")
case KnowingYourOwnStrength:
return i18n.Text("Knowing Your Own Strength")
case NoSchoolGrognardDamage:
return i18n.Text("No School Grognard Damage")
case ThrustEqualsSwingMinus2:
return i18n.Text("Thrust = Swing-2")
case SwingEqualsThrustPlus2:
return i18n.Text("Swing = Thrust+2")
case Tbone1:
return i18n.Text("T Bone's New Damage for ST (option 1)")
case Tbone1Clean:
return i18n.Text("T Bone's New Damage for ST (option 1, cleaned)")
case Tbone2:
return i18n.Text("T Bone's New Damage for ST (option 2)")
case Tbone2Clean:
return i18n.Text("T Bone's New Damage for ST (option 2, cleaned)")
case PhoenixFlameD3:
return i18n.Text("Phoenix Flame D3")
default:
return Option(0).String()
}
}
// AltString returns the alternate string.
func (enum Option) AltString() string {
switch enum {
case BasicSet:
return i18n.Text("*The standard damage progression*")
case KnowingYourOwnStrength:
return i18n.Text("*From [Pyramid 3-83, pages 16-19](PY83:16)*")
case NoSchoolGrognardDamage:
return i18n.Text("*From [Adjusting Swing Damage in Dungeon Fantasy](https://noschoolgrognard.blogspot.com/2013/04/adjusting-swing-damage-in-dungeon.html)*")
case ThrustEqualsSwingMinus2:
return i18n.Text("*From [Alternate Damage Scheme (Thr = Sw-2)](https://github.com/richardwilkes/gcs/issues/97)*")
case SwingEqualsThrustPlus2:
return i18n.Text("*From a [house rule](https://gamingballistic.com/2020/12/04/df-eastmarch-boss-fight-and-house-rules/) originating with Kevin Smyth*")
case Tbone1:
return i18n.Text("*From [T Bone's Games Diner](https://www.gamesdiner.com/rules-nugget-gurps-new-damage-for-st/)*")
case Tbone1Clean:
return i18n.Text("*From [T Bone's Games Diner](https://www.gamesdiner.com/rules-nugget-gurps-new-damage-for-st/)*")
case Tbone2:
return i18n.Text("*From [T Bone's Games Diner](https://www.gamesdiner.com/rules-nugget-gurps-new-damage-for-st/)*")
case Tbone2Clean:
return i18n.Text("*From [T Bone's Games Diner](https://www.gamesdiner.com/rules-nugget-gurps-new-damage-for-st/)*")
case PhoenixFlameD3:
return i18n.Text("*From a [house rule](https://github.com/richardwilkes/gcs/pull/393) that uses d3s instead of d6s for damage*")
default:
return Option(0).AltString()
}
}
// MarshalText implements the encoding.TextMarshaler interface.
func (enum Option) MarshalText() (text []byte, err error) {
return []byte(enum.Key()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (enum *Option) UnmarshalText(text []byte) error {
*enum = ExtractOption(string(text))
return nil
}
// ExtractOption extracts the value from a string.
func ExtractOption(str string) Option {
for _, enum := range Options {
if strings.EqualFold(enum.Key(), str) {
return enum
}
}
return 0
}