--[[
	Singleton, holds the current minigame, and constructs new minigames
]]

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BaseMinigame = require(ServerStorage.Source.BaseMinigame)
local Flags = require(ReplicatedStorage.Source.Common.Flags)

local minigameModules = {
	require(ServerStorage.Source.Minigames.Platform),
	require(ServerStorage.Source.Minigames.Bombs),
	require(ServerStorage.Source.Minigames.Volcano)
}

local nextRoundIndex = Flags.FirstRound and (Flags.FirstRound - 1) or math.random(1, #minigameModules)

local RoundController = {}

local currentMinigame

function RoundController.selectNextMinigame()
	nextRoundIndex = nextRoundIndex + 1

	if nextRoundIndex > #minigameModules then
		nextRoundIndex = 1
	end
end

function RoundController.getNextMinigame()
	return minigameModules[nextRoundIndex]
end

function RoundController.initialiseMinigame()
	local minigameClass = minigameModules[nextRoundIndex]

	currentMinigame = BaseMinigame.new(minigameClass)
end
