-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from supreme2580/join-round
Join round
- Loading branch information
Showing
9 changed files
with
367 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,5 @@ func InitRoutes() { | |
InitWorldsRoutes() | ||
InitStencilsRoutes() | ||
InitStencilsStaticRoutes() | ||
InitRoundsRoutes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.