Add version module and update player colours

This commit is contained in:
Melon 2021-12-17 15:03:21 +00:00
parent 98dad4d273
commit 0ba6d712d3
Signed by: melon
GPG Key ID: B0ADD5395BCDAAB6
9 changed files with 91 additions and 62 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"math"
"strconv"
"tea.melonie54.xyz/sean/go-susapp/src/version"
"time"
"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.h = float64(allocation.GetHeight())
versionText := GetVersionFormatted(r.state.Version)
versionText := version.GetVersionFormatted(r.state.Version)
// Background
r.DrawFilledRectangle(0, 0, r.w, r.h, 0x14181c)

View File

@ -12,34 +12,34 @@ var playerColorNames = []string{
"Purple",
"Brown",
"Cyan",
"Light Green",
"Lime",
"Maroon",
"Rose",
"Banana",
"Gray",
"Tan",
"Sunset",
"Coral",
}
var playerColors = []int{
rgb(215, 30, 34),
rgb(29, 60, 233),
rgb(27, 145, 62),
rgb(255, 99, 212),
rgb(255, 141, 28),
rgb(198, 17, 17),
rgb(19, 46, 210),
rgb(17, 128, 45),
rgb(238, 84, 187),
rgb(240, 125, 13),
rgb(246, 246, 87),
rgb(74, 86, 94),
rgb(233, 247, 255),
rgb(120, 61, 210),
rgb(128, 88, 45),
rgb(68, 255, 247),
rgb(91, 255, 75),
rgb(108, 43, 61),
rgb(255, 214, 236),
rgb(255, 255, 190),
rgb(131, 151, 167),
rgb(159, 153, 137),
rgb(236, 117, 120),
rgb(63, 71, 78),
rgb(215, 225, 241),
rgb(107, 47, 188),
rgb(113, 73, 30),
rgb(56, 255, 221),
rgb(80, 240, 57),
6233390,
15515859,
15787944,
7701907,
9537655,
14115940,
}
var playerShadedColors = []int{
@ -48,19 +48,19 @@ var playerShadedColors = []int{
rgb(10, 77, 46),
rgb(172, 43, 174),
rgb(180, 62, 21),
rgb(255, 255, 103),
rgb(195, 136, 34),
rgb(30, 31, 38),
rgb(132, 149, 192),
rgb(59, 23, 124),
rgb(94, 38, 21),
rgb(36, 169, 191),
rgb(21, 168, 66),
rgb(65, 15, 26),
rgb(222, 146, 179),
rgb(210, 188, 137),
rgb(70, 86, 100),
rgb(81, 65, 62),
rgb(180, 67, 98),
4263706,
14586547,
13810825,
4609636,
5325118,
11813730,
}
func rgb(r int, g int, b int) int {

View File

@ -2,5 +2,12 @@ module tea.melonie54.xyz/sean/go-susapp/src/protocol
go 1.17
replace tea.melonie54.xyz/sean/go-susapp/src/util => ../util
require tea.melonie54.xyz/sean/go-susapp/src/util v0.0.0
replace (
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
)

View File

@ -4,6 +4,7 @@ import (
"fmt"
"net"
"sync"
"tea.melonie54.xyz/sean/go-susapp/src/version"
)
const (
@ -118,15 +119,19 @@ func (ph *PacketHandler) SendReliablePacket(nonce uint16, h []*Hazel) {
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.WriteUInt16BigEndian(nonce)
p.Write(hazelVersion)
p.WriteInt32(clientVersion)
p.WriteInt32(int32(clientVersion.GetVersion()))
p.WriteString(username)
p.WriteUInt32(authNonce)
p.WriteUInt32(keyword)
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)
}

3
src/version/go.mod Normal file
View File

@ -0,0 +1,3 @@
module tea.melonie54.xyz/sean/go-susapp/src/version
go 1.17

38
src/version/version.go Normal file
View 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)
}

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"tea.melonie54.xyz/sean/go-susapp/src/version"
"tea.melonie54.xyz/sean/go-susapp/src/collision"
"tea.melonie54.xyz/sean/go-susapp/src/enum"
@ -12,7 +13,7 @@ import (
type State struct {
Screen int
Version int32
Version *version.GameVersion
PosX float32
PosY float32
Settings *SettingsJSON
@ -76,7 +77,7 @@ type PlayerObject struct {
var settingsFilename string = "SusSettings.json"
func CreateAppState(version int32) *State {
func CreateAppState(version *version.GameVersion) *State {
forceSave := false
settings, err := readSettingsJson(settingsFilename)
if err != nil {

5
sus.go
View File

@ -5,6 +5,7 @@ import (
"log"
"net"
"os"
"tea.melonie54.xyz/sean/go-susapp/src/version"
"time"
"github.com/gotk3/gotk3/cairo"
@ -65,7 +66,7 @@ func (sus *SusApp) startApp() {
movementTickerDone <- true
}()
sus.state = CreateAppState(GenerateVersionNumber(2021, 6, 30, 0))
sus.state = CreateAppState(version.NewGameVersion(2021, 12, 14, 0))
if sus.state == nil {
fmt.Println("Error loading new app state")
return
@ -76,7 +77,7 @@ func (sus *SusApp) startApp() {
sus.packetProcessor = NewPacketProcessor(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() {
w := 800

View File

@ -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))
}