Add version module and update player colours
This commit is contained in:
parent
98dad4d273
commit
0ba6d712d3
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"tea.melonie54.xyz/sean/go-susapp/src/version"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tea.melonie54.xyz/sean/go-susapp/src/enum"
|
"tea.melonie54.xyz/sean/go-susapp/src/enum"
|
||||||
@ -40,7 +41,7 @@ func (r *Renderer) Draw(da *gtk.DrawingArea, cr *cairo.Context) {
|
|||||||
r.w = float64(allocation.GetWidth())
|
r.w = float64(allocation.GetWidth())
|
||||||
r.h = float64(allocation.GetHeight())
|
r.h = float64(allocation.GetHeight())
|
||||||
|
|
||||||
versionText := GetVersionFormatted(r.state.Version)
|
versionText := version.GetVersionFormatted(r.state.Version)
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
r.DrawFilledRectangle(0, 0, r.w, r.h, 0x14181c)
|
r.DrawFilledRectangle(0, 0, r.w, r.h, 0x14181c)
|
||||||
|
@ -12,34 +12,34 @@ var playerColorNames = []string{
|
|||||||
"Purple",
|
"Purple",
|
||||||
"Brown",
|
"Brown",
|
||||||
"Cyan",
|
"Cyan",
|
||||||
"Light Green",
|
"Lime",
|
||||||
"Maroon",
|
"Maroon",
|
||||||
"Rose",
|
"Rose",
|
||||||
"Banana",
|
"Banana",
|
||||||
"Gray",
|
"Gray",
|
||||||
"Tan",
|
"Tan",
|
||||||
"Sunset",
|
"Coral",
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerColors = []int{
|
var playerColors = []int{
|
||||||
rgb(215, 30, 34),
|
rgb(198, 17, 17),
|
||||||
rgb(29, 60, 233),
|
rgb(19, 46, 210),
|
||||||
rgb(27, 145, 62),
|
rgb(17, 128, 45),
|
||||||
rgb(255, 99, 212),
|
rgb(238, 84, 187),
|
||||||
rgb(255, 141, 28),
|
rgb(240, 125, 13),
|
||||||
rgb(246, 246, 87),
|
rgb(246, 246, 87),
|
||||||
rgb(74, 86, 94),
|
rgb(63, 71, 78),
|
||||||
rgb(233, 247, 255),
|
rgb(215, 225, 241),
|
||||||
rgb(120, 61, 210),
|
rgb(107, 47, 188),
|
||||||
rgb(128, 88, 45),
|
rgb(113, 73, 30),
|
||||||
rgb(68, 255, 247),
|
rgb(56, 255, 221),
|
||||||
rgb(91, 255, 75),
|
rgb(80, 240, 57),
|
||||||
rgb(108, 43, 61),
|
6233390,
|
||||||
rgb(255, 214, 236),
|
15515859,
|
||||||
rgb(255, 255, 190),
|
15787944,
|
||||||
rgb(131, 151, 167),
|
7701907,
|
||||||
rgb(159, 153, 137),
|
9537655,
|
||||||
rgb(236, 117, 120),
|
14115940,
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerShadedColors = []int{
|
var playerShadedColors = []int{
|
||||||
@ -48,19 +48,19 @@ var playerShadedColors = []int{
|
|||||||
rgb(10, 77, 46),
|
rgb(10, 77, 46),
|
||||||
rgb(172, 43, 174),
|
rgb(172, 43, 174),
|
||||||
rgb(180, 62, 21),
|
rgb(180, 62, 21),
|
||||||
rgb(255, 255, 103),
|
rgb(195, 136, 34),
|
||||||
rgb(30, 31, 38),
|
rgb(30, 31, 38),
|
||||||
rgb(132, 149, 192),
|
rgb(132, 149, 192),
|
||||||
rgb(59, 23, 124),
|
rgb(59, 23, 124),
|
||||||
rgb(94, 38, 21),
|
rgb(94, 38, 21),
|
||||||
rgb(36, 169, 191),
|
rgb(36, 169, 191),
|
||||||
rgb(21, 168, 66),
|
rgb(21, 168, 66),
|
||||||
rgb(65, 15, 26),
|
4263706,
|
||||||
rgb(222, 146, 179),
|
14586547,
|
||||||
rgb(210, 188, 137),
|
13810825,
|
||||||
rgb(70, 86, 100),
|
4609636,
|
||||||
rgb(81, 65, 62),
|
5325118,
|
||||||
rgb(180, 67, 98),
|
11813730,
|
||||||
}
|
}
|
||||||
|
|
||||||
func rgb(r int, g int, b int) int {
|
func rgb(r int, g int, b int) int {
|
||||||
|
@ -2,5 +2,12 @@ module tea.melonie54.xyz/sean/go-susapp/src/protocol
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
replace tea.melonie54.xyz/sean/go-susapp/src/util => ../util
|
replace (
|
||||||
require tea.melonie54.xyz/sean/go-susapp/src/util v0.0.0
|
tea.melonie54.xyz/sean/go-susapp/src/util => ../util
|
||||||
|
tea.melonie54.xyz/sean/go-susapp/src/version => ../version
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
tea.melonie54.xyz/sean/go-susapp/src/util v0.0.0
|
||||||
|
tea.melonie54.xyz/sean/go-susapp/src/version v0.0.0
|
||||||
|
)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
"tea.melonie54.xyz/sean/go-susapp/src/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -118,15 +119,19 @@ func (ph *PacketHandler) SendReliablePacket(nonce uint16, h []*Hazel) {
|
|||||||
ph.SendPacket(p)
|
ph.SendPacket(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ph *PacketHandler) SendHelloPacket(nonce uint16, hazelVersion byte, clientVersion int32, username string, authNonce uint32, keyword uint32, quickChatMode byte) {
|
func (ph *PacketHandler) SendHelloPacket(nonce uint16, hazelVersion byte, clientVersion *version.GameVersion, username string, authNonce uint32, keyword uint32, quickChatMode byte) {
|
||||||
p := ph.NewPacketFromType(0x08)
|
p := ph.NewPacketFromType(0x08)
|
||||||
p.WriteUInt16BigEndian(nonce)
|
p.WriteUInt16BigEndian(nonce)
|
||||||
p.Write(hazelVersion)
|
p.Write(hazelVersion)
|
||||||
p.WriteInt32(clientVersion)
|
p.WriteInt32(int32(clientVersion.GetVersion()))
|
||||||
p.WriteString(username)
|
p.WriteString(username)
|
||||||
p.WriteUInt32(authNonce)
|
p.WriteUInt32(authNonce)
|
||||||
p.WriteUInt32(keyword)
|
p.WriteUInt32(keyword)
|
||||||
p.Write(quickChatMode)
|
p.Write(quickChatMode)
|
||||||
|
h := NewHazelFromRawData(0x02, []byte{0x08, 0x54, 0x45, 0x53, 0x54, 0x4e, 0x41, 0x4d, 0x45})
|
||||||
|
p.WriteHazel(h)
|
||||||
|
p.WriteUInt32(0)
|
||||||
|
p.Write(0x00)
|
||||||
ph.SendPacket(p)
|
ph.SendPacket(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
src/version/go.mod
Normal file
3
src/version/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module tea.melonie54.xyz/sean/go-susapp/src/version
|
||||||
|
|
||||||
|
go 1.17
|
38
src/version/version.go
Normal file
38
src/version/version.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type GameVersion struct {
|
||||||
|
year int
|
||||||
|
month int
|
||||||
|
day int
|
||||||
|
revision int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGameVersion(year int, month int, day int, revision int) *GameVersion {
|
||||||
|
return &GameVersion{
|
||||||
|
year: year,
|
||||||
|
month: month,
|
||||||
|
day: day,
|
||||||
|
revision: revision,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseVersion(version int) *GameVersion {
|
||||||
|
gv := &GameVersion{}
|
||||||
|
gv.year = version / 25000
|
||||||
|
version %= 25000
|
||||||
|
gv.month = version / 1800
|
||||||
|
version %= 1800
|
||||||
|
gv.day = version / 50
|
||||||
|
gv.revision = version % 50
|
||||||
|
return gv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *GameVersion) GetVersion() int {
|
||||||
|
return (v.year * 25000) + (v.month * 1800) + (v.day)*50 + v.revision
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *GameVersion) Formatted() string {
|
||||||
|
return fmt.Sprintf("v%v.%v.%v", v.year, v.month, v.month)
|
||||||
|
}
|
5
state.go
5
state.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"tea.melonie54.xyz/sean/go-susapp/src/version"
|
||||||
|
|
||||||
"tea.melonie54.xyz/sean/go-susapp/src/collision"
|
"tea.melonie54.xyz/sean/go-susapp/src/collision"
|
||||||
"tea.melonie54.xyz/sean/go-susapp/src/enum"
|
"tea.melonie54.xyz/sean/go-susapp/src/enum"
|
||||||
@ -12,7 +13,7 @@ import (
|
|||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
Screen int
|
Screen int
|
||||||
Version int32
|
Version *version.GameVersion
|
||||||
PosX float32
|
PosX float32
|
||||||
PosY float32
|
PosY float32
|
||||||
Settings *SettingsJSON
|
Settings *SettingsJSON
|
||||||
@ -76,7 +77,7 @@ type PlayerObject struct {
|
|||||||
|
|
||||||
var settingsFilename string = "SusSettings.json"
|
var settingsFilename string = "SusSettings.json"
|
||||||
|
|
||||||
func CreateAppState(version int32) *State {
|
func CreateAppState(version *version.GameVersion) *State {
|
||||||
forceSave := false
|
forceSave := false
|
||||||
settings, err := readSettingsJson(settingsFilename)
|
settings, err := readSettingsJson(settingsFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
5
sus.go
5
sus.go
@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"tea.melonie54.xyz/sean/go-susapp/src/version"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gotk3/gotk3/cairo"
|
"github.com/gotk3/gotk3/cairo"
|
||||||
@ -65,7 +66,7 @@ func (sus *SusApp) startApp() {
|
|||||||
movementTickerDone <- true
|
movementTickerDone <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
sus.state = CreateAppState(GenerateVersionNumber(2021, 6, 30, 0))
|
sus.state = CreateAppState(version.NewGameVersion(2021, 12, 14, 0))
|
||||||
if sus.state == nil {
|
if sus.state == nil {
|
||||||
fmt.Println("Error loading new app state")
|
fmt.Println("Error loading new app state")
|
||||||
return
|
return
|
||||||
@ -76,7 +77,7 @@ func (sus *SusApp) startApp() {
|
|||||||
sus.packetProcessor = NewPacketProcessor(sus)
|
sus.packetProcessor = NewPacketProcessor(sus)
|
||||||
sus.movementProcessor = &MovementProcessor{sus: sus}
|
sus.movementProcessor = &MovementProcessor{sus: sus}
|
||||||
|
|
||||||
fmt.Printf("Starting Sus App %s\n", GetVersionFormatted(sus.state.Version))
|
fmt.Printf("Starting Sus App %s\n", sus.state.Version.Formatted())
|
||||||
|
|
||||||
sus.application.Connect("activate", func() {
|
sus.application.Connect("activate", func() {
|
||||||
w := 800
|
w := 800
|
||||||
|
27
version.go
27
version.go
@ -1,27 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func GenerateVersionNumber(year int, month int, day int, revision int) int32 {
|
|
||||||
return int32(year*25000 + month*1800 + day*50 + revision)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetVersionYear(version int32) int {
|
|
||||||
return int(version / 25000)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetVersionMonth(version int32) int {
|
|
||||||
return int((version % 25000) / 1800)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetVersionDay(version int32) int {
|
|
||||||
return int((version % 25000 % 1800) / 50)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetVersionRevision(version int32) int {
|
|
||||||
return int((version % 50))
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetVersionFormatted(v int32) string {
|
|
||||||
return fmt.Sprintf("v%v.%v.%v", GetVersionYear(v), GetVersionMonth(v), GetVersionDay(v))
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user