fixed bug with recording matches on older versions, added colour scheme models

This commit is contained in:
Michael Simard
2021-10-31 11:05:15 -05:00
parent c88098e05e
commit 9374175c50
6 changed files with 93 additions and 7 deletions

View File

@@ -0,0 +1,21 @@
//
// ColorSchemeConfig.swift
// App
//
// Created by Michael Simard on 10/31/21.
//
import Foundation
import Foundation
import Fluent
import Vapor
struct ColorSchemeConfig: Content {
var gameId: Int
var tileColour: String?
var winColour: String?
var lossColour: String?
}

View File

@@ -16,7 +16,8 @@ struct GameConfig: Content {
var gameId: String
var name: String
var maps: [MapConfig]
var enabled:Bool
var enabled:Bool
var colours:ColorSchemeConfig?
}

View File

@@ -47,18 +47,30 @@ struct AppDataController: RouteCollection {
}
}
return (gameModeConfigs.and(gameModeGroupConfigs).and(games).and(maps).and(playerConfigs).and(lossReasonConfigs)).map { arg -> (Configuration) in
let colourSchemeConfigs = ColourScheme.query(on: req.db).all().map { colourScheme in
return colourScheme.map { cs in
return cs.colorSchemeConfig
}
}
return (gameModeConfigs.and(gameModeGroupConfigs).and(games).and(maps).and(playerConfigs).and(lossReasonConfigs).and(colourSchemeConfigs)).map { arg -> (Configuration) in
let (((((( gameModeConfigs), gameModeGroupConfigs),games),maps),playerConfigs), lossReasonConfigs) = arg
let ((((((( gameModeConfigs), gameModeGroupConfigs),games),maps),playerConfigs), lossReasonConfigs),colourSchemeConfigs) = arg
var gameConfigs:[GameConfig] = []
gameConfigs = games.map({ game in
let mapConfigs = game.mapIds.compactMap { mapId in
return maps.first { m in
m.mapId == mapId
}?.mapConfig
}
return GameConfig(gameId: game.gameId, name: game.name, maps: mapConfigs, enabled: game.enabled)
return GameConfig(gameId: game.gameId, name: game.name, maps: mapConfigs, enabled: game.enabled, colours: colourSchemeConfigs.first{game.gameId == "\($0.gameId)"})
})
return Configuration(games:gameConfigs, gameModes: gameModeConfigs, gameModeGroups: gameModeGroupConfigs, players: playerConfigs, lossReasons: lossReasonConfigs)
}

View File

@@ -0,0 +1,52 @@
//
// ColourScheme.swift
// App
//
// Created by Michael Simard on 10/31/21.
//
import Foundation
import Fluent
import Vapor
final class ColourScheme: Model, Content {
// Name of the table or collection.
static let schema = "color_scheme"
@ID(key: .id)
var id: UUID?
@Field(key: "game_id")
var gameId: Int
@Field(key: "tile_colour")
var tileColour: String?
@Field(key: "win_colour")
var winColour: String?
@Field(key: "loss_colour")
var lossColour: String?
// Creates a new, empty .
init() { }
// Creates a new with all properties set.
init(id: UUID? = nil, gameId: Int, tileColour: String?,winColour: String?,lossColour: String? ) {
self.id = id
self.gameId = gameId
self.tileColour = tileColour
self.winColour = winColour
self.lossColour = lossColour
}
var colorSchemeConfig: ColorSchemeConfig {
return ColorSchemeConfig(gameId: gameId, tileColour: tileColour, winColour:winColour, lossColour:lossColour)
}
}

View File

@@ -43,7 +43,7 @@ final class Game: Model, Content {
self.gameId = gameId
self.name = name
self.maps = maps
self.enabled = enabled
self.enabled = enabled
}

View File

@@ -48,13 +48,13 @@ final class Match: Model, Content {
@Field(key: "lossReason")
var lossReason: Int
var lossReason: Int?
init() { }
init(id: UUID? = nil, map:String?, win:Bool, date:Date, roundsWon:Int?, roundsLost:Int?, codGame:String?, notes:String?, players:String?, sweaty:Bool?, finalKillRuinedPlayerId:Int?, numberOfFinalKillsRuined:Int?,competitive:Bool, gameMode:Int, lossReason:Int) {
init(id: UUID? = nil, map:String?, win:Bool, date:Date, roundsWon:Int?, roundsLost:Int?, codGame:String?, notes:String?, players:String?, sweaty:Bool?, finalKillRuinedPlayerId:Int?, numberOfFinalKillsRuined:Int?,competitive:Bool, gameMode:Int, lossReason:Int = 0) {
self.id = id
self.map = map
self.win = win