mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-05 19:14:14 -04:00
common: use stringer and string2enum tools to convert back and forth between enum and string (#107)
This commit is contained in:
parent
3555578c0e
commit
b0ca8138bd
205
common/Cof.go
205
common/Cof.go
@ -2,102 +2,62 @@ package common
|
|||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
|
// Tools used for go:generate.
|
||||||
|
//
|
||||||
|
// go get golang.org/x/tools/cmd/stringer
|
||||||
|
// go get github.com/mewspring/tools/cmd/string2enum
|
||||||
|
|
||||||
|
//go:generate stringer -linecomment -type AnimationMode
|
||||||
|
|
||||||
type AnimationMode int
|
type AnimationMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AnimationModePlayerDeath AnimationMode = 0
|
AnimationModePlayerDeath AnimationMode = 0 // DT
|
||||||
AnimationModePlayerNeutral AnimationMode = 1
|
AnimationModePlayerNeutral AnimationMode = 1 // NU
|
||||||
AnimationModePlayerWalk AnimationMode = 2
|
AnimationModePlayerWalk AnimationMode = 2 // WL
|
||||||
AnimationModePlayerRun AnimationMode = 3
|
AnimationModePlayerRun AnimationMode = 3 // RN
|
||||||
AnimationModePlayerGetHit AnimationMode = 4
|
AnimationModePlayerGetHit AnimationMode = 4 // GH
|
||||||
AnimationModePlayerTownNeutral AnimationMode = 5
|
AnimationModePlayerTownNeutral AnimationMode = 5 // TN
|
||||||
AnimationModePlayerTownWalk AnimationMode = 6
|
AnimationModePlayerTownWalk AnimationMode = 6 // TW
|
||||||
AnimationModePlayerAttack1 AnimationMode = 7
|
AnimationModePlayerAttack1 AnimationMode = 7 // A1
|
||||||
AnimationModePlayerAttack2 AnimationMode = 8
|
AnimationModePlayerAttack2 AnimationMode = 8 // A2
|
||||||
AnimationModePlayerBlock AnimationMode = 9
|
AnimationModePlayerBlock AnimationMode = 9 // BL
|
||||||
AnimationModePlayerCast AnimationMode = 10
|
AnimationModePlayerCast AnimationMode = 10 // SC
|
||||||
AnimationModePlayerThrow AnimationMode = 11
|
AnimationModePlayerThrow AnimationMode = 11 // TH
|
||||||
AnimationModePlayerKick AnimationMode = 12
|
AnimationModePlayerKick AnimationMode = 12 // KK
|
||||||
AnimationModePlayerSkill1 AnimationMode = 13
|
AnimationModePlayerSkill1 AnimationMode = 13 // S1
|
||||||
AnimationModePlayerSkill2 AnimationMode = 14
|
AnimationModePlayerSkill2 AnimationMode = 14 // S2
|
||||||
AnimationModePlayerSkill3 AnimationMode = 15
|
AnimationModePlayerSkill3 AnimationMode = 15 // S3
|
||||||
AnimationModePlayerSkill4 AnimationMode = 16
|
AnimationModePlayerSkill4 AnimationMode = 16 // S4
|
||||||
AnimationModePlayerDead AnimationMode = 17
|
AnimationModePlayerDead AnimationMode = 17 // DD
|
||||||
AnimationModePlayerSequence AnimationMode = 18
|
AnimationModePlayerSequence AnimationMode = 18 // GH
|
||||||
AnimationModePlayerKnockBack AnimationMode = 19
|
AnimationModePlayerKnockBack AnimationMode = 19 // GH
|
||||||
AnimationModeMonsterDeath AnimationMode = 20
|
AnimationModeMonsterDeath AnimationMode = 20 // DT
|
||||||
AnimationModeMonsterNeutral AnimationMode = 21
|
AnimationModeMonsterNeutral AnimationMode = 21 // NU
|
||||||
AnimationModeMonsterWalk AnimationMode = 22
|
AnimationModeMonsterWalk AnimationMode = 22 // WL
|
||||||
AnimationModeMonsterGetHit AnimationMode = 23
|
AnimationModeMonsterGetHit AnimationMode = 23 // GH
|
||||||
AnimationModeMonsterAttack1 AnimationMode = 24
|
AnimationModeMonsterAttack1 AnimationMode = 24 // A1
|
||||||
AnimationModeMonsterAttack2 AnimationMode = 25
|
AnimationModeMonsterAttack2 AnimationMode = 25 // A2
|
||||||
AnimationModeMonsterBlock AnimationMode = 26
|
AnimationModeMonsterBlock AnimationMode = 26 // BL
|
||||||
AnimationModeMonsterCast AnimationMode = 27
|
AnimationModeMonsterCast AnimationMode = 27 // SC
|
||||||
AnimationModeMonsterSkill1 AnimationMode = 28
|
AnimationModeMonsterSkill1 AnimationMode = 28 // S1
|
||||||
AnimationModeMonsterSkill2 AnimationMode = 29
|
AnimationModeMonsterSkill2 AnimationMode = 29 // S2
|
||||||
AnimationModeMonsterSkill3 AnimationMode = 30
|
AnimationModeMonsterSkill3 AnimationMode = 30 // S3
|
||||||
AnimationModeMonsterSkill4 AnimationMode = 31
|
AnimationModeMonsterSkill4 AnimationMode = 31 // S4
|
||||||
AnimationModeMonsterDead AnimationMode = 32
|
AnimationModeMonsterDead AnimationMode = 32 // DD
|
||||||
AnimationModeMonsterKnockback AnimationMode = 33
|
AnimationModeMonsterKnockback AnimationMode = 33 // GH
|
||||||
AnimationModeMonsterSequence AnimationMode = 34
|
AnimationModeMonsterSequence AnimationMode = 34 // xx
|
||||||
AnimationModeMonsterRun AnimationMode = 35
|
AnimationModeMonsterRun AnimationMode = 35 // RN
|
||||||
AnimationModeObjectNeutral AnimationMode = 36
|
AnimationModeObjectNeutral AnimationMode = 36 // NU
|
||||||
AnimationModeObjectOperating AnimationMode = 37
|
AnimationModeObjectOperating AnimationMode = 37 // OP
|
||||||
AnimationModeObjectOpened AnimationMode = 38
|
AnimationModeObjectOpened AnimationMode = 38 // ON
|
||||||
AnimationModeObjectSpecial1 AnimationMode = 39
|
AnimationModeObjectSpecial1 AnimationMode = 39 // S1
|
||||||
AnimationModeObjectSpecial2 AnimationMode = 40
|
AnimationModeObjectSpecial2 AnimationMode = 40 // S2
|
||||||
AnimationModeObjectSpecial3 AnimationMode = 41
|
AnimationModeObjectSpecial3 AnimationMode = 41 // S3
|
||||||
AnimationModeObjectSpecial4 AnimationMode = 42
|
AnimationModeObjectSpecial4 AnimationMode = 42 // S4
|
||||||
AnimationModeObjectSpecial5 AnimationMode = 43
|
AnimationModeObjectSpecial5 AnimationMode = 43 // S5
|
||||||
)
|
)
|
||||||
|
|
||||||
var AnimationModeStr = map[AnimationMode]string{
|
|
||||||
AnimationModePlayerDeath: "DT",
|
|
||||||
AnimationModePlayerNeutral: "NU",
|
|
||||||
AnimationModePlayerWalk: "WL",
|
|
||||||
AnimationModePlayerRun: "RN",
|
|
||||||
AnimationModePlayerGetHit: "GH",
|
|
||||||
AnimationModePlayerTownNeutral: "TN",
|
|
||||||
AnimationModePlayerTownWalk: "TW",
|
|
||||||
AnimationModePlayerAttack1: "A1",
|
|
||||||
AnimationModePlayerAttack2: "A2",
|
|
||||||
AnimationModePlayerBlock: "BL",
|
|
||||||
AnimationModePlayerCast: "SC",
|
|
||||||
AnimationModePlayerThrow: "TH",
|
|
||||||
AnimationModePlayerKick: "KK",
|
|
||||||
AnimationModePlayerSkill1: "S1",
|
|
||||||
AnimationModePlayerSkill2: "S2",
|
|
||||||
AnimationModePlayerSkill3: "S3",
|
|
||||||
AnimationModePlayerSkill4: "S4",
|
|
||||||
AnimationModePlayerDead: "DD",
|
|
||||||
AnimationModePlayerSequence: "GH",
|
|
||||||
AnimationModePlayerKnockBack: "GH",
|
|
||||||
AnimationModeMonsterDeath: "DT",
|
|
||||||
AnimationModeMonsterNeutral: "NU",
|
|
||||||
AnimationModeMonsterWalk: "WL",
|
|
||||||
AnimationModeMonsterGetHit: "GH",
|
|
||||||
AnimationModeMonsterAttack1: "A1",
|
|
||||||
AnimationModeMonsterAttack2: "A2",
|
|
||||||
AnimationModeMonsterBlock: "BL",
|
|
||||||
AnimationModeMonsterCast: "SC",
|
|
||||||
AnimationModeMonsterSkill1: "S1",
|
|
||||||
AnimationModeMonsterSkill2: "S2",
|
|
||||||
AnimationModeMonsterSkill3: "S3",
|
|
||||||
AnimationModeMonsterSkill4: "S4",
|
|
||||||
AnimationModeMonsterDead: "DD",
|
|
||||||
AnimationModeMonsterKnockback: "GH",
|
|
||||||
AnimationModeMonsterSequence: "xx",
|
|
||||||
AnimationModeMonsterRun: "RN",
|
|
||||||
AnimationModeObjectNeutral: "NU",
|
|
||||||
AnimationModeObjectOperating: "OP",
|
|
||||||
AnimationModeObjectOpened: "ON",
|
|
||||||
AnimationModeObjectSpecial1: "S1",
|
|
||||||
AnimationModeObjectSpecial2: "S2",
|
|
||||||
AnimationModeObjectSpecial3: "S3",
|
|
||||||
AnimationModeObjectSpecial4: "S4",
|
|
||||||
AnimationModeObjectSpecial5: "S5",
|
|
||||||
}
|
|
||||||
|
|
||||||
type CompositeType int
|
type CompositeType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -131,54 +91,29 @@ const (
|
|||||||
DrawEffectBringAlphaBlending = 5 //bright alpha blending (colormaps 1457-1712 in a .pl2)
|
DrawEffectBringAlphaBlending = 5 //bright alpha blending (colormaps 1457-1712 in a .pl2)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:generate stringer -linecomment -type WeaponClass
|
||||||
|
//go:generate string2enum -samepkg -linecomment -type WeaponClass
|
||||||
|
|
||||||
type WeaponClass int
|
type WeaponClass int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WeaponClassNone WeaponClass = 0
|
WeaponClassNone WeaponClass = 0 //
|
||||||
WeaponClassHandToHand WeaponClass = 1
|
WeaponClassHandToHand WeaponClass = 1 // hth
|
||||||
WeaponClassBow WeaponClass = 2
|
WeaponClassBow WeaponClass = 2 // bow
|
||||||
WeaponClassOneHandSwing WeaponClass = 3
|
WeaponClassOneHandSwing WeaponClass = 3 // 1hs
|
||||||
WeaponClassOneHandThrust WeaponClass = 4
|
WeaponClassOneHandThrust WeaponClass = 4 // 1ht
|
||||||
WeaponClassStaff WeaponClass = 5
|
WeaponClassStaff WeaponClass = 5 // stf
|
||||||
WeaponClassTwoHandSwing WeaponClass = 6
|
WeaponClassTwoHandSwing WeaponClass = 6 // 2hs
|
||||||
WeaponClassTwoHandThrust WeaponClass = 7
|
WeaponClassTwoHandThrust WeaponClass = 7 // 2ht
|
||||||
WeaponClassCrossbow WeaponClass = 8
|
WeaponClassCrossbow WeaponClass = 8 // xbw
|
||||||
WeaponClassLeftJabRightSwing WeaponClass = 9
|
WeaponClassLeftJabRightSwing WeaponClass = 9 // 1js
|
||||||
WeaponClassLeftJabRightThrust WeaponClass = 10
|
WeaponClassLeftJabRightThrust WeaponClass = 10 // 1jt
|
||||||
WeaponClassLeftSwingRightSwing WeaponClass = 11
|
WeaponClassLeftSwingRightSwing WeaponClass = 11 // 1ss
|
||||||
WeaponClassLeftSwingRightThrust WeaponClass = 12
|
WeaponClassLeftSwingRightThrust WeaponClass = 12 // 1st
|
||||||
WeaponClassOneHandToHand WeaponClass = 13
|
WeaponClassOneHandToHand WeaponClass = 13 // ht1
|
||||||
WeaponClassTwoHandToHand WeaponClass = 14
|
WeaponClassTwoHandToHand WeaponClass = 14 // ht2
|
||||||
)
|
)
|
||||||
|
|
||||||
var WeaponClassStr = map[WeaponClass]string{
|
|
||||||
WeaponClassNone: "",
|
|
||||||
WeaponClassHandToHand: "hth",
|
|
||||||
WeaponClassBow: "bow",
|
|
||||||
WeaponClassOneHandSwing: "1hs",
|
|
||||||
WeaponClassOneHandThrust: "1ht",
|
|
||||||
WeaponClassStaff: "stf",
|
|
||||||
WeaponClassTwoHandSwing: "2hs",
|
|
||||||
WeaponClassTwoHandThrust: "2ht",
|
|
||||||
WeaponClassCrossbow: "xbw",
|
|
||||||
WeaponClassLeftJabRightSwing: "1js",
|
|
||||||
WeaponClassLeftJabRightThrust: "1jt",
|
|
||||||
WeaponClassLeftSwingRightSwing: "1ss",
|
|
||||||
WeaponClassLeftSwingRightThrust: "1st",
|
|
||||||
WeaponClassOneHandToHand: "ht1",
|
|
||||||
WeaponClassTwoHandToHand: "ht2",
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetWeaponClass(val string) WeaponClass {
|
|
||||||
for weaponClass, weaponStr := range WeaponClassStr {
|
|
||||||
if val != weaponStr {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return weaponClass
|
|
||||||
}
|
|
||||||
return WeaponClassNone
|
|
||||||
}
|
|
||||||
|
|
||||||
type AnimationFrame int
|
type AnimationFrame int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -225,7 +160,7 @@ func LoadCof(fileName string, fileProvider FileProvider) *Cof {
|
|||||||
layer.Transparent = streamReader.GetByte() != 0
|
layer.Transparent = streamReader.GetByte() != 0
|
||||||
layer.DrawEffect = DrawEffect(streamReader.GetByte())
|
layer.DrawEffect = DrawEffect(streamReader.GetByte())
|
||||||
weaponClassStr, _ := streamReader.ReadBytes(4)
|
weaponClassStr, _ := streamReader.ReadBytes(4)
|
||||||
layer.WeaponClass = GetWeaponClass(strings.TrimSpace(strings.ReplaceAll(string(weaponClassStr), string(0), "")))
|
layer.WeaponClass = WeaponClassFromString(strings.TrimSpace(strings.ReplaceAll(string(weaponClassStr), string(0), "")))
|
||||||
result.CofLayers = append(result.CofLayers, layer)
|
result.CofLayers = append(result.CofLayers, layer)
|
||||||
result.CompositeLayers[layer.Type] = i
|
result.CompositeLayers[layer.Type] = i
|
||||||
}
|
}
|
||||||
|
66
common/animationmode_string.go
Normal file
66
common/animationmode_string.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// Code generated by "stringer -linecomment -type AnimationMode"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package common
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[AnimationModePlayerDeath-0]
|
||||||
|
_ = x[AnimationModePlayerNeutral-1]
|
||||||
|
_ = x[AnimationModePlayerWalk-2]
|
||||||
|
_ = x[AnimationModePlayerRun-3]
|
||||||
|
_ = x[AnimationModePlayerGetHit-4]
|
||||||
|
_ = x[AnimationModePlayerTownNeutral-5]
|
||||||
|
_ = x[AnimationModePlayerTownWalk-6]
|
||||||
|
_ = x[AnimationModePlayerAttack1-7]
|
||||||
|
_ = x[AnimationModePlayerAttack2-8]
|
||||||
|
_ = x[AnimationModePlayerBlock-9]
|
||||||
|
_ = x[AnimationModePlayerCast-10]
|
||||||
|
_ = x[AnimationModePlayerThrow-11]
|
||||||
|
_ = x[AnimationModePlayerKick-12]
|
||||||
|
_ = x[AnimationModePlayerSkill1-13]
|
||||||
|
_ = x[AnimationModePlayerSkill2-14]
|
||||||
|
_ = x[AnimationModePlayerSkill3-15]
|
||||||
|
_ = x[AnimationModePlayerSkill4-16]
|
||||||
|
_ = x[AnimationModePlayerDead-17]
|
||||||
|
_ = x[AnimationModePlayerSequence-18]
|
||||||
|
_ = x[AnimationModePlayerKnockBack-19]
|
||||||
|
_ = x[AnimationModeMonsterDeath-20]
|
||||||
|
_ = x[AnimationModeMonsterNeutral-21]
|
||||||
|
_ = x[AnimationModeMonsterWalk-22]
|
||||||
|
_ = x[AnimationModeMonsterGetHit-23]
|
||||||
|
_ = x[AnimationModeMonsterAttack1-24]
|
||||||
|
_ = x[AnimationModeMonsterAttack2-25]
|
||||||
|
_ = x[AnimationModeMonsterBlock-26]
|
||||||
|
_ = x[AnimationModeMonsterCast-27]
|
||||||
|
_ = x[AnimationModeMonsterSkill1-28]
|
||||||
|
_ = x[AnimationModeMonsterSkill2-29]
|
||||||
|
_ = x[AnimationModeMonsterSkill3-30]
|
||||||
|
_ = x[AnimationModeMonsterSkill4-31]
|
||||||
|
_ = x[AnimationModeMonsterDead-32]
|
||||||
|
_ = x[AnimationModeMonsterKnockback-33]
|
||||||
|
_ = x[AnimationModeMonsterSequence-34]
|
||||||
|
_ = x[AnimationModeMonsterRun-35]
|
||||||
|
_ = x[AnimationModeObjectNeutral-36]
|
||||||
|
_ = x[AnimationModeObjectOperating-37]
|
||||||
|
_ = x[AnimationModeObjectOpened-38]
|
||||||
|
_ = x[AnimationModeObjectSpecial1-39]
|
||||||
|
_ = x[AnimationModeObjectSpecial2-40]
|
||||||
|
_ = x[AnimationModeObjectSpecial3-41]
|
||||||
|
_ = x[AnimationModeObjectSpecial4-42]
|
||||||
|
_ = x[AnimationModeObjectSpecial5-43]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _AnimationMode_name = "DTNUWLRNGHTNTWA1A2BLSCTHKKS1S2S3S4DDGHGHDTNUWLGHA1A2BLSCS1S2S3S4DDGHxxRNNUOPONS1S2S3S4S5"
|
||||||
|
|
||||||
|
var _AnimationMode_index = [...]uint8{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88}
|
||||||
|
|
||||||
|
func (i AnimationMode) String() string {
|
||||||
|
if i < 0 || i >= AnimationMode(len(_AnimationMode_index)-1) {
|
||||||
|
return "AnimationMode(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _AnimationMode_name[_AnimationMode_index[i]:_AnimationMode_index[i+1]]
|
||||||
|
}
|
37
common/weaponclass_string.go
Normal file
37
common/weaponclass_string.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Code generated by "stringer -linecomment -type WeaponClass"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package common
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[WeaponClassNone-0]
|
||||||
|
_ = x[WeaponClassHandToHand-1]
|
||||||
|
_ = x[WeaponClassBow-2]
|
||||||
|
_ = x[WeaponClassOneHandSwing-3]
|
||||||
|
_ = x[WeaponClassOneHandThrust-4]
|
||||||
|
_ = x[WeaponClassStaff-5]
|
||||||
|
_ = x[WeaponClassTwoHandSwing-6]
|
||||||
|
_ = x[WeaponClassTwoHandThrust-7]
|
||||||
|
_ = x[WeaponClassCrossbow-8]
|
||||||
|
_ = x[WeaponClassLeftJabRightSwing-9]
|
||||||
|
_ = x[WeaponClassLeftJabRightThrust-10]
|
||||||
|
_ = x[WeaponClassLeftSwingRightSwing-11]
|
||||||
|
_ = x[WeaponClassLeftSwingRightThrust-12]
|
||||||
|
_ = x[WeaponClassOneHandToHand-13]
|
||||||
|
_ = x[WeaponClassTwoHandToHand-14]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _WeaponClass_name = "hthbow1hs1htstf2hs2htxbw1js1jt1ss1stht1ht2"
|
||||||
|
|
||||||
|
var _WeaponClass_index = [...]uint8{0, 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42}
|
||||||
|
|
||||||
|
func (i WeaponClass) String() string {
|
||||||
|
if i < 0 || i >= WeaponClass(len(_WeaponClass_index)-1) {
|
||||||
|
return "WeaponClass(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _WeaponClass_name[_WeaponClass_index[i]:_WeaponClass_index[i+1]]
|
||||||
|
}
|
18
common/weaponclass_string2enum.go
Normal file
18
common/weaponclass_string2enum.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Code generated by "string2enum -samepkg -linecomment -type WeaponClass"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package common
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// WeaponClassFromString returns the WeaponClass enum corresponding to s.
|
||||||
|
func WeaponClassFromString(s string) WeaponClass {
|
||||||
|
if len(s) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
for i := range _WeaponClass_index[:len(_WeaponClass_index)-1] {
|
||||||
|
if s == _WeaponClass_name[_WeaponClass_index[i]:_WeaponClass_index[i+1]] {
|
||||||
|
return WeaponClass(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic(fmt.Errorf("unable to locate WeaponClass enum corresponding to %q", s))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user