Nepida
01-15-2008, 10:24 PM
I've gotten frustrated with editing my macros on all of my characters. And because I have some specific macros per character (sequencing tremor totems/earth shocks) I can't have a "master" macro list without editing it for each character. And this is with 5 shaman, I can't image it with multiple classes.
So what I did was make a script (a bash script in linux as a prototype) that would read in a very simple macro template file and output files for each character.
I would like to do it in C or something and have it automatically overwrite (with a backup) of your current macro files, but for now copy/pasting works.
I'm inlining the script because I really don't have anywhere to host it. I dunno if there is any interest but I thought I'd post it.
[code:1]#!/bin/bash
# CAVEATS
# This is currently tuned for 5 characters, so if you have a different number
# then you will need to change the spots indicated by "assumes 5 toons"
#
# There is currently is no protection for going over the 255 character limit
#
# Make sure to back up your macros before you replace them with the auto
# generated ones, I don't want a bug to eliminate your hard work.
# INPUT FILE FORMAT
# NAMES=<name1> <name2> ... <nameN>
# STAR=<name1's target> <name2's target> ... <nameN's target>
# PLUS=<name1's target> <name2's target> ... <nameN's target>
# <macro information>
# NAMES is a list of your characters
# STAR is a list of targets to produce a star formation
# PLUS is a list of target to produce a plus formation
#
#ex:
# STAR (produces a star with chain heal)
# a
#b d
# c e
#
# NAMES=a b c d e
# STAR= c e d b a
# PLUS= b c d e a
#
# STAR: a -> c -> d -> b -> e -> a
# PLUS: a -> b -> c -> d -> e -> a
# SUBSTITUTIONS
# {} are for sequencing
# @ = self
# + = plus neighbor
# * = star neighbor
# : = seperate spells for each toon
# ex (first line is what is in the input file, second is what goes in the output file):
# /say Hi, my name is @.
# a) /say Hi, my name is a.
# b) /say Hi, my name is b.
# c) /say Hi, my name is c.
# d) /say Hi, my name is d.
# e) /say Hi, my name is e.
#
# /cast [target=*] chain heal(rank 1)
# a) /cast [target=c] chain heal(rank 1)
# b) /cast [target=e] chain heal(rank 1)
# c) /cast [target=d] chain heal(rank 1)
# d) /cast [target=b] chain heal(rank 1)
# e) /cast [target=a] chain heal(rank 1)
#
# /cast [target=+] chain heal(rank 1)
# a) /cast [target=b] chain heal(rank 1)
# b) /cast [target=c] chain heal(rank 1)
# c) /cast [target=d] chain heal(rank 1)
# d) /cast [target=e] chain heal(rank 1)
# e) /cast [target=a] chain heal(rank 1)
#
# /castsequence {tremor totem}
# a) /castsequence tremor totem,,,,
# b) /castsequence ,tremor totem,,,
# c) /castsequence ,,tremor totem,,
# d) /castsequence ,,,tremor totem,
# e) /castsequence ,,,,tremor totem
#
# /cast :tremor totem:earthbind totem:stoneskin totem:grounding totem:mana spring totem:
# a) /cast tremor totem
# b) /cast earthbind totem
# c) /cast stoneskin totem
# d) /cast grounding totem
# e) /cast mana spring totem
function name_to_index {
I=1
for N in $NAMES ; do
if [[ $N == $1 ]] ; then
echo $I
return
fi
I=$((I+1))
done
echo 0
return
}
function index_to_star {
I=1
for N in $STAR ; do
if [[ $I -eq $1 ]] ; then
echo $N
return
fi
I=$((I+1))
done
echo ""
return
}
function index_to_plus {
I=1
for N in $PLUS ; do
if [[ $I -eq $1 ]] ; then
echo $N
return
fi
I=$((I+1))
done
echo ""
return
}
function repeat_char {
C=$1
N=$2
for I in $(seq 1 $N) ; do
echo -n "$C"
done
}
function convert_macro {
M=$1
N=$2
I=$(name_to_index $2)
M=${M//\{/$(repeat_char "," $((I-1)))} # assumes 5 toons
M=${M//\}/$(repeat_char "," $((5-I)))} # assumes 5 toons
M=$(echo "$M" | sed 's/:\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):/'"\\$I"'/g') # assumes 5 toons
M=${M//\*/$(index_to_star $I)}
M=${M//\+/$(index_to_plus $I)}
M=${M//\@/$N}
echo "$M"
}
if [[ -z $1 ]] ; then
echo "$0 <input file>"
exit
fi
if [[ ! -f $1 ]] ; then
echo "cannot find file: $1"
exit
fi
NAMES=$(cat $1 | grep NAMES | cut -d = -f 2- | sed 's/"//g')
STAR=$(cat $1 | grep STAR | cut -d = -f 2- | sed 's/"//g')
PLUS=$(cat $1 | grep PLUS | cut -d = -f 2- | sed 's/"//g')
for N in $NAMES ; do
FILE=$1.$N
M=$(cat $1 | grep -v -e NAMES -e STAR -e PLUS)
CM=$(convert_macro "$M" $N)
echo "$CM" > "$FILE"
done
[/code:1]
So what I did was make a script (a bash script in linux as a prototype) that would read in a very simple macro template file and output files for each character.
I would like to do it in C or something and have it automatically overwrite (with a backup) of your current macro files, but for now copy/pasting works.
I'm inlining the script because I really don't have anywhere to host it. I dunno if there is any interest but I thought I'd post it.
[code:1]#!/bin/bash
# CAVEATS
# This is currently tuned for 5 characters, so if you have a different number
# then you will need to change the spots indicated by "assumes 5 toons"
#
# There is currently is no protection for going over the 255 character limit
#
# Make sure to back up your macros before you replace them with the auto
# generated ones, I don't want a bug to eliminate your hard work.
# INPUT FILE FORMAT
# NAMES=<name1> <name2> ... <nameN>
# STAR=<name1's target> <name2's target> ... <nameN's target>
# PLUS=<name1's target> <name2's target> ... <nameN's target>
# <macro information>
# NAMES is a list of your characters
# STAR is a list of targets to produce a star formation
# PLUS is a list of target to produce a plus formation
#
#ex:
# STAR (produces a star with chain heal)
# a
#b d
# c e
#
# NAMES=a b c d e
# STAR= c e d b a
# PLUS= b c d e a
#
# STAR: a -> c -> d -> b -> e -> a
# PLUS: a -> b -> c -> d -> e -> a
# SUBSTITUTIONS
# {} are for sequencing
# @ = self
# + = plus neighbor
# * = star neighbor
# : = seperate spells for each toon
# ex (first line is what is in the input file, second is what goes in the output file):
# /say Hi, my name is @.
# a) /say Hi, my name is a.
# b) /say Hi, my name is b.
# c) /say Hi, my name is c.
# d) /say Hi, my name is d.
# e) /say Hi, my name is e.
#
# /cast [target=*] chain heal(rank 1)
# a) /cast [target=c] chain heal(rank 1)
# b) /cast [target=e] chain heal(rank 1)
# c) /cast [target=d] chain heal(rank 1)
# d) /cast [target=b] chain heal(rank 1)
# e) /cast [target=a] chain heal(rank 1)
#
# /cast [target=+] chain heal(rank 1)
# a) /cast [target=b] chain heal(rank 1)
# b) /cast [target=c] chain heal(rank 1)
# c) /cast [target=d] chain heal(rank 1)
# d) /cast [target=e] chain heal(rank 1)
# e) /cast [target=a] chain heal(rank 1)
#
# /castsequence {tremor totem}
# a) /castsequence tremor totem,,,,
# b) /castsequence ,tremor totem,,,
# c) /castsequence ,,tremor totem,,
# d) /castsequence ,,,tremor totem,
# e) /castsequence ,,,,tremor totem
#
# /cast :tremor totem:earthbind totem:stoneskin totem:grounding totem:mana spring totem:
# a) /cast tremor totem
# b) /cast earthbind totem
# c) /cast stoneskin totem
# d) /cast grounding totem
# e) /cast mana spring totem
function name_to_index {
I=1
for N in $NAMES ; do
if [[ $N == $1 ]] ; then
echo $I
return
fi
I=$((I+1))
done
echo 0
return
}
function index_to_star {
I=1
for N in $STAR ; do
if [[ $I -eq $1 ]] ; then
echo $N
return
fi
I=$((I+1))
done
echo ""
return
}
function index_to_plus {
I=1
for N in $PLUS ; do
if [[ $I -eq $1 ]] ; then
echo $N
return
fi
I=$((I+1))
done
echo ""
return
}
function repeat_char {
C=$1
N=$2
for I in $(seq 1 $N) ; do
echo -n "$C"
done
}
function convert_macro {
M=$1
N=$2
I=$(name_to_index $2)
M=${M//\{/$(repeat_char "," $((I-1)))} # assumes 5 toons
M=${M//\}/$(repeat_char "," $((5-I)))} # assumes 5 toons
M=$(echo "$M" | sed 's/:\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):/'"\\$I"'/g') # assumes 5 toons
M=${M//\*/$(index_to_star $I)}
M=${M//\+/$(index_to_plus $I)}
M=${M//\@/$N}
echo "$M"
}
if [[ -z $1 ]] ; then
echo "$0 <input file>"
exit
fi
if [[ ! -f $1 ]] ; then
echo "cannot find file: $1"
exit
fi
NAMES=$(cat $1 | grep NAMES | cut -d = -f 2- | sed 's/"//g')
STAR=$(cat $1 | grep STAR | cut -d = -f 2- | sed 's/"//g')
PLUS=$(cat $1 | grep PLUS | cut -d = -f 2- | sed 's/"//g')
for N in $NAMES ; do
FILE=$1.$N
M=$(cat $1 | grep -v -e NAMES -e STAR -e PLUS)
CM=$(convert_macro "$M" $N)
echo "$CM" > "$FILE"
done
[/code:1]