Skip to content

Commit

Permalink
Change config to match other config patterns and future setup for all…
Browse files Browse the repository at this point in the history
… round configs
  • Loading branch information
b-j-roberts committed Dec 16, 2024
1 parent 36cf487 commit a4a2273
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 159 deletions.
8 changes: 7 additions & 1 deletion backend/cmd/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func isFlagSet(name string) bool {
}

func main() {
roundsConfigFilename := flag.String("rounds-config", config.DefaultRoundsConfigPath, "Rounds config file")
canvasConfigFilename := flag.String("canvas-config", config.DefaultCanvasConfigPath, "Canvas config file")
databaseConfigFilename := flag.String("database-config", config.DefaultDatabaseConfigPath, "Database config file")
backendConfigFilename := flag.String("backend-config", config.DefaultBackendConfigPath, "Backend config file")
Expand All @@ -27,6 +28,11 @@ func main() {

flag.Parse()

roundsConfig, err := config.LoadRoundsConfig(*roundsConfigFilename)
if err != nil {
panic(err)
}

canvasConfig, err := config.LoadCanvasConfig(*canvasConfigFilename)
if err != nil {
panic(err)
Expand All @@ -49,7 +55,7 @@ func main() {
databases := core.NewDatabases(databaseConfig)
defer databases.Close()

core.ArtPeaceBackend = core.NewBackend(databases, canvasConfig, backendConfig, *admin)
core.ArtPeaceBackend = core.NewBackend(databases, roundsConfig, canvasConfig, backendConfig, *admin)

routes.InitRoutes()

Expand Down
8 changes: 7 additions & 1 deletion backend/cmd/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ func isFlagSet(name string) bool {
}

func main() {
roundsConfigFilename := flag.String("rounds-config", config.DefaultRoundsConfigPath, "Rounds config file")
canvasConfigFilename := flag.String("canvas-config", config.DefaultCanvasConfigPath, "Canvas config file")
databaseConfigFilename := flag.String("database-config", config.DefaultDatabaseConfigPath, "Database config file")
backendConfigFilename := flag.String("backend-config", config.DefaultBackendConfigPath, "Backend config file")
production := flag.Bool("production", false, "Production mode")

flag.Parse()

roundsConfig, err := config.LoadRoundsConfig(*roundsConfigFilename)
if err != nil {
panic(err)
}

canvasConfig, err := config.LoadCanvasConfig(*canvasConfigFilename)
if err != nil {
panic(err)
Expand All @@ -49,7 +55,7 @@ func main() {
databases := core.NewDatabases(databaseConfig)
defer databases.Close()

core.ArtPeaceBackend = core.NewBackend(databases, canvasConfig, backendConfig, false)
core.ArtPeaceBackend = core.NewBackend(databases, roundsConfig, canvasConfig, backendConfig, false)

routes.InitBaseRoutes()
indexer.InitIndexerRoutes()
Expand Down
8 changes: 7 additions & 1 deletion backend/cmd/video-gen/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import (
)

func main() {
roundsConfigFilename := flag.String("rounds-config", config.DefaultRoundsConfigPath, "Rounds config file")
canvasConfigFilename := flag.String("canvas-config", config.DefaultCanvasConfigPath, "Canvas config file")
databaseConfigFilename := flag.String("database-config", config.DefaultDatabaseConfigPath, "Database config file")
backendConfigFilename := flag.String("backend-config", config.DefaultBackendConfigPath, "Backend config file")

flag.Parse()

roundsConfig, err := config.LoadRoundsConfig(*roundsConfigFilename)
if err != nil {
panic(err)
}

canvasConfig, err := config.LoadCanvasConfig(*canvasConfigFilename)
if err != nil {
panic(err)
Expand All @@ -34,7 +40,7 @@ func main() {
databases := core.NewDatabases(databaseConfig)
defer databases.Close()

core.ArtPeaceBackend = core.NewBackend(databases, canvasConfig, backendConfig, true)
core.ArtPeaceBackend = core.NewBackend(databases, roundsConfig, canvasConfig, backendConfig, true)

routes.InitBaseRoutes()
routes.InitCanvasRoutes()
Expand Down
47 changes: 47 additions & 0 deletions backend/config/rounds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package config

import (
"encoding/json"
"os"
)

type Round3 struct {
Width uint `json:"width"`
Height uint `json:"height"`
Timer uint `json:"timer"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
}

type RoundsConfig struct {
Round3 Round3 `json:"round3"`
}

var DefaultRoundsConfig = &RoundsConfig{
Round3: Round3{
Width: 256,
Height: 192,
Timer: 5,
StartTime: "2024-12-01T00:00:00Z",
EndTime: "2025-01-01T00:00:00Z",
},
}

var DefaultRoundsConfigPath = "../configs/rounds.config.json"

func LoadRoundsConfig(roundsConfigPath string) (*RoundsConfig, error) {
roundsConfig := &RoundsConfig{}

roundsConfigFile, err := os.Open(roundsConfigPath)
if err != nil {
return nil, err
}
defer roundsConfigFile.Close()

jsonParser := json.NewDecoder(roundsConfigFile)
if err = jsonParser.Decode(roundsConfig); err != nil {
return nil, err
}

return roundsConfig, nil
}
4 changes: 3 additions & 1 deletion backend/core/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Backend struct {
WSConnections []*websocket.Conn
WSConnectionsLock sync.Mutex

RoundsConfig *config.RoundsConfig
CanvasConfig *config.CanvasConfig
BackendConfig *config.BackendConfig

Expand All @@ -23,9 +24,10 @@ type Backend struct {

var ArtPeaceBackend *Backend

func NewBackend(databases *Databases, canvasConfig *config.CanvasConfig, backendConfig *config.BackendConfig, adminMode bool) *Backend {
func NewBackend(databases *Databases, roundsConfig *config.RoundsConfig, canvasConfig *config.CanvasConfig, backendConfig *config.BackendConfig, adminMode bool) *Backend {
return &Backend{
Databases: databases,
RoundsConfig: roundsConfig,
CanvasConfig: canvasConfig,
BackendConfig: backendConfig,
AdminMode: adminMode,
Expand Down
52 changes: 0 additions & 52 deletions backend/routes/competition.go

This file was deleted.

31 changes: 31 additions & 0 deletions backend/routes/rounds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package routes

import (
"encoding/json"
"net/http"

"github.com/keep-starknet-strange/art-peace/backend/core"
routeutils "github.com/keep-starknet-strange/art-peace/backend/routes/utils"
)

func InitRoundsRoutes() {
http.HandleFunc("/get-rounds-config", getRoundsConfig)
}

func getRoundsConfig(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
routeutils.WriteErrorJson(w, http.StatusMethodNotAllowed, "Method not allowed")
return
}

config := core.ArtPeaceBackend.RoundsConfig

// Marshal the config to JSON
configJson, err := json.Marshal(config)
if err != nil {
routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Error marshalling config to JSON")
return
}

routeutils.WriteDataJson(w, string(configJson))
}
1 change: 1 addition & 0 deletions backend/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ func InitRoutes() {
InitWorldsRoutes()
InitStencilsRoutes()
InitStencilsStaticRoutes()
InitRoundsRoutes()
}
7 changes: 0 additions & 7 deletions configs/competition.config.json

This file was deleted.

9 changes: 9 additions & 0 deletions configs/rounds.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"round3": {
"width": 256,
"height": 192,
"timer": 5,
"startTime": "2024-12-06T00:00:00Z",
"endTime": "2025-01-01T00:00:00Z"
}
}
4 changes: 1 addition & 3 deletions frontend/src/tabs/worlds/WorldsCreationPanel.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.WorldsCreationPanel {
position: relative;
width: 530px;
width: 100%;
padding: 1rem 0.5rem 0.5rem 0.5rem;
margin-bottom: 0.3rem;

Expand All @@ -18,8 +18,6 @@
box-shadow: 0 0 1rem 0.1rem rgba(0, 0, 0, 0.3);
border: 0.2rem solid rgba(0, 0, 0, 0.4);

right: 100px;

pointer-events: fill;
}

Expand Down
Loading

0 comments on commit a4a2273

Please sign in to comment.