• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Snippet] Debug

Level 4
Joined
Jun 9, 2011
Messages
91
JASS:
library DebugToolkit 
    /*! by LuizBills | v1.1.0 */ 

    globals
        private constant real MSG_DURATION = 60 // seconds
        
        private constant string COLOR_LOG = "FFFFFF"
        private constant string COLOR_WARN = "FF851B"
        private constant string COLOR_ERROR = "FF4136"
        
        private constant string PREFIX_LOG = ""
        private constant string PREFIX_WARN = "[WARNING] "
        private constant string PREFIX_ERROR = "[ERROR] "
    endglobals

    struct Debug extends array

        // Displays a normal message
        static method log takes string msg returns nothing
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MSG_DURATION, "|cFF" + COLOR_LOG + PREFIX_LOG + msg + "|r")
        endmethod

        // Displays an warning message
        static method warn takes string msg returns nothing
            debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MSG_DURATION, "|cFF" + COLOR_WARN + PREFIX_WARN + msg + "|r")
        endmethod

        // Displays an error message
        static method error takes string msg returns nothing
            debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MSG_DURATION, "|cFF" + COLOR_ERROR + PREFIX_ERROR + msg + "|r")
        endmethod

        /* Displays an error message if the condition is false
         *
         * @param {boolean} A boolean, which references whether your test passed or failed
         * @param {string} A short description of your test
         *
         * @example
         *    ```
         *    call Debug.assert(1 == 1, "it will never be shown")
         *    call Debug.assert(1 == 0, "it will be shown")
         *    ```
         */
        static method assert takes boolean condition, string msg returns nothing
            if (not condition) then
                call thistype.error(msg)
            endif
        endmethod
        
        /*
        static if DEBUG_MODE then
        static method onInit takes nothing returns nothing
            // test
            call thistype.log("foo")
            call thistype.warn("bar")
            call thistype.error("taz")
        endmethod
        endif
        */
    endstruct

endlibrary


v1.0.0
- first release

v1.1.0
- Now "[WARNING] " and "[ERROR] " prefixes are configurables
 
Last edited:
Top