diff --git a/evoGUI.lua b/evoGUI.lua index d36f8a3..72b9c6b 100644 --- a/evoGUI.lua +++ b/evoGUI.lua @@ -159,6 +159,25 @@ local function update_sensors(element, sensor_list, active_sensors) end +local octant_names = { + [0] = {"direction.east"}, + [1] = {"direction.southeast"}, + [2] = {"direction.south"}, + [3] = {"direction.southwest"}, + [4] = {"direction.west"}, + [5] = {"direction.northwest"}, + [6] = {"direction.north"}, + [7] = {"direction.northeast"}, +} + +function evogui.get_octant_name(vector) + local radians = math.atan2(vector.y, vector.x) + local octant = math.floor( 8 * radians / (2*math.pi) + 8.5 ) % 8 + + return octant_names[octant] +end + + function evogui.update_av(player, element) local always_visible = global.evogui[player.name].always_visible diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg index 1c30c09..96d4a3f 100644 --- a/locale/en/locale.cfg +++ b/locale/en/locale.cfg @@ -57,6 +57,17 @@ settings_in_popup=Visible in popup settings_close=Close +direction.north=N +direction.south=S +direction.east=E +direction.west=W +direction.northeast=NE +direction.northwest=NW +direction.southeast=SE +direction.southwest=SW +direction.unknown=? + + err_generic=[EvoGUI|__1__] Error: __2__ err_specific=[EvoGUI|__1__|__2__] Error: __3__ diff --git a/value_sensors/player_locations.lua b/value_sensors/player_locations.lua index 0c95fca..ee24ea2 100644 --- a/value_sensors/player_locations.lua +++ b/value_sensors/player_locations.lua @@ -58,28 +58,14 @@ end local function directions(source, destination) -- Directions to or from positionless things? Hrm. - if not source.position or not destination.position then return '?' end + if not source.position or not destination.position then return {"direction.unknown"} end local delta_x = destination.position.x - source.position.x local delta_y = destination.position.y - source.position.y - if math.abs(delta_x) > math.abs(delta_y) then - if delta_x < -1 then - return '<' - elseif delta_x > 1 then - return '>' - else - return '=' - end - else - if delta_y < -1 then - return '^' - elseif delta_y > 1 then - return 'v' - else - return '=' - end - end + if math.abs(delta_x) < 2 and math.abs(delta_y) < 2 then return '' end + + return evogui.get_octant_name{x=delta_x, y=delta_y} end