Howdy. Sorry just now seen you replied. I probably should've commented my code explaining it. Basically what the direction2str method does is get the angle you're moving. It's in radians, which is based on PI. So instead of -180 to 180 (degrees), it's -PI to PI (3.14 etc). 0 is right, negative is counter-clockwise to right and positive is clockwise to right.
To make things simple we want to make angle positive, so if it's less than 0, we add 2 * PI to it. So now angle is a value between 0 and 2 * PI. We can then divide it by PI * 4 and round it to get a value between 0 and 7, which correlates to the direction you're facing. 0 being right going clockwise. You then use that value to determine which string in the array you need to use.
As for "idle" and "move", I would have them named like "idle_right" and "move_right" etc. So that you can determine if you're idling or moving, then do something along the lines of:
var suffix = "idle_"
var direction = direction2str(facing)
var animation = suffix + direction # idle_right