Module:XC2 enum enhance

From Xeno Series Wiki
Jump to navigation Jump to search

The data is at Module:XC2 enum enhance/data (BTL_Enhance) and Module:XC2 enum enhance/data 2 (BTL_EnhanceEff). It's unlikely you'll need to edit them.

The captions are at Module:XC2 enum enhance/captions. Edit that if you need to repoint links or something. If an "uncaptioned" entry pops up (there's a lot of them), go to Module:XC2 enum enhance/captions 2 and add a relevant entry there, using the same general style. (Though first see if /captions haas an existing entry for the same effect.)



local enhance_table = mw.loadData("Module:XC2 enum enhance/data")
local enhance_table_2 = mw.loadData("Module:XC2 enum enhance/data 2")
local enhance_ms_table = mw.loadData("Module:XC2 enum enhance/captions")
local enhance_ms_custom_table = mw.loadData("Module:XC2 enum enhance/captions 2")

local xc2_enum_enhance = {}

function xc2_enum_enhance.getEnhanceCaptionParams(id,e,isTorna)
	extraParams = enhance_table_2[e[1]]
	if e[1] == 0 then
		extraParams = {0,0,0,0,0,0,0}
	end
	captionID = e[4]
	if isTorna then
		captionID = e[5]
	end
	if captionID == 0 then
		-- so the "use which caption" column is in /data, but the actual logical place to put it is /data 2
		-- therefore, if an entry in /data has no caption, pick out a custom one based on the /data 2 index
		caption = enhance_ms_custom_table[e[1]]
		if caption == nil or caption == "" then
			caption = "uncaptioned enhance ["..e[1].."]: [ML:Enhance kind=Param1 ], [ML:Enhance kind=Param2 ], [ML:Enhance ]{{#set:undefined enum=xc2 uncaptioned enhance "..e[1].."}}"
		end
	else
		caption = enhance_ms_table[captionID]
	end
	return {captionID,caption,e[2],e[3],extraParams[4]}
end

function xc2_enum_enhance.formatCaptionParams(p)
	-- this gsub format lets us do a single operation rather than "three but we usually only need one"
	return p[2]:gsub("%[ML:Enhance.-]",{["[ML:Enhance kind=Param1 ]"]=p[3],["[ML:Enhance kind=Param2 ]"]=p[4],["[ML:Enhance ]"]=p[5]})
end

function xc2_enum_enhance.getEnhanceCategory(frame) -- used for driver skill icons
	id = tonumber(frame.args[1])
	if id == 0 then
		return -1
	else
		enhanceEntry = enhance_table[id]
		if enhanceEntry then
			enhanceEffEntry = enhance_table_2[enhanceEntry[1]]
			if enhanceEntry[1] == 0 then
				return -1
			else
				return enhanceEffEntry[1]
			end
		else
			return -1
		end
	end
end

function xc2_enum_enhance.getEnhanceIcon(frame) -- used for driver art icons
	id = tonumber(frame.args[1])
	if id == 0 then
		return -1
	else
		enhanceEntry = enhance_table[id]
		if enhanceEntry then
			enhanceEffEntry = enhance_table_2[enhanceEntry[1]]
			if enhanceEntry[1] == 0 then
				return -1
			else
				-- bonus fun: if the icon is 0, can't actually return 0 unless UI (Flag bit 2) is True
				-- why? the logic seems to be "if Icon is nonzero, use it, but if it *is* zero, look at UI to decide"
				icon = enhanceEffEntry[2]
				uiFlag = enhanceEffEntry[3]%2
				if icon > 0 or (icon == 0 and uiFlag == 1) then
					return icon
				else
					return -1
				end
			end
		else
			return -1
		end
	end
end

function xc2_enum_enhance.getEnhanceName(frame)
--	this would involve linking extraParams[5] to btl_buff_ms, which is a bit too weird to bother with right now
end

function xc2_enum_enhance.getEnhanceCaption(frame)
	id = tonumber(frame.args[1])
	if id == 0 then
		return "''none''"
	end
	isTorna = false
	if frame.args[2] == "y" then
		isTorna = true
	end
	enhanceEntry = enhance_table[id]
	if enhanceEntry then
		params = xc2_enum_enhance.getEnhanceCaptionParams(id,enhanceEntry,isTorna)
		return frame:preprocess(xc2_enum_enhance.formatCaptionParams(params))
	else
		return "undefinedEnhance["..id.."]"
	end
end

function xc2_enum_enhance.getEnhanceCaptionRange(frame)
	id1 = tonumber(frame.args[1])
	id2 = tonumber(frame.args[2])
	if id1 == id2 then
		return xc2_enum_enhance.getEnhanceCaption(frame)
	end
	if id1 == 0 then
		return "''none''"
	end
	isTorna = false
	if frame.args[3] == "y" then
		isTorna = true
	end
	enhance1Entry = enhance_table[id1]
	enhance2Entry = enhance_table[id2]
	if enhance1Entry then
		if enhance2Entry then
			params1 = xc2_enum_enhance.getEnhanceCaptionParams(id1,enhance1Entry,isTorna)
			params2 = xc2_enum_enhance.getEnhanceCaptionParams(id2,enhance2Entry,isTorna)
			if params1[1] ~= params2[1] then -- captions don't match, so we can't auto-compare them
				-- here we would put predefined manual compares, if we later find we need any
				return "incomparable enhances ["..id1..","..id2.."]"
			end
			rangeParams = {params1[1],params1[2],params1[3].."-"..params2[3],params1[4].."-"..params2[4],params1[5].."-"..params2[5]}
			return frame:preprocess(xc2_enum_enhance.formatCaptionParams(rangeParams))
		else
			return "undefinedEnhance2["..id.."]"
		end
	else
		return "undefinedEnhance1["..id.."]"
	end
end

return xc2_enum_enhance