map, player, game, gamemode data now database driven

This commit is contained in:
Michael Simard
2021-10-31 00:01:27 -05:00
parent b0b0b7bc60
commit 64a66e28b8
22 changed files with 711 additions and 143 deletions

View File

@@ -0,0 +1,53 @@
//
// Game.swift
// App
//
// Created by Michael Simard on 10/29/21.
//
import Foundation
import Fluent
import Vapor
final class Game: Model, Content {
// Name of the table or collection.
static let schema = "game"
@ID(key: .id)
var id: UUID?
@Field(key: "game_id")
var gameId: String
@Field(key: "name")
var name: String
@Field(key: "maps")
var maps: String
@Field(key: "enabled")
var enabled: Bool
// Creates a new, empty .
init() { }
// Creates a new with all properties set.
init(id: UUID? = nil, gameId: String, name: String, maps:String, enabled:Bool) {
self.id = id
self.gameId = gameId
self.name = name
self.maps = maps
self.enabled = enabled
}
var mapIds:[Int] {
maps.components(separatedBy: ",").map{Int($0)!}
}
}

View File

@@ -0,0 +1,51 @@
//
// GameModes.swift
// App
//
// Created by Michael Simard on 10/29/21.
//
import Foundation
import Fluent
import Vapor
final class GameMode: Model, Content {
// Name of the table or collection.
static let schema = "game_mode"
@ID(key: .id)
var id: UUID?
@Field(key: "game_mode_id")
var gameModeId: Int
@Field(key: "name")
var name: String
@Field(key: "competitive")
var competitive: Bool
// Creates a new, empty .
init() { }
// Creates a new with all properties set.
init(id: UUID? = nil, gameModeId: Int, name: String, competitive:Bool) {
self.id = id
self.gameModeId = gameModeId
self.name = name
self.competitive = competitive
}
var gameModeConfig:GameModeConfig {
return GameModeConfig(gameModeId: gameModeId, name: name, competitive: competitive)
}
}

View File

@@ -0,0 +1,45 @@
//
// GameModeGroups.swift
// App
//
// Created by Michael Simard on 10/29/21.
//
import Fluent
import Vapor
final class GameModeGroup: Model, Content {
// Name of the table or collection.
static let schema = "game_mode_group"
@ID(key: .id)
var id: UUID?
@Field(key: "game_mode_ids")
var gameModeIds: String
@Field(key: "game_mode_group_id")
var gameModeGroupId: String
@Field(key: "name")
var name: String
// Creates a new, empty .
init() { }
// Creates a new with all properties set.
init(id: UUID? = nil, gameModeIds: String, name: String, gameModeGroupId:String) {
self.id = id
self.gameModeIds = gameModeIds
self.name = name
self.gameModeGroupId = gameModeGroupId
}
var gameModeGroupConfig: GameModeGroupConfig {
return GameModeGroupConfig(gameModeIds: gameModeIds, gameModeGroupId: gameModeGroupId, name: name)
}
}

View File

@@ -0,0 +1,43 @@
//
// LossReason.swift
// App
//
// Created by Michael Simard on 10/30/21.
//
import Fluent
import Vapor
import Fluent
import Vapor
final class LossReason: Model, Content {
// Name of the table or collection.
static let schema = "loss_reason"
@ID(key: .id)
var id: UUID?
@Field(key: "reason_id")
var reasonId: Int
@Field(key: "name")
var name: String
// Creates a new, empty .
init() { }
// Creates a new with all properties set.
init(id: UUID? = nil, lossReasonId: Int, name: String) {
self.id = id
self.reasonId = reasonId
self.name = name
}
var lossReasonConfig: LossReasonConfig {
return LossReasonConfig(reasonId: reasonId, name: name)
}
}

View File

@@ -0,0 +1,48 @@
//
// Map.swift
// App
//
// Created by Michael Simard on 10/29/21.
//
import Fluent
import Vapor
final class Map: Model, Content {
// Name of the table or collection.
static let schema = "map"
@ID(key: .id)
var id: UUID?
@Field(key: "name")
var name: String
@Field(key: "image_name")
var imageName: String
@Field(key: "game_mode_group_ids")
var gameModeGroupIds: String
@Field(key: "map_id")
var mapId: Int
// Creates a new, empty .
init() { }
// Creates a new with all properties set.
init(id: UUID? = nil, name: String, imageName: String, gameModeGroupIds: String, mapId:Int) {
self.id = id
self.name = name
self.imageName = imageName
self.gameModeGroupIds = gameModeGroupIds
self.mapId = mapId
}
var mapConfig:MapConfig {
return MapConfig(mapId: mapId, name: name, imageName: imageName, gameModeGroupIds: gameModeGroupIds.components(separatedBy: ","))
}
}

View File

@@ -47,11 +47,14 @@ final class Match: Model, Content {
var gameMode: Int
@Field(key: "lossReason")
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) {
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) {
self.id = id
self.map = map
self.win = win
@@ -66,7 +69,7 @@ final class Match: Model, Content {
self.numberOfFinalKillsRuined = numberOfFinalKillsRuined
self.competitive = competitive
self.gameMode = gameMode
self.lossReason = lossReason
}
func update( newMatch:Match) {
@@ -88,6 +91,7 @@ final class Match: Model, Content {
self.numberOfFinalKillsRuined = newMatch.numberOfFinalKillsRuined
self.competitive = newMatch.competitive
self.gameMode = newMatch.gameMode
self.lossReason = newMatch.lossReason
}

View File

@@ -0,0 +1,40 @@
//
// Player.swift
// App
//
// Created by Michael Simard on 10/30/21.
//
import Fluent
import Vapor
final class Player: Model, Content {
// Name of the table or collection.
static let schema = "player"
@ID(key: .id)
var id: UUID?
@Field(key: "player_id")
var playerId: Int
@Field(key: "name")
var name: String
// Creates a new, empty .
init() { }
// Creates a new with all properties set.
init(id: UUID? = nil, playerId: Int, name: String) {
self.id = id
self.playerId = playerId
self.name = name
}
var playerConfig: PlayerConfig {
return PlayerConfig(playerId: playerId, name: name)
}
}

View File

@@ -55,6 +55,7 @@ final class WinLossRecords: Model, Content {
self.wins = statistics.wins
self.losses = statistics.losses
self.codTrackerId = statistics.codTrackerId
}