Skip to content

Commit

Permalink
Add initial support for Wand2 template
Browse files Browse the repository at this point in the history
  • Loading branch information
dextercd committed Jan 28, 2024
1 parent f5c1d19 commit 9587974
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 26 deletions.
102 changes: 76 additions & 26 deletions component-explorer/utils/wiki_wand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ local wiki_wand = {}
---Turn an EZWand object into a list of values used in Wand/Wand Card templates
---@param ezwand table
---@param to_wand_card boolean
---@param is_wand2 boolean
---@return table
function wiki_wand.get_wand_values(ezwand, to_wand_card)
function wiki_wand.get_wand_values(ezwand, to_wand_card, is_wand2)
local values = {}
local wiki_file_name = wand_sprites.wiki_sprite_filename(ezwand)

if is_wand2 and to_wand_card then
table.insert(values, {"wandCard", "Yes"})
end

if to_wand_card then
local item_name = nil
Expand All @@ -35,6 +39,7 @@ function wiki_wand.get_wand_values(ezwand, to_wand_card)
end
end

local wiki_file_name = wand_sprites.wiki_sprite_filename(ezwand)
if wiki_file_name then
table.insert(values, {"wandPic", wiki_file_name})
end
Expand Down Expand Up @@ -67,16 +72,32 @@ function wiki_wand.get_wand_values(ezwand, to_wand_card)
table.insert(values, {"speed", ("%.2f"):format(ezwand.speedMultiplier)})
end

for _, spell in ipairs(attached_spells) do
local wiki_name = wiki_spell_names.by_action_id[spell.action_id]
table.insert(values, {"alwaysCasts", wiki_name})
end
if is_wand2 then
if #attached_spells > 0 then
local ac_actions = {}
for _, ac in ipairs(attached_spells) do
ac_actions[#ac_actions+1] = ac.action_id
end
table.insert(values, {"alwaysCasts", table.concat(ac_actions, ",")})
end

local spell_nr = 1
for _, spell in ipairs(spells) do
local wiki_name = wiki_spell_names.by_action_id[spell.action_id]
table.insert(values, {"spell" .. spell_nr, wiki_name})
spell_nr = spell_nr + 1
local spell_actions = {}
for _, spell in ipairs(spells) do
spell_actions[#spell_actions+1] = spell.action_id
end
table.insert(values, {"spells", table.concat(spell_actions, ",")})
else
for _, spell in ipairs(attached_spells) do
local wiki_name = wiki_spell_names.by_action_id[spell.action_id]
table.insert(values, {"alwaysCasts", wiki_name})
end

local spell_nr = 1
for _, spell in ipairs(spells) do
local wiki_name = wiki_spell_names.by_action_id[spell.action_id]
table.insert(values, {"spell" .. spell_nr, wiki_name})
spell_nr = spell_nr + 1
end
end

return values
Expand All @@ -86,14 +107,18 @@ end
---@param ezwand table
---@param to_wand_card boolean
---@return string
function wiki_wand.wand_to_wiki_text(ezwand, to_wand_card)
local wand_values = wiki_wand.get_wand_values(ezwand, to_wand_card)
function wiki_wand.wand_to_wiki_text(ezwand, to_wand_card, is_wand2)
local wand_values = wiki_wand.get_wand_values(ezwand, to_wand_card, is_wand2)

if is_wand2 then
return wiki.format_template("Wand2", wand_values, 12)
end

if to_wand_card then
return wiki.format_template("Wand Card", wand_values, 12)
else
return wiki.format_template("Wand", wand_values, 11)
end

return wiki.format_template("Wand", wand_values, 11)
end

---Turn range text like "(3 - 8.5)" to values 3, 8.5. Also parses a single value successfully.
Expand Down Expand Up @@ -163,6 +188,21 @@ local function set_sprite_by_filename(ezwand, filename)
return true
end

---@param spell_list string
---@return string[]
local function split_spell_list(spell_list)
local actions = string_util.split(spell_list, ",", true)
local ret = {}
for _, action in ipairs(actions) do
action = string_util.trim(action)
if action ~= "" then
ret[#ret+1] = action
end
end

return ret
end

function wiki_wand.load_data_to_wand(wand, template_data)
map = {}
for _, v in ipairs(template_data.values) do
Expand Down Expand Up @@ -221,19 +261,29 @@ function wiki_wand.load_data_to_wand(wand, template_data)
end

wand:DetachSpells()
for _, item in ipairs(template_data.values) do
if item[1] == "alwaysCasts" then
local action_id = wiki_spell_names.to_action_id(item[2])
wand:AttachSpells(action_id)
wand:RemoveSpells()

if template_data.template_name == "Wand2" then
if map.alwaysCasts then
wand:AttachSpells(split_spell_list(map.alwaysCasts))
end
if map.spells then
wand:AddSpells(split_spell_list(map.spells))
end
else
for _, item in ipairs(template_data.values) do
if item[1] == "alwaysCasts" then
local action_id = wiki_spell_names.to_action_id(item[2])
wand:AttachSpells(action_id)
end
end
end

wand:RemoveSpells()
for spell_nr=1, map.capacity do
local spell_name = map["spell" .. spell_nr]
if spell_name ~= nil then
local action_id = wiki_spell_names.to_action_id(spell_name)
wand:AddSpells(action_id)
for spell_nr=1, map.capacity do
local spell_name = map["spell" .. spell_nr]
if spell_name ~= nil then
local action_id = wiki_spell_names.to_action_id(spell_name)
wand:AddSpells(action_id)
end
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions component-explorer/wiki_wands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ local function import_menu()
confirm_function = confirm_wand_card_import
elseif _g_parsed_template.template_name == "Wand" then
confirm_function = confirm_wand_import
elseif _g_parsed_template.template_name == "Wand2" then
confirm_function = confirm_wand_card_import
else
error_text("Unknown template: '" .. _g_parsed_template.template_name .. "'")
return
Expand Down Expand Up @@ -261,6 +263,8 @@ local function needs_wand()
imgui.PopStyleColor()
end

local wand2_wand_card = false

local function wiki_wands_contents()
local wand = EZWand.GetHeldWand()

Expand Down Expand Up @@ -296,6 +300,22 @@ local function wiki_wands_contents()
imgui.EndTabItem()
end

if imgui.BeginTabItem("Wand2") then
if not wand then
needs_wand()
else
local _
_, wand2_wand_card = imgui.Checkbox("Wand Card", wand2_wand_card)
local wand_text = wiki_wand_util.wand_to_wiki_text(wand, wand2_wand_card, true)
if imgui.Button("Copy") then
imgui.SetClipboardText(wand_text)
end

imgui.Text(wand_text)
end
imgui.EndTabItem()
end

if imgui.BeginTabItem("Import") then
import_menu()
imgui.EndTabItem()
Expand Down

0 comments on commit 9587974

Please sign in to comment.