initial commit
This commit is contained in:
commit
cb08c08246
2
README.md
Normal file
2
README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Play of the Game
|
||||
Host "fun" game show events with your friends!
|
4
backend/.gitignore
vendored
Normal file
4
backend/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*.beam
|
||||
*.ez
|
||||
/build
|
||||
erl_crash.dump
|
24
backend/README.md
Normal file
24
backend/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# backend
|
||||
|
||||
[](https://hex.pm/packages/backend)
|
||||
[](https://hexdocs.pm/backend/)
|
||||
|
||||
```sh
|
||||
gleam add backend@1
|
||||
```
|
||||
```gleam
|
||||
import backend
|
||||
|
||||
pub fn main() {
|
||||
// TODO: An example of the project in use
|
||||
}
|
||||
```
|
||||
|
||||
Further documentation can be found at <https://hexdocs.pm/backend>.
|
||||
|
||||
## Development
|
||||
|
||||
```sh
|
||||
gleam run # Run the project
|
||||
gleam test # Run the tests
|
||||
```
|
19
backend/gleam.toml
Normal file
19
backend/gleam.toml
Normal file
@ -0,0 +1,19 @@
|
||||
name = "backend"
|
||||
version = "1.0.0"
|
||||
|
||||
# Fill out these fields if you intend to generate HTML documentation or publish
|
||||
# your project to the Hex package manager.
|
||||
#
|
||||
# description = ""
|
||||
# licences = ["Apache-2.0"]
|
||||
# repository = { type = "github", user = "", repo = "" }
|
||||
# links = [{ title = "Website", href = "" }]
|
||||
#
|
||||
# For a full reference of all the available options, you can have a look at
|
||||
# https://gleam.run/writing-gleam/gleam-toml/.
|
||||
|
||||
[dependencies]
|
||||
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
gleeunit = ">= 1.0.0 and < 2.0.0"
|
5
backend/src/backend.gleam
Normal file
5
backend/src/backend.gleam
Normal file
@ -0,0 +1,5 @@
|
||||
import gleam/io
|
||||
|
||||
pub fn main() {
|
||||
io.println("Hello from backend!")
|
||||
}
|
12
backend/test/backend_test.gleam
Normal file
12
backend/test/backend_test.gleam
Normal file
@ -0,0 +1,12 @@
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
||||
pub fn main() {
|
||||
gleeunit.main()
|
||||
}
|
||||
|
||||
// gleeunit test functions end in `_test`
|
||||
pub fn hello_world_test() {
|
||||
1
|
||||
|> should.equal(1)
|
||||
}
|
4
game_client/.gitignore
vendored
Normal file
4
game_client/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*.beam
|
||||
*.ez
|
||||
/build
|
||||
erl_crash.dump
|
24
game_client/README.md
Normal file
24
game_client/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# game_client
|
||||
|
||||
[](https://hex.pm/packages/game_client)
|
||||
[](https://hexdocs.pm/game_client/)
|
||||
|
||||
```sh
|
||||
gleam add game_client@1
|
||||
```
|
||||
```gleam
|
||||
import game_client
|
||||
|
||||
pub fn main() {
|
||||
// TODO: An example of the project in use
|
||||
}
|
||||
```
|
||||
|
||||
Further documentation can be found at <https://hexdocs.pm/game_client>.
|
||||
|
||||
## Development
|
||||
|
||||
```sh
|
||||
gleam run # Run the project
|
||||
gleam test # Run the tests
|
||||
```
|
19
game_client/gleam.toml
Normal file
19
game_client/gleam.toml
Normal file
@ -0,0 +1,19 @@
|
||||
name = "game_client"
|
||||
version = "1.0.0"
|
||||
|
||||
# Fill out these fields if you intend to generate HTML documentation or publish
|
||||
# your project to the Hex package manager.
|
||||
#
|
||||
# description = ""
|
||||
# licences = ["Apache-2.0"]
|
||||
# repository = { type = "github", user = "", repo = "" }
|
||||
# links = [{ title = "Website", href = "" }]
|
||||
#
|
||||
# For a full reference of all the available options, you can have a look at
|
||||
# https://gleam.run/writing-gleam/gleam-toml/.
|
||||
|
||||
[dependencies]
|
||||
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
gleeunit = ">= 1.0.0 and < 2.0.0"
|
11
game_client/manifest.toml
Normal file
11
game_client/manifest.toml
Normal file
@ -0,0 +1,11 @@
|
||||
# This file was generated by Gleam
|
||||
# You typically do not need to edit this file
|
||||
|
||||
packages = [
|
||||
{ name = "gleam_stdlib", version = "0.59.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "F8FEE9B35797301994B81AF75508CF87C328FE1585558B0FFD188DC2B32EAA95" },
|
||||
{ name = "gleeunit", version = "1.3.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "A7DD6C07B7DA49A6E28796058AA89E651D233B357D5607006D70619CD89DAAAB" },
|
||||
]
|
||||
|
||||
[requirements]
|
||||
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
|
||||
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
|
5
game_client/src/game_client.gleam
Normal file
5
game_client/src/game_client.gleam
Normal file
@ -0,0 +1,5 @@
|
||||
import gleam/io
|
||||
|
||||
pub fn main() {
|
||||
io.println("Hello from game_client!")
|
||||
}
|
12
game_client/test/game_client_test.gleam
Normal file
12
game_client/test/game_client_test.gleam
Normal file
@ -0,0 +1,12 @@
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
||||
pub fn main() {
|
||||
gleeunit.main()
|
||||
}
|
||||
|
||||
// gleeunit test functions end in `_test`
|
||||
pub fn hello_world_test() {
|
||||
1
|
||||
|> should.equal(1)
|
||||
}
|
4
shared/.gitignore
vendored
Normal file
4
shared/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*.beam
|
||||
*.ez
|
||||
/build
|
||||
erl_crash.dump
|
24
shared/README.md
Normal file
24
shared/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# shared
|
||||
|
||||
[](https://hex.pm/packages/shared)
|
||||
[](https://hexdocs.pm/shared/)
|
||||
|
||||
```sh
|
||||
gleam add shared@1
|
||||
```
|
||||
```gleam
|
||||
import shared
|
||||
|
||||
pub fn main() {
|
||||
// TODO: An example of the project in use
|
||||
}
|
||||
```
|
||||
|
||||
Further documentation can be found at <https://hexdocs.pm/shared>.
|
||||
|
||||
## Development
|
||||
|
||||
```sh
|
||||
gleam run # Run the project
|
||||
gleam test # Run the tests
|
||||
```
|
20
shared/gleam.toml
Normal file
20
shared/gleam.toml
Normal file
@ -0,0 +1,20 @@
|
||||
name = "shared"
|
||||
version = "1.0.0"
|
||||
|
||||
# Fill out these fields if you intend to generate HTML documentation or publish
|
||||
# your project to the Hex package manager.
|
||||
#
|
||||
# description = ""
|
||||
# licences = ["Apache-2.0"]
|
||||
# repository = { type = "github", user = "", repo = "" }
|
||||
# links = [{ title = "Website", href = "" }]
|
||||
#
|
||||
# For a full reference of all the available options, you can have a look at
|
||||
# https://gleam.run/writing-gleam/gleam-toml/.
|
||||
|
||||
[dependencies]
|
||||
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
|
||||
gleam_json = ">= 2.3.0 and < 3.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
gleeunit = ">= 1.0.0 and < 2.0.0"
|
13
shared/manifest.toml
Normal file
13
shared/manifest.toml
Normal file
@ -0,0 +1,13 @@
|
||||
# This file was generated by Gleam
|
||||
# You typically do not need to edit this file
|
||||
|
||||
packages = [
|
||||
{ name = "gleam_json", version = "2.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "C55C5C2B318533A8072D221C5E06E5A75711C129E420DD1CE463342106012E5D" },
|
||||
{ name = "gleam_stdlib", version = "0.59.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "F8FEE9B35797301994B81AF75508CF87C328FE1585558B0FFD188DC2B32EAA95" },
|
||||
{ name = "gleeunit", version = "1.3.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "A7DD6C07B7DA49A6E28796058AA89E651D233B357D5607006D70619CD89DAAAB" },
|
||||
]
|
||||
|
||||
[requirements]
|
||||
gleam_json = { version = ">= 2.3.0 and < 3.0.0" }
|
||||
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
|
||||
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
|
23
shared/src/player.gleam
Normal file
23
shared/src/player.gleam
Normal file
@ -0,0 +1,23 @@
|
||||
import gleam/dynamic/decode
|
||||
import gleam/json
|
||||
|
||||
pub type Player {
|
||||
Player(name: String, id: Int, score: Int)
|
||||
}
|
||||
|
||||
pub fn serialize(player: Player) -> List(#(String, json.Json)) {
|
||||
[
|
||||
#("name", json.string(player.name)),
|
||||
#("id", json.int(player.id)),
|
||||
#("score", json.int(player.score)),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn decoder() -> decode.Decoder(Player) {
|
||||
{
|
||||
use name <- decode.field("name", decode.string)
|
||||
use id <- decode.field("id", decode.int)
|
||||
use score <- decode.field("score", decode.int)
|
||||
decode.success(Player(name:, id:, score:))
|
||||
}
|
||||
}
|
34
shared/src/session.gleam
Normal file
34
shared/src/session.gleam
Normal file
@ -0,0 +1,34 @@
|
||||
import gleam/dynamic/decode
|
||||
import gleam/json
|
||||
import gleam/list
|
||||
import player
|
||||
|
||||
pub type Session {
|
||||
Session(id: Int, host_user_id: Int, players: List(player.Player))
|
||||
}
|
||||
|
||||
pub fn serialize(session: Session) -> json.Json {
|
||||
json.object([
|
||||
#("id", json.int(session.id)),
|
||||
#("host_user_id", json.int(session.host_user_id)),
|
||||
#(
|
||||
"players",
|
||||
json.array(
|
||||
list.map(session.players, fn(p) { player.serialize(p) }),
|
||||
of: json.object,
|
||||
),
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
pub fn deseralize(json_string: String) -> Result(Session, json.DecodeError) {
|
||||
let session_decoder = {
|
||||
use id <- decode.field("id", decode.int)
|
||||
use host_user_id <- decode.field("host_user_id", decode.int)
|
||||
use players <- decode.field("players", decode.list(player.decoder()))
|
||||
|
||||
decode.success(Session(id:, host_user_id:, players:))
|
||||
}
|
||||
|
||||
json.parse(from: json_string, using: session_decoder)
|
||||
}
|
5
shared/src/shared.gleam
Normal file
5
shared/src/shared.gleam
Normal file
@ -0,0 +1,5 @@
|
||||
import gleam/io
|
||||
|
||||
pub fn main() {
|
||||
io.println("Hello from shared!")
|
||||
}
|
47
shared/test/shared_test.gleam
Normal file
47
shared/test/shared_test.gleam
Normal file
@ -0,0 +1,47 @@
|
||||
import gleam/json
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
import player
|
||||
import session
|
||||
|
||||
pub fn main() {
|
||||
gleeunit.main()
|
||||
}
|
||||
|
||||
pub fn serialize_player_test() {
|
||||
player.Player("CoolZero123", 55, 0)
|
||||
|> player.serialize
|
||||
|> should.equal([
|
||||
#("name", json.string("CoolZero123")),
|
||||
#("id", json.int(55)),
|
||||
#("score", json.int(0)),
|
||||
])
|
||||
}
|
||||
|
||||
pub fn decoder_player_test() {
|
||||
let decoder = player.decoder()
|
||||
let input_str = "{\"name\": \"CoolZero123\", \"id\": 55, \"score\": 0}"
|
||||
|
||||
let assert Ok(player) = json.parse(from: input_str, using: decoder)
|
||||
|
||||
should.equal(player.name, "CoolZero123")
|
||||
should.equal(player.id, 55)
|
||||
should.equal(player.score, 0)
|
||||
}
|
||||
|
||||
pub fn serialzie_session_test() {
|
||||
session.Session(2, 55, [player.Player("CoolZero123", 55, 0)])
|
||||
|> session.serialize
|
||||
|> json.to_string
|
||||
|> should.equal(
|
||||
"{\"id\":2,\"host_user_id\":55,\"players\":[{\"name\":\"CoolZero123\",\"id\":55,\"score\":0}]}",
|
||||
)
|
||||
}
|
||||
|
||||
pub fn desarlize_session_test() {
|
||||
let input_str =
|
||||
"{\"id\":2,\"host_user_id\":55,\"players\":[{\"name\":\"CoolZero123\",\"id\":55,\"score\":0}]}"
|
||||
let assert Ok(s) = session.deseralize(input_str)
|
||||
|
||||
should.equal(s, session.Session(2, 55, [player.Player("CoolZero123", 55, 0)]))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user