Sota-Lua-DrawRadii - Draw some circles around you

Discussion in 'Player Created Lua Script Repository' started by John Markus, Aug 21, 2022.

Thread Status:
Not open for further replies.
  1. John Markus

    John Markus Avatar

    Messages:
    305
    Likes Received:
    324
    Trophy Points:
    43
    Gender:
    Male
    Location:
    Tokyo, Japan
    Here's my take on the ShroudWorldToScreenPoint()

    This overbloated script will draw effective ranges of bard skills while in combat (for now)

    https://github.com/John-Markus/Sota...load/v1.1.0/Sota-Lua-DrawRadii-20220821-1.zip

    Notables:
    • Supports all UI languages (including Japanese language mods) for those Lua APIs that return localized strings instead of fixed IDs.
    • Uses additional module loading via assert(loadsafe(text read from file))
    • Uses additional data loading from .json file
     
    Rinaldi, Tirrag and that_shawn_guy like this.
  2. John Markus

    John Markus Avatar

    Messages:
    305
    Likes Received:
    324
    Trophy Points:
    43
    Gender:
    Male
    Location:
    Tokyo, Japan
  3. John Markus

    John Markus Avatar

    Messages:
    305
    Likes Received:
    324
    Trophy Points:
    43
    Gender:
    Male
    Location:
    Tokyo, Japan
    Here are few things that might be useful:
    • data/unique_skills.json: List of skills that are localized uniquely (no two languages have same localization) mapped against the language - Useful for detecting current languages.
    • data/schools_map.json: Skill ID mapped against school of skills - Useful if you want to divide into different functions depending on school of skills.
    • data/skills_map.json: Maps Skill ID to localized Skill name for each languages.
    • data/skills_map_rev.json: Maps localized Skill name to Skill IDs for each languages.
    • importModule function: Let's you read another Lua file (needs absolute paths) and instantiate as object.

    Code:
    function importModule(filename)
        local _path = ShroudLuaPath .. "/Sota-Lua-DrawRadii/modules/lib_" .. filename .. ".lua"
        local file = io.open(_path)
        local data = file:read("*all")
        file:close()
        local obj = assert(loadsafe(data))
        if obj then
            _G["init_" .. filename] = obj
            ShroudConsoleLog("Loaded lua module: " .. filename)
        else
            ShroudConsoleLog("Module Load Failed: " .. _path)
        end
    end
    
    importModule("submodule")
    myobj = init_submodule()
    myobj.somefunction()
    
    Code:
    module = { }
    
    module.somefunction = function(args)
    
    end
    
    return module
    • importJSON: Reads JSON data from file and return as a Lua table (needs absolute paths)
    Code:
    function importJSON(filename)
        local _path = ShroudLuaPath .. "/Sota-Lua-DrawRadii/data/" .. filename
        local file = io.open(_path)
        local data = file:read("*all")
        file:close()
        local _data = json.parse(data)
        if _data then
            ShroudConsoleLog("Loaded JSON data: " .. filename)
            return _data
        end
        ShroudConsoleLog("JSON Load failed: " .. _path)
        return { }
    end
    • Drawing a line using UI.Image
    Code:
    function DrawLine(ui_object, X1, Y1, X2, Y2)
        -- Calculate parameters for rotating and resizing solid texture into lines
        -- Left Top is (0, 0)
        local _size = math.ceil(math.sqrt(math.pow(X2 - X1, 2) + math.pow(Y2 - Y1, 2)))
        local _slope = math.deg(math.atan2(X2 - X1 , Y2 - Y1)) + 270
    
        -- Perform UI object modifications
        ShroudSetPosition    (ui_object, UI.Image, X1, Y1)
        ShroudSetSize        (ui_object, UI.Image, _size, 1)
        ShroudRotateObject   (ui_object, UI.image, _slope)
        ShroudShowObject     (ui_object, UI.Image)
        ShroudSetTransparency(ui_object, UI.Image, 1)
    end
     
    Last edited: Aug 21, 2022
    Rinaldi and Tirrag like this.
  4. Tirrag

    Tirrag Avatar

    Messages:
    857
    Likes Received:
    1,826
    Trophy Points:
    93
    Location:
    Iowa, USA
    great job on this @John Markus! very well thought out addon and seems to work great on all the skills i have tried so far. 100% going to keep this one active :) love that you incorporated the ResoundingReachBonus stat :)
     
    John Markus likes this.
  5. John Markus

    John Markus Avatar

    Messages:
    305
    Likes Received:
    324
    Trophy Points:
    43
    Gender:
    Male
    Location:
    Tokyo, Japan
    It is worth mentioning that ShroudWorldToScreenPoint() returns coordinate system that places (0, 0) on the left bottom.
    You need to reverse the Y axis to convert it to traditional drawing coordinate that has (0, 0) on the left top.
    Code:
        local vOut = ShroudWorldToScreenPoint(x, y, z)
    
        vOut.y = ShroudGetScreenY() - vOut.y
        return vOut
     
    Last edited: Aug 21, 2022
    Tirrag likes this.
Thread Status:
Not open for further replies.