--[[
Interface: 1.5.1.0 b6732

Copyright (C) GtX (Andy), 2020

Author: GtX | Andy
Date: 08.03.2020
Version: 1.0.0.0

Contact:
https://forum.giants-software.com
https://github.com/GtX-Andy

History:
V 1.0.0.0 @ 08.03.2020 - Release for 'FS19_FI_SeedCleaner' only.

About:
Simple loader for 'FS19_FI_SeedCleaner' so I do not need to use my PlacableLoader.lua and RegisterFillTypes.lua and ObjectStorageLoader.lua
Not for use on other mods in this or an edited form, contact me for more information or help.
]]


local modName = g_currentModName
local modDirectory = g_currentModDirectory

local function loadFillTypes(fillTypeManager, xmlFile, missionInfo, baseDirectory)
    local name = "LUMIGEN"

    if fillTypeManager:getFillTypeByName(name) == nil then
        local price = 1.75
        local hudOverlayFilename = "hud/hud_fill_lumiGen.png"
        local hudOverlayFilenameSmall = "hud/hud_fill_lumiGen_sml.png"
        local palletFilename = "liquidTank/lumiGenTank.xml"

        local fillType = fillTypeManager:addFillType(name, g_i18n:getText("fillType_lumiGen", modName), false, price, 0.001, 0, hudOverlayFilename, hudOverlayFilenameSmall, modDirectory, nil, {1, 1, 1}, palletFilename, false)
        if fillType ~= nil then
            local inserted = false

            for _, fillTypeSample in pairs (fillTypeManager.fillTypeSamples) do
                for i, fillTypeIndex in pairs (fillTypeSample.fillTypes) do
                    if fillTypeIndex == FillType.WATER then
                        fillTypeManager.fillTypeToSample[fillType.index] = fillTypeSample.sample
                        table.insert(fillTypeSample.fillTypes, fillType.index)

                        inserted = true
                        break
                    end
                end

                if inserted then
                    break
                end
            end

            local categoryIndex = fillTypeManager.nameToCategoryIndex["LIQUID"]
            if categoryIndex ~= nil then
                fillTypeManager:addFillTypeToCategory(fillType.index, categoryIndex)
            end

            -- print(string.format("  Register fillType '%s' (%s)", name, tostring(modName)))
        end
    end
end

local function init()
    if modName == "FS19_FI_SeedCleaner" or modName == "FS19_FI_SeedCleaner_update" then
        g_placeableTypeManager:addPlaceableType("fillTypeConverter", "FillTypeConverter", modDirectory .. "scripts/FillTypeConverter.lua")

		source(modDirectory .. "scripts/events/ObjectStorageSpawnEvent.lua")
		source(modDirectory .. "scripts/events/ObjectStorageStoreEvent.lua")
		source(modDirectory .. "scripts/events/ObjectStorageFermentEvent.lua")
		source(modDirectory .. "scripts/events/ObjectStorageSpecialStoreEvent.lua")

		g_placeableTypeManager:addPlaceableType("objectStoragePlaceable", "ObjectStorage", modDirectory .. "scripts/ObjectStorage.lua")

		if g_gui ~= nil and g_gui.guis.ObjectStorageGui == nil then
            source(modDirectory .. "scripts/gui/ObjectStorageGui.lua")
            local objectStorageGui = ObjectStorageGui:new(nil, nil)
			g_gui:loadGui(modDirectory .. "scripts/gui/ObjectStorageGui.xml", "ObjectStorageGui", objectStorageGui)
        end

		FillTypeManager.loadMapData = Utils.appendedFunction(FillTypeManager.loadMapData, loadFillTypes)
	else
		local text = "  - Mod has failed to load, please visit official modHub link below for latest version."
		local link = "  - https://farming-simulator.com/mods.php?lang=en&title=fs2019&filter=org&org_id=129652&page=0"
		print(string.format("Seed Cleaner 1200-LG - Version 1.0.0.0\n%s\n%s", text, link))
    end
end

init()
