more structure to forms and views
shared ui got an interface to demo the components
This commit is contained in:
@@ -46,6 +46,9 @@ dependencies {
|
||||
// Websockets
|
||||
implementation(libs.ktor.server.websockets)
|
||||
|
||||
// CORS
|
||||
implementation(libs.ktor.server.cors)
|
||||
|
||||
// General Use
|
||||
implementation(libs.kotlinx.datetime)
|
||||
|
||||
|
||||
@@ -698,20 +698,13 @@
|
||||
},
|
||||
"quantity" : { }
|
||||
}
|
||||
};
|
||||
defs["Location"] = {
|
||||
"title" : "Location",
|
||||
"required" : [ "name" ],
|
||||
"properties" : {
|
||||
"name" : { }
|
||||
}
|
||||
};
|
||||
defs["Market"] = {
|
||||
"title" : "Market",
|
||||
"required" : [ "location", "prices" ],
|
||||
"properties" : {
|
||||
"location" : {
|
||||
"$ref" : "#/components/schemas/Location"
|
||||
"enum" : [ "BROOKLYN", "BRONX", "STATTEN_ISLAND", "QUEENS" ]
|
||||
},
|
||||
"prices" : {
|
||||
"additionalProperties" : { }
|
||||
@@ -737,7 +730,7 @@
|
||||
"debt" : { },
|
||||
"health" : { },
|
||||
"location" : {
|
||||
"$ref" : "#/components/schemas/Location"
|
||||
"enum" : [ "BROOKLYN", "BRONX", "STATTEN_ISLAND", "QUEENS" ]
|
||||
},
|
||||
"day" : { },
|
||||
"inventory" : {
|
||||
|
||||
@@ -6,6 +6,8 @@ import dev.geekback.dopewars.server.routes.modelCrudRoutes
|
||||
import dev.geekback.dopewars.server.routes.playerRoutes
|
||||
import dev.geekback.dopewars.server.services.GameService
|
||||
import dev.geekback.dopewars.server.services.MarketService
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.engine.*
|
||||
@@ -13,6 +15,7 @@ import io.ktor.server.http.content.*
|
||||
import io.ktor.server.netty.*
|
||||
import io.ktor.server.plugins.calllogging.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.server.plugins.cors.routing.CORS
|
||||
import io.ktor.server.plugins.openapi.*
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.server.websocket.*
|
||||
@@ -27,7 +30,7 @@ fun Application.module() {
|
||||
}
|
||||
|
||||
println("[ # ] Loading Web Sockets Plugin")
|
||||
install(WebSockets);
|
||||
install(WebSockets)
|
||||
|
||||
println("[ # ] Loading Content Negotiation Plugin")
|
||||
install(ContentNegotiation) {
|
||||
@@ -39,6 +42,13 @@ fun Application.module() {
|
||||
})
|
||||
}
|
||||
|
||||
println("[ # ] Loading CORS Plugin")
|
||||
install(CORS) {
|
||||
anyHost()
|
||||
allowMethod(HttpMethod.Options)
|
||||
allowHeader(HttpHeaders.ContentType)
|
||||
}
|
||||
|
||||
println("[ # ] Plugins Loaded")
|
||||
|
||||
val marketService = MarketService()
|
||||
@@ -52,7 +62,7 @@ fun Application.module() {
|
||||
modelCrudRoutes(marketService)
|
||||
|
||||
webSocket("/ws") {
|
||||
send("Welcome to DopeWars");
|
||||
send("Welcome to DopeWars")
|
||||
for (frame in incoming) {
|
||||
if (frame is Frame.Text) send("Echo: ${frame.readText()}")
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ fun Route.marketRoutes(
|
||||
get {
|
||||
val players = PlayerRepository.all().toList()
|
||||
|
||||
val response: MutableList<Market> = mutableListOf();
|
||||
val response: MutableList<Market> = mutableListOf()
|
||||
players.forEach { player ->
|
||||
response.add(player.lastMarket!!)
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@ fun Route.modelCrudRoutes(marketService: MarketService) {
|
||||
|
||||
// List
|
||||
get {
|
||||
val modelName = call.parameters["modelName"]
|
||||
when (modelName) {
|
||||
when (val modelName = call.parameters["modelName"]) {
|
||||
"market" -> {
|
||||
call.respond(marketService.generateMarket(Location("BRONX")))
|
||||
call.respond(marketService.generateMarket(Location.BRONX))
|
||||
}
|
||||
else -> {
|
||||
call.respond("Model name is $modelName")
|
||||
|
||||
@@ -27,7 +27,7 @@ fun Route.playerRoutes(
|
||||
|
||||
// Create
|
||||
post {
|
||||
val location = Location("Brooklyn")
|
||||
val location = Location.BROOKLYN
|
||||
val mkt = marketService.generateMarket(location)
|
||||
|
||||
val player = Player(
|
||||
@@ -59,7 +59,7 @@ fun Route.playerRoutes(
|
||||
|
||||
// Read
|
||||
get {
|
||||
val players = PlayerRepository.all();
|
||||
val players = PlayerRepository.all()
|
||||
|
||||
call.respond(
|
||||
HttpStatusCode.OK,
|
||||
|
||||
@@ -60,7 +60,7 @@ class GameService(
|
||||
player: Player,
|
||||
drug: Drug,
|
||||
quantity: Int,
|
||||
price: Float
|
||||
price: Int
|
||||
) {
|
||||
|
||||
val cost = price * quantity
|
||||
@@ -90,7 +90,7 @@ class GameService(
|
||||
player: Player,
|
||||
drug: Drug,
|
||||
quantity: Int,
|
||||
price: Float
|
||||
price: Int
|
||||
) {
|
||||
|
||||
val inventoryItem = player.inventory
|
||||
@@ -104,7 +104,7 @@ class GameService(
|
||||
}
|
||||
|
||||
inventoryItem.quantity -= quantity
|
||||
player.cash += price * quantity.toFloat()
|
||||
player.cash += price * quantity
|
||||
|
||||
if (inventoryItem.quantity == 0) {
|
||||
player.inventory.remove(inventoryItem)
|
||||
|
||||
@@ -8,7 +8,7 @@ import dev.geekback.dopewars.shared.Market
|
||||
class MarketService {
|
||||
|
||||
fun generateMarket(location: Location): Market {
|
||||
val prices: MutableMap<Drug, Float> = mutableMapOf()
|
||||
val prices: MutableMap<Drug, Int> = mutableMapOf()
|
||||
|
||||
Drugs.all.forEach { drugInfo ->
|
||||
prices[drugInfo.drug] = drugInfo.newPrice()
|
||||
|
||||
Reference in New Issue
Block a user