From 83fed68432f037c456ac61c959ce0566bff90730 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sat, 15 Nov 2025 16:01:31 +0100 Subject: [PATCH] Fix csv header key assignment --- processor/luahelper-test.lua | 9 +++++++++ processor/luahelper.lua | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/processor/luahelper-test.lua b/processor/luahelper-test.lua index 81a5e4f..a2fc6df 100644 --- a/processor/luahelper-test.lua +++ b/processor/luahelper-test.lua @@ -362,4 +362,13 @@ test("isArray function", function() assert(isArray(123) == false, "isArray should return false for number") end) +test("toCSV assigns header keys correctly", function() + local teststr = [[ +#mercenary_profiles +Id ModifyStartCost ModifyStep ModifyLevelLimit Health ResistSheet WoundSlots MeleeDamage MeleeAccuracy RangeAccuracy ReceiveAmputationChance ReceiveWoundChanceMult AttackWoundChanceMult Dodge Los StarvationLimit PainThresholdLimit PainThresholdRegen TalentPerkId ActorId SkinIndex HairType HairColorHex VoiceBank Immunity CreatureClass +john_hawkwood_boss 20 0.1 140 blunt 0 pierce 0 lacer 0 fire 0 cold 0 poison 0 shock 0 beam 0 HumanHead HumanShoulder HumanArm HumanThigh HumanFeet HumanChest HumanBody HumanStomach HumanKnee blunt 8 16 crit 1.60 critchance 0.05 0.5 0.5 0.03 0.5 1.2 0.3 8 2200 16 2 talent_the_man_who_sold_the_world human_male 0 hair1 #633D08 player Human +francis_reid_daly 20 0.1 130 blunt 0 pierce 0 lacer 0 fire 0 cold 0 poison 0 shock 0 beam 0 HumanHead HumanShoulder HumanArm HumanThigh HumanFeet HumanChest HumanBody HumanStomach HumanKnee blunt 7 14 crit 1.70 critchance 0.05 0.5 0.4 0.04 0.9 1 0.3 8 2000 10 1 talent_weapon_durability human_male 0 player Human +]] +end) + print("\nAll tests completed!") diff --git a/processor/luahelper.lua b/processor/luahelper.lua index 31817a5..0047da3 100644 --- a/processor/luahelper.lua +++ b/processor/luahelper.lua @@ -106,7 +106,7 @@ function fromCSV(csv, options) local shouldAdd = true if hascomments and #fields > 0 then local firstField = fields[1] - local trimmed = string.gsub(firstField, "^%s*(.-)%s*$", "%1") + local trimmed = trim(firstField) if string.sub(trimmed, 1, 1) == "#" then shouldAdd = false end end if shouldAdd then table.insert(allRows, fields) end @@ -181,7 +181,10 @@ function fromCSV(csv, options) local dataRow = allRows[ii] for j = 1, #dataRow do row[j] = dataRow[j] - if headers[j] ~= nil and headers[j] ~= "" then row[headers[j]] = dataRow[j] end + if headers[j] ~= nil and headers[j] ~= "" then + local headerName = trim(headers[j]) + row[headerName] = dataRow[j] + end end table.insert(rows, row) end