From Dark and Darker Wiki

(insert_space_before_capitals init)
 
m (dash_for_space() added)
Line 10: Line 10:
     local output_text = input_text:gsub("(%S)(%u)", "%1 %2")
     local output_text = input_text:gsub("(%S)(%u)", "%1 %2")
     return output_text
     return output_text
end
function p.dash_for_space(frame)
    local text = frame.args[1] or ""
    return text:gsub(" ", "-")
end
end


return p
return p

Revision as of 23:47, 26 February 2025

Overview

Utility functions

Functions

insert_space_before_capitals

Adds spaces before capital letters (other than if its the first character). i.e. "ElementalBolt" -> "Elemental Bolt"

Can be invoked within wikitext, or called within another lua module. See Module:MergeSpells for an example that utilizes this module.

Parameters

  • input_text - input string

Examples

{{#invoke:Utilities|insert_space_before_capitals|ElementalBolt}}

Elemental Bolt

dash_for_space

Replaces all spaces with dashes. i.e. "Physical Damage" -> "Physical Damage". Useful for turning text into something that can be used as a css class.

See Module:Enchantments for an example that utilizes this module.

Parameters

  • input_text - input string

Examples

{{#invoke:Utilities|dash_for_space|Physical Damage}}

Physical-Damage1


rarity_name_to_num

Translates the rarity name to its corresponding number, where Junk has numerical equivalent of 0, up to Unique as 7.

Used by draw_socket_cost_table() in Module:Enchantments to determine the order and css class for each rarity.

Parameters

  • rarity_name - Name of the rarity: Junk, Poor, Common, Uncommon, Rare, Epic, Legend, Unique (not Artifact)

Examples

{{#invoke:Utilities|rarity_name_to_num|Poor}}

Script error: The function "rarity_name_to_num" does not exist.


local p = {}

function p.insert_space_before_capitals(input_text)
	if type(input_text) == "table" and input_text.args then -- if called via wikitext instead of lua
        local frame = input_text
        input_text = frame.args[1]
	end

    -- Add a space before each capital letter that is not the first character
    local output_text = input_text:gsub("(%S)(%u)", "%1 %2")
    return output_text
end

function p.dash_for_space(frame)
    local text = frame.args[1] or ""
    return text:gsub(" ", "-")
end

return p