From 29034b091a467ed709d450656291741749e12555 Mon Sep 17 00:00:00 2001 From: ForkBench <robinvandemerghel@protonmail.com> Date: Wed, 10 Jul 2024 21:29:14 +0200 Subject: [PATCH] Updating type : adding pointers. --- astro/services/Competition.go | 37 ++++++++++++++--------------------- astro/services/Person.go | 24 +++++++++++++++++------ astro/services/Pool.go | 6 +++--- astro/services/Session.go | 27 +++++++++++++++++++++++++ frontend/src/Util.ts | 11 +++++++++++ 5 files changed, 74 insertions(+), 31 deletions(-) create mode 100644 frontend/src/Util.ts diff --git a/astro/services/Competition.go b/astro/services/Competition.go index 7f02d75..4c85011 100644 --- a/astro/services/Competition.go +++ b/astro/services/Competition.go @@ -14,7 +14,7 @@ type Competition struct { CompetitionPlayers []Player } -func (c Competition) String() string { +func (c *Competition) String() string { return "Competition : " + c.CompetitionName + " - " + c.CompetitionCategory.String() + " - " + c.CompetitionWeapon.String() + " - " + c.CompetitionState.String() } @@ -27,12 +27,13 @@ func CreateCompetition(competitionID uint8, competitionName string, competitionC c.CompetitionWeapon = competitionWeapon c.CompetitionState = REGISTERING c.CompetitionMaxStageNumber = competitionMaxStageNumber - c.CompetitionStages = make([]Stage, competitionMaxStageNumber) + c.CompetitionStages = []Stage{} + c.CompetitionPlayers = []Player{} return c } -func (c Competition) AddStage(stage Stage) bool { +func (c *Competition) AddStage(stage Stage) bool { if c.CompetitionState != IDLE { return false } @@ -46,7 +47,7 @@ func (c Competition) AddStage(stage Stage) bool { return true } -func (c Competition) StagePosition(stage Stage) uint16 { +func (c *Competition) StagePosition(stage Stage) uint16 { for i, competitionStage := range c.CompetitionStages { if competitionStage == stage { return uint16(i) @@ -56,7 +57,7 @@ func (c Competition) StagePosition(stage Stage) uint16 { return math.MaxInt16 } -func (c Competition) RemoveStage(stage Stage) bool { +func (c *Competition) RemoveStage(stage Stage) bool { if c.CompetitionState != IDLE { return false } @@ -70,7 +71,7 @@ func (c Competition) RemoveStage(stage Stage) bool { return true } -func (c Competition) StartCompetition() bool { +func (c *Competition) StartCompetition() bool { if c.CompetitionState != REGISTERING { return false } @@ -80,7 +81,7 @@ func (c Competition) StartCompetition() bool { return true } -func (c Competition) FinishCompetition() bool { +func (c *Competition) FinishCompetition() bool { if c.CompetitionState != STARTED { return false } @@ -92,7 +93,7 @@ func (c Competition) FinishCompetition() bool { return true } -func (c Competition) AddPlayer(player Player) bool { +func (c *Competition) AddPlayer(player Player) bool { if c.CompetitionState != REGISTERING { return false } @@ -102,7 +103,7 @@ func (c Competition) AddPlayer(player Player) bool { return true } -func (c Competition) PlayerPosition(player Player) uint16 { +func (c *Competition) PlayerPosition(player Player) uint16 { for i, competitionPlayer := range c.CompetitionPlayers { if competitionPlayer == player { return uint16(i) @@ -112,7 +113,7 @@ func (c Competition) PlayerPosition(player Player) uint16 { return math.MaxInt16 } -func (c Competition) RemovePlayer(player Player) bool { +func (c *Competition) RemovePlayer(player Player) bool { if c.CompetitionState != REGISTERING { return false } @@ -128,18 +129,10 @@ func (c Competition) RemovePlayer(player Player) bool { return true } -func (c Competition) AddPlayerToStage(player Player, stage Stage) bool { - if stage.AddPlayer(player) { - return true - } - - return false +func (c *Competition) AddPlayerToStage(player Player, stage Stage) bool { + return stage.AddPlayer(player) } -func (c Competition) RemovePlayerFromStage(player Player, stage Stage) bool { - if stage.RemovePlayer(player) { - return true - } - - return false +func (c *Competition) RemovePlayerFromStage(player Player, stage Stage) bool { + return stage.RemovePlayer(player) } diff --git a/astro/services/Person.go b/astro/services/Person.go index 65ccb7b..4161d08 100644 --- a/astro/services/Person.go +++ b/astro/services/Person.go @@ -2,18 +2,30 @@ package services // Player : Person details type Player struct { - PlayerID uint16 // More than 255 players - PlayerFirstname string - PlayerLastname string - PlayerNationID uint16 - PlayerRegionID uint16 - PlayerClubID uint16 + PlayerID uint16 // More than 255 players + PlayerFirstname string + PlayerLastname string + PlayerNationID uint16 + PlayerRegionID uint16 + PlayerClubID uint16 + PlayerInitialRank uint16 } func (p Player) String() string { return "Player : " + p.PlayerFirstname + " " + p.PlayerLastname } +func CreatePlayer(playerID uint16, playerFirstname string, playerLastname string) Player { + var p Player + + p.PlayerID = playerID + p.PlayerFirstname = playerFirstname + p.PlayerLastname = playerLastname + p.PlayerInitialRank = 10000 + + return p +} + // Referee : Person details type Referee struct { RefereeID uint16 // More than 255 referees diff --git a/astro/services/Pool.go b/astro/services/Pool.go index 793c69f..73eeaf0 100644 --- a/astro/services/Pool.go +++ b/astro/services/Pool.go @@ -44,7 +44,7 @@ func (p Pool) PlayerPosition(player Player) uint16 { return math.MaxInt16 } -func (p Pool) AddPlayer(player Player) bool { +func (p *Pool) AddPlayer(player Player) bool { if p.PoolState != IDLE { return false } @@ -61,7 +61,7 @@ func (p Pool) AddPlayer(player Player) bool { return false } -func (p Pool) RemovePlayer(player Player) bool { +func (p *Pool) RemovePlayer(player Player) bool { if p.PoolState != IDLE { return false } @@ -76,6 +76,6 @@ func (p Pool) RemovePlayer(player Player) bool { return false } -func (p Pool) SetReferee(referee Referee) { +func (p *Pool) SetReferee(referee Referee) { p.PoolReferee = referee } diff --git a/astro/services/Session.go b/astro/services/Session.go index 92e3516..2d6fae9 100644 --- a/astro/services/Session.go +++ b/astro/services/Session.go @@ -32,3 +32,30 @@ func (s *Session) RemoveCompetition(competitionID uint8) { func (s *Session) GetCompetitions() []Competition { return s.Competitions } + +func (s *Session) GetCompetition(competitionID uint8) Competition { + for _, competition := range s.Competitions { + if competition.CompetitionID == competitionID { + return competition + } + } + return Competition{} +} + +func (s *Session) AddPlayerToCompetition(competitionID uint8, player Player) bool { + competition := s.GetCompetition(competitionID) + if competition.CompetitionName == "" { + return false + } + + return competition.AddPlayer(player) +} + +func (s *Session) RemovePlayerFromCompetition(competitionID uint8, player Player) bool { + competition := s.GetCompetition(competitionID) + if competition.CompetitionName == "" { + return false + } + + return competition.RemovePlayer(player) +} diff --git a/frontend/src/Util.ts b/frontend/src/Util.ts new file mode 100644 index 0000000..d5b2bce --- /dev/null +++ b/frontend/src/Util.ts @@ -0,0 +1,11 @@ +export function randomColor(brightness: number): string { + function randomChannel(brightness: number): string { + var r = 255-brightness; + var n = 0|((Math.random() * r) + brightness); + var s = n.toString(16); + return (s.length==1) ? '0'+s : s; + } + return '#' + randomChannel(brightness) + randomChannel(brightness) + randomChannel(brightness); +} + +export const rightBrighness = 240; \ No newline at end of file -- GitLab