• 🏆 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!

Macro v1.2

  • Macro v1.1
  • Allows users to generate codes or simply generate CnP codes and replaces words with wanted words for much easier replacement. JASS and GUI doesn't have this kind of functionality, so I gave them the ability to do so.
  • Code:
    JASS:
    //*************************************************************************************
    //*
    //*    Macro by Almia
    //*
    //*    Allows users to generate codes or simply generate CnP codes and replaces words
    //*    with wanted words for much easier replacement. JASS and GUI doesn't have this
    //*    kind of functionality, so I gave them the ability to do so. The system is similar
    //*    to vJASS Text Macro though has the following "ugly" features:
    //*        - Macro generates the code outside the map,read the next statement.
    //*        - Codes are generated inside a .bat file and you need to download the
    //*          generated codes from the .bat file.
    //*        - Copy paste generate codes into your map code.
    //*        - Because of these features, it uses Preload.
    //*        - You can't replace the macro variable names,
    //*          all are sequenced with an integer, so you need to use those integers
    //*          instead of these.
    //*
    //*************************************************************************************
    //*
    //*    API
    //*
    //*    function Macro takes nothing returns integer
    //*        Creates a macro instance
    //*
    //*    function MacroAppend takes integer macro, string phrase returns nothing
    //*        Declares a macro phrase
    //*
    //*    function MacroPushArgument takes integer macro, string val returns nothing
    //*        Declares a macro variable's value
    //*
    //*    function MacroParse takes integer macro returns nothing
    //*        Run a macro and generates its code
    //*
    //*    function DownloadMacro takes integer macro returns nothing
    //*        Download generated macro code
    //*    
    //*    function ClearMacro takes integer macro returns nothing
    //*        Clears macro memory 
    //*
    //*    function DestroyMacro takes integer macro returns nothing
    //*        Destroys a macro instance
    //*
    //*************************************************************************************
    //*
    //*    How does Macro works?
    //*
    //*    - First,you need to create a Macro Instance:
    //*        local integer macro = Macro()
    //*    - Do declare phrase use:
    //*        call MacroAppend(whichMacro, "someStatement")
    //*    - Variables are done like these:
    //*      {1}
    //*      {2}
    //*    - Declare a phrase with macro variable
    //*        call MacroAppend(whichMacro, "someSortOfStuffLike{1} or {2}")
    //*    - Those won't be complete without declaring what is the value of the macro variable
    //*        call MacroPushArgument(whichMacro, "This") // replaces {1}
    //*        call MacroPushArgument(whichMacro, "That") // replaces {2}
    //*    - Generate code by running:
    //*        call MacroParse(m)
    //*    - Download code:
    //*        call DownloadMacro(m)
    //*
    //*************************************************************************************
    //*
    //*   About Macro Var
    //*
    //*   Noticed that Macro variables uses integers. Setting macro variable integer's value 
    //*   must be equal to how many times MacroVarSet was called to a given macro.
    //*   For example:
    //*       call MacroPushArgument(whichMacro, "that")
    //*       call MacroPushArgument(whichMacro, "this")
    //*       call MacroPushArgument(whichMacro, "those")
    //*
    //*       "that" replaces {1}, "this" replaces {2}, "those" replaces {3}
    //*   Another example:
    //*       call MacroPushArgument(whichMacro, "hahah")
    //*       call BJDebugMsg("hahah")
    //*       call MacroPushArgument(whichMacro, "hahaha")
    //*
    //*       "hahah" replaces {1} and "hahaha" replaces {2}
    //*
    //*************************************************************************************
    constant function MACRO_FOLDER takes nothing returns string
        return "MacroFiles\\"
    endfunction
    
    constant function MAP_NAME takes nothing returns string
        return "testMap"
    endfunction
    
    function PreloadMacroPhrase takes integer macro, integer key returns string
        local string s = LoadStr(udg_MacroTable, macro, key)
        local integer i = 0
        local integer i2 = StringLength(s)
        local string s2
        local string s3 = ""
        local boolean open = false
        loop
            exitwhen i == i2
            set s2 = SubString(s, i, i + 1)
            if s2 == "{" then
                set open = true
            elseif s2 == "}" then
                set open = false
            elseif open then
                set s3 = s3 + s2
            elseif s3 != "" then
                set s = SubString(s, 0, i - StringLength(s3) - 2) + LoadStr(udg_MacroTable, macro, 8192 + S2I(s3)) + SubString(s, i, i2)
                set i2 = StringLength(s)
                set s3 = ""
            endif
            set i = i + 1
        endloop
        return s
    endfunction
    
    function Macro takes nothing returns integer
        local integer macro = udg_Macro_R[0]
        if 0 == macro then
            set macro = udg_Macro + 1
            set udg_Macro = macro
        else
            set udg_Macro_R[0] = udg_Macro_R[macro]
        endif
        if null == udg_MacroTable then
            set udg_MacroTable = InitHashtable()
            call BJDebugMsg("Note:")
            call BJDebugMsg("All macro files can be found in your Warcraft III folder -> " + MACRO_FOLDER() + MAP_NAME())
        endif
        set udg_Macro_Var[macro] = 0
        set udg_Macro_Phrase[macro] = 0
        set udg_Macro_Use[macro] = 0
        call FlushChildHashtable(udg_MacroTable, macro)
        return macro
    endfunction
    
    function MacroAppend takes integer macro, string phrase returns nothing
        call SaveStr(udg_MacroTable, macro, udg_Macro_Phrase[macro], phrase)
        set udg_Macro_Phrase[macro] = udg_Macro_Phrase[macro] + 1
    endfunction
    
    function MacroPushArgument takes integer macro, string val returns nothing
        set udg_Macro_Var[macro] = udg_Macro_Var[macro] + 1
        call SaveStr(udg_MacroTable, macro, 8192 + udg_Macro_Var[macro], val)
    endfunction
    
    function MacroParse takes integer macro returns nothing
        local integer i = 0
        loop
            exitwhen i == udg_Macro_Phrase[macro]
            call SaveStr(udg_MacroTable, macro, 16384 + (udg_Macro_Use[macro] * udg_Macro_Phrase[macro]) + i, "\")\r\n\techo " + PreloadMacroPhrase(macro, i) + " >> macro" + I2S(macro) + ".txt\r\n\t(\"")
            set i = i + 1
        endloop
        set udg_Macro_Use[macro] = udg_Macro_Use[macro] + 1
        set udg_Macro_Var[macro] = 0
    endfunction
    
    function DownloadMacro takes integer macro returns nothing
        local integer i = 0
        call PreloadGenClear()
        call PreloadGenStart()
        call Preload("\")\r\n\tdel macro" + I2S(macro) + ".txt\r\n\t(\"")
        loop
            exitwhen i == udg_Macro_Use[macro] * udg_Macro_Phrase[macro]
            call Preload(LoadStr(udg_MacroTable, macro, 16384 + i))
            set i = i + 1
        endloop
        call Preload("\")\r\n\tstart macro" + I2S(macro) + ".txt\r\n\t(\"")
        call Preload("\")\r\n\tdel macroDL" + I2S(macro) + ".bat\r\n\t(\"")
        call PreloadGenEnd(MACRO_FOLDER() + MAP_NAME() + "\\macroDL" + I2S(macro) + ".bat")
        set udg_Macro_Use[macro] = 0
    endfunction
    
    function ClearMacro takes integer macro returns nothing
        set udg_Macro_Var[macro] = 0
        set udg_Macro_Preload[macro] = 0
        set udg_Macro_Phrase[macro] = 0
        call FlushChildHashtable(udg_MacroTable, macro)
    endfunction
    
    function DestroyMacro takes integer macro returns nothing
        call ClearMacro(macro)
        set udg_Macro_R[macro] = udg_Macro_R[0]
        set udg_Macro_R[0] = macro
    endfunction
  • Demonstration:
    JASS:
    function Test takes nothing returns nothing
        local integer m = Macro()
        // Declare macro phrases
        call MacroAppend(m, "function Save{1} takes integer t, {2} a returns nothing")
        call MacroAppend(m, "    call Save{1}Handle(ht, t, 0, a)")
        call MacroAppend(m, "endfunction")
        
        //Declare macro variables
        call MacroPushArgument(m, "Unit") // replaces {1}
        call MacroPushArgument(m, "unit") // replaces {2}
        
        //Generate macro code
        call MacroParse(m)
        
        //Declare macro variables
        call MacroPushArgument(m, "Destructable") // replaces {1}
        call MacroPushArgument(m, "destructable") // replaces {2}
        
        //Generate macro code
        call MacroParse(m)
        
        //Download macro code
        call DownloadMacro(m)
        
        //Clear macro memory
        call ClearMacro(m)
        
        //Destroy macro
        call DestroyMacro(m)
    endfunction
    
    //===========================================================================
    function InitTrig_Temp takes nothing returns nothing
        call Test()
    endfunction
  • Changelogs
    - Improved algorithm
    - Now creates only one macro file per macro
    - Added README
Contents

Macro v1.2 (Map)

Reviews
08:25, 26th Jul 2013 Magtheridon96: Approved.
Level 19
Joined
Aug 8, 2007
Messages
2,765
Meh, Very limited usage like the rest of your systems... Compile-time code shouldn't be used anyway because its not filtered through the syntax checker. This system can also not use any vJass or ZINC functions. This is also less efficient than JNGP textmacros because it uses alot of preload functions where JNGP is raw with 0 extra functions.

I'd recommend changing

JASS:
    call MacroVarSet(m, "Destructable") // replaces {1}
    call MacroVarSet(m, "destructable") // replaces {2}

to

JASS:
    call MacroVarSet(m, 1, "Destructable") // replaces {1}
    call MacroVarSet(m, 2, "destructable") // replaces {2}

e/ Oh, your supposed to copy the generated code... I still dont understand this why do you do desktop applications in JASS? its so inefficient.

2e/

Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package easy;

import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;

/**
 *
 * @author Arhowk
 */
public class Easy {

    /**
     * @param args the command line arguments
     */
    public static class Replaceable{
        String term;
        
        public Replaceable(String t){
            term = t;
        }
        
        public String generate(String... args){
            String s = term.substring(0, term.length());
            for(int i = 0; i < args.length; i++){
                s = s.replace("{" + i + "}", args[i]);
            }
            return s;
        }
        
    }
    public static void run(Replaceable s, String... args){
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(s.generate(args)), null);
    }
    public static void main(String[] args) {
        Replaceable s = new Replaceable("function Save{0} takes {1} d returns nothing\n    call Save{0}Handle(ht, t, 0, a)\nendfunction");
        run(s, "Destructable", "destructable");
        // TODO code application logic here
    }
}

No putting it into a new map, running it, getting the bat....

function SaveDestructable takes destructable d returns nothing
call SaveDestructableHandle(ht, t, 0, a)
endfunction
 
Level 33
Joined
Apr 24, 2012
Messages
5,113
Anyways, updating the code just to make the RunMacro write it then downloads the generated macro only one per macro. My algo was that bad first.

@Arhowk
Please just don't show me those codes. All I know was to code JASS, vJASS and Zinc(include VBS and Batch if you want)

edit
Updated. Please view changelogs for details.
 
Last edited:
Top