Module:Skills/Cartography: Difference between revisions

From Melvor Idle
(adding another linebreak for readablity)
(Swapped output of test to a table)
Line 17: Line 17:
local POIs = {}
local POIs = {}
local POI_Strings = {}
local POI_Strings = {}
local tableStr = {}
table.insert(tableStr, '{| class="wikitable sortable"')
table.insert(tableStr, '\r\n|-\r\n!Name!!Type!!X!!Y!!Description')
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do
Line 36: Line 38:
local X, Y = p.convertAxialToXY(POI.coords)
local X, Y = p.convertAxialToXY(POI.coords)
table.insert(POI_Strings, POI.name..' ('..X..', '..Y..')')
table.insert(POI_Strings, POI.name..' ('..X..', '..Y..')')
table.insert(tableStr,'\r\n|-\r\n|')
table.insert(tableStr, POI.name)
table.insert(tableStr, '||'..POI.type)
table.insert(tableStr, '||'..X)
table.insert(tableStr, '||'..Y)
table.insert(tableStr, '||'..POI.description)
end
end
table.insert(tableStr, '\r\n|}')
local keyset={}
local keyset={}
local n=0
local n=0
for k,v in pairs(SkillData.Cartography.worldMaps[1]) do
for k,v in pairs(POIs[1]) do
  n=n+1
  n=n+1
  keyset[n]=k
  keyset[n]=k
end
end
mw.logObject(POIs[1])
mw.logObject(POIs[1])
return table.concat(POI_Strings, '<br/>\n')
return table.concat(tableStr, '')
end
end


return p
return p

Revision as of 20:06, 12 September 2023

Documentation for this module may be created at Module:Skills/Cartography/doc

local p = {}

local Shared = require('Module:Shared')
local Constants = require('Module:Constants')
local GameData = require('Module:GameData')
local SkillData = GameData.skillData
local Items = require('Module:Items')
local Icons = require('Module:Icons')

function p.convertAxialToXY(HexCoords)
	local Y = HexCoords.r + (HexCoords.q - (HexCoords.q % 2)) / 2
	local X = HexCoords.q
	return X, Y
end

function p.test()
	local POIs = {}
	local POI_Strings = {}
	local tableStr = {}
	table.insert(tableStr, '{| class="wikitable sortable"')
	table.insert(tableStr, '\r\n|-\r\n!Name!!Type!!X!!Y!!Description')
	
	for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do
		table.insert(POIs, POI)
	end
	
	table.sort(POIs, function(a, b)
						local aX, aY = p.convertAxialToXY(a.coords)
						local bX, bY = p.convertAxialToXY(b.coords)
						if aX ~= bX then
							return aX < bX
						else
							return aY < bY
						end
					 end)
	
	for i, POI in pairs(POIs) do
		local X, Y = p.convertAxialToXY(POI.coords)
		table.insert(POI_Strings, POI.name..' ('..X..', '..Y..')')
		
		table.insert(tableStr,'\r\n|-\r\n|')
		table.insert(tableStr, POI.name)
		table.insert(tableStr, '||'..POI.type)
		table.insert(tableStr, '||'..X)
		table.insert(tableStr, '||'..Y)
		table.insert(tableStr, '||'..POI.description)
	end
	
	table.insert(tableStr, '\r\n|}')
	
	local keyset={}
	local n=0
	
	for k,v in pairs(POIs[1]) do
	  n=n+1
	  keyset[n]=k
	end
	mw.logObject(POIs[1])
	return table.concat(tableStr, '')
end

return p