--Sett referee kit as random
--Module created by MjTs-140914 on (01/09/2018)

local function set_referee_random(ctx, options)
    rdm = math.random (1,5)
	if rdm then
	   log(string.format("switching referee kit texture to: (referee_%s.dds).", rdm))
	end
end

local function get_ref_texture_name(filename)
    if rdm then
       return string.match(string.lower(filename), "common\\character0\\model\\character\\uniform\\texture\\(referee_%d+%.dds)")
    end
end

local function rewrite(ctx, filename)
	refname = get_ref_texture_name(filename)
	if refname then
   	   return string.gsub(filename, refname, string.format("referee_%s.dds", rdm))
    end
end

local function init(ctx)
    math.randomseed(os.time())
	ctx.register("livecpk_rewrite", rewrite)
	ctx.register("set_conditions", set_referee_random)
end

return { init = init }