Jump to content

Module:ImportRaces

From Utopia Game
Revision as of 13:01, 6 November 2025 by Sonja says (talk | contribs)

local p = {}

function p.import()

   -- Load the CSV file from the specified folder
   local csvFile = mw.title.new("File:uploads/utopia_race_details.csv")  -- Adjust the path as necessary
   local content = csvFile:getContent()  -- Get the content of the file
   local lines = mw.text.split(content, "\n")  -- Split the content into lines
   for i, line in ipairs(lines) do  -- Loop through each line in the CSV
       if i > 1 then  -- Skip header line (the first line)
           local fields = mw.text.split(line, ",")  -- Split the line into fields
           local race = fields[1]  -- First field: race name
           local bonuses = fields[2]  -- Second field: bonuses
           local penalties = fields[3]  -- Third field: penalties
           local unique = fields[4]  -- Fourth field: unique features
           local spells = fields[5]  -- Fifth field: spells
           -- Here, you would use Cargo's #cargo_insert_data to insert the data
           mw.log("Inserting race: " .. race)  -- Log the race being inserted
           --[[ 
           {{#cargo_insert_data:
           | table = races
           | race = race
           | bonuses = bonuses
           | penalties = penalties
           | unique = unique
           | spells = spells
           }}
           ]]  -- Pseudo-code for inserting data into Cargo
       end
   end

end

return p