Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SM64Lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ local views = {
dofile(views_path .. 'Settings.lua'),
dofile(views_path .. 'Tools.lua'),
dofile(views_path .. 'Timer.lua'),
dofile(views_path .. 'Visualizer.lua'),
}

local semantic_workflow = dofile(processors_path .. 'SemanticWorkflow.lua')
Expand Down
34 changes: 19 additions & 15 deletions src/core/Locales.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Locales = {}
---@field public SETTINGS_TAB_NAME string
---@field public TOOLS_TAB_NAME string
---@field public TIMER_TAB_NAME string
---@field public VISUALIZER_TAB_NAME string
---@field public PRESET string
---@field public PRESET_CONTEXT_MENU_DELETE_ALL string
---@field public DISABLED string
Expand Down Expand Up @@ -152,25 +153,28 @@ Locales = {}
---@field public TIMER_RESET string
---@field public TIMER_MANUAL string
---@field public TIMER_AUTO string
---@field public VARWATCH_FACING_YAW_LABEL string
---@field public VARWATCH_FACING_YAW string
---@field public VARWATCH_INTENDED_YAW_LABEL string
---@field public VARWATCH_INTENDED_YAW string
---@field public VARWATCH_H_SPEED_LABEL string
---@field public VARWATCH_H_SPEED string
---@field public VARWATCH_H_SLIDING string
---@field public VARWATCH_Y_SPEED string
---@field public VARWATCH_SPD_EFFICIENCY string
---@field public VARWATCH_POS_X string
---@field public VARWATCH_POS_Y string
---@field public VARWATCH_POS_Z string
---@field public VARWATCH_PITCH string
---@field public VARWATCH_YAW_VEL string
---@field public VARWATCH_PITCH_VEL string
---@field public VARWATCH_XZ_MOVEMENT string
---@field public VARWATCH_ACTION string
---@field public VARWATCH_H_SLIDING_LABEL string
---@field public VARWATCH_Y_SPEED_LABEL string
---@field public VARWATCH_SPD_EFFICIENCY_LABEL string
---@field public VARWATCH_POS_X_LABEL string
---@field public VARWATCH_POS_Y_LABEL string
---@field public VARWATCH_POS_Z_LABEL string
---@field public VARWATCH_PITCH_LABEL string
---@field public VARWATCH_YAW_VEL_LABEL string
---@field public VARWATCH_PITCH_VEL_LABEL string
---@field public VARWATCH_XZ_MOVEMENT_LABEL string
---@field public VARWATCH_ACTION_LABEL string
---@field public VARWATCH_UNKNOWN_ACTION string
---@field public VARWATCH_RNG string
---@field public VARWATCH_RNG_INDEX string
---@field public VARWATCH_GLOBAL_TIMER string
---@field public VARWATCH_DIST_MOVED string
---@field public VARWATCH_RNG_LABEL string
---@field public VARWATCH_RNG_INDEX_LABEL string
---@field public VARWATCH_GLOBAL_TIMER_LABEL string
---@field public VARWATCH_DIST_MOVED_LABEL string
---@field public ADDRESS_USA string
---@field public ADDRESS_JAPAN string
---@field public ADDRESS_SHINDOU string
Expand Down
139 changes: 107 additions & 32 deletions src/core/VarWatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,97 +4,172 @@
-- SPDX-License-Identifier: GPL-2.0-or-later
--

local var_funcs = {
---@alias VarWatchEntry { label: string?, value: string }

VarWatch = {
---@type string[]
processed_values = {},

---@type table<string, fun(): VarWatchEntry>
var_funcs = {},
}

VarWatch.var_funcs = {
['yaw_facing'] = function()
local angle = (Settings.show_effective_angles and Engine.get_effective_angle(Memory.current.mario_facing_yaw) or Memory.current.mario_facing_yaw)
local opposite = (Settings.show_effective_angles and (Engine.get_effective_angle(Memory.current.mario_facing_yaw) + 32768) % 65536 or (Memory.current.mario_facing_yaw + 32768) % 65536)
return string.format(Locales.str('VARWATCH_FACING_YAW'), Formatter.angle(angle), Formatter.angle(opposite))
return {
label = Locales.str('VARWATCH_FACING_YAW_LABEL'),
value = string.format(Locales.str('VARWATCH_FACING_YAW'),
Formatter.angle(angle), Formatter.angle(opposite))
}
end,
['yaw_intended'] = function()
local angle = (Settings.show_effective_angles and Engine.get_effective_angle(Memory.current.mario_intended_yaw) or Memory.current.mario_intended_yaw)
local opposite = (Settings.show_effective_angles and (Engine.get_effective_angle(Memory.current.mario_intended_yaw) + 32768) % 65536 or (Memory.current.mario_intended_yaw + 32768) % 65536)
return string.format(Locales.str('VARWATCH_INTENDED_YAW'), Formatter.angle(angle), Formatter.angle(opposite))
return {
label = Locales.str('VARWATCH_INTENDED_YAW_LABEL'),
value = string.format(
Locales.str('VARWATCH_INTENDED_YAW'), Formatter.angle(angle), Formatter.angle(opposite))
}
end,
['h_spd'] = function()
local h_speed = Memory.current.mario_h_speed
local h_sliding_speed = Engine.GetHSlidingSpeed()
return string.format(Locales.str('VARWATCH_H_SPEED'), Formatter.ups(h_speed), Formatter.ups(h_sliding_speed))
return {
label = Locales.str('VARWATCH_H_SPEED_LABEL'),
value = string.format(Locales.str('VARWATCH_H_SPEED'),
Formatter.ups(h_speed), Formatter.ups(h_sliding_speed))
}
end,
['v_spd'] = function()
local y_speed = Memory.current.mario_v_speed
return string.format(Locales.str('VARWATCH_Y_SPEED'), Formatter.ups(y_speed))
return {
label = Locales.str('VARWATCH_Y_SPEED_LABEL'),
value = Formatter.ups(y_speed)
}
end,
['spd_efficiency'] = function()
local spd_efficiency = Engine.GetSpeedEfficiency()
local percentage = Formatter.percent(spd_efficiency)
local fraction = Formatter.fraction(spd_efficiency, 4)
local full = string.format("%s (%s)", percentage, fraction)

return string.format(Locales.str('VARWATCH_SPD_EFFICIENCY'), full)
return {
label = Locales.str('VARWATCH_SPD_EFFICIENCY_LABEL'),
value = full
}
end,
['position_x'] = function()
return string.format(Locales.str('VARWATCH_POS_X'), Formatter.u(Memory.current.mario_x))
return {
label = Locales.str('VARWATCH_POS_X_LABEL'),
value = Formatter.u(Memory.current.mario_x)
}
end,
['position_y'] = function()
return string.format(Locales.str('VARWATCH_POS_Y'), Formatter.u(Memory.current.mario_y))
return {
label = Locales.str('VARWATCH_POS_Y_LABEL'),
value = Formatter.u(Memory.current.mario_y)
}
end,
['position_z'] = function()
return string.format(Locales.str('VARWATCH_POS_Z'), Formatter.u(Memory.current.mario_z))
return {
label = Locales.str('VARWATCH_POS_Z_LABEL'),
value = Formatter.u(Memory.current.mario_z)
}
end,
['pitch'] = function()
return string.format(Locales.str('VARWATCH_PITCH'), Formatter.angle(Memory.current.mario_pitch))
return {
label = Locales.str('VARWATCH_PITCH_LABEL'),
value = Formatter.angle(Memory.current.mario_pitch)
}
end,
['yaw_vel'] = function()
return string.format(Locales.str('VARWATCH_YAW_VEL'), Formatter.angle(Memory.current.mario_yaw_vel))
return {
label = Locales.str('VARWATCH_YAW_VEL_LABEL'),
value = Formatter.angle(Memory.current.mario_yaw_vel)
}
end,
['pitch_vel'] = function()
return string.format(Locales.str('VARWATCH_PITCH_VEL'), Formatter.angle(Memory.current.mario_pitch_vel))
return {
label = Locales.str('VARWATCH_PITCH_VEL_LABEL'),
value = Formatter.angle(Memory.current.mario_pitch_vel)
}
end,
['xz_movement'] = function()
return string.format(Locales.str('VARWATCH_XZ_MOVEMENT'),
Formatter.u(Engine.get_xz_distance_moved_since_last_frame()))
return {
label = Locales.str('VARWATCH_XZ_MOVEMENT_LABEL'),
value = Formatter.u(Engine.get_xz_distance_moved_since_last_frame())
}
end,
['action'] = function()
local name = Locales.raw().ACTIONS[Memory.current.mario_action]
local fallback = Locales.str('VARWATCH_UNKNOWN_ACTION') .. Memory.current.mario_action
return Locales.str('VARWATCH_ACTION') .. (name or fallback)
return {
label = Locales.str('VARWATCH_ACTION_LABEL'),
value = (name or fallback)
}
end,
['rng'] = function()
return Locales.str('VARWATCH_RNG') ..
Memory.current.rng_value ..
' (' .. Locales.str('VARWATCH_RNG_INDEX') .. RNG.get_index(Memory.current.rng_value) .. ')'
return {
label = Locales.str('VARWATCH_RNG_LABEL'),
value = string.format("%d (%s %d)",
Memory.current.rng_value,
Locales.str('VARWATCH_RNG_INDEX_LABEL'),
RNG.get_index(Memory.current.rng_value))
}
end,
['global_timer'] = function()
return string.format(Locales.str('VARWATCH_GLOBAL_TIMER'), (Memory.current.mario_global_timer))
return {
label = Locales.str('VARWATCH_GLOBAL_TIMER_LABEL'),
value = tostring(Memory.current.mario_global_timer)
}
end,
['moved_dist'] = function()
local dist = Settings.track_moved_distance and Engine.get_distance_moved() or Settings.moved_distance
return string.format(Locales.str('VARWATCH_DIST_MOVED'), Formatter.u(dist))
return {
label = Locales.str('VARWATCH_DIST_MOVED_LABEL'),
value = Formatter.u(dist)
}
end,
['atan_basic'] = function()
return string.format('E: %s R: %s D: %s N: %s', Settings.atan_exp,
MoreMaths.round(Settings.tas.atan_r, Settings.format_decimal_points),
MoreMaths.round(Settings.tas.atan_d, Settings.format_decimal_points),
MoreMaths.round(Settings.tas.atan_n, Settings.format_decimal_points)
)
return {
value = string.format('E: %s R: %s D: %s N: %s', Settings.atan_exp,
MoreMaths.round(Settings.tas.atan_r, Settings.format_decimal_points),
MoreMaths.round(Settings.tas.atan_d, Settings.format_decimal_points),
MoreMaths.round(Settings.tas.atan_n, Settings.format_decimal_points)
)
}
end,
['atan_start_frame'] = function()
return 'S: ' .. math.floor(Settings.tas.atan_start + 1)
return {
value = 'S: ' .. math.floor(Settings.tas.atan_start + 1)
}
end,
}
VarWatch = {
processed_values = {},
}


VarWatch_compute_value = function(key)
return var_funcs[key]()
return VarWatch.var_funcs[key]()
end

VarWatch_update = function()
VarWatch.processed_values = {}
for key, value in pairs(Settings.variables) do
if value.visible then
VarWatch.processed_values[#VarWatch.processed_values + 1] = var_funcs[value.identifier]()
if not value.visible then
goto continue
end

local entry = VarWatch.var_funcs[value.identifier]()

local str
if entry.label then
str = string.format('%s: %s', entry.label, entry.value)
else
str = entry.value
end
VarWatch.processed_values[#VarWatch.processed_values + 1] = str

::continue::
end
end
51 changes: 29 additions & 22 deletions src/res/lang/en_US.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ return {
SETTINGS_TAB_NAME = 'Settings',
TOOLS_TAB_NAME = 'Tools',
TIMER_TAB_NAME = 'Timer',
VISUALIZER_TAB_NAME = 'Visualizer',
PRESET = 'Preset ',
-- Preset Context Menu
PRESET_CONTEXT_MENU_DELETE_ALL = 'Delete All',
Expand Down Expand Up @@ -130,7 +131,8 @@ This action cannot be undone.
SETTINGS_VISUALS_NOTIFICATIONS = 'Notifications',
SETTINGS_VISUALS_NOTIFICATIONS_BUBBLE = 'Bubble',
SETTINGS_VISUALS_NOTIFICATIONS_CONSOLE = 'Console',
SETTINGS_VISUALS_NOTIFICATIONS_TOOLTIP = 'The style used for notifications.\n Bubble: Show notifications over the game.\n Console: Show notifications in the Lua console.',
SETTINGS_VISUALS_NOTIFICATIONS_TOOLTIP =
'The style used for notifications.\n Bubble: Show notifications over the game.\n Console: Show notifications in the Lua console.',
SETTINGS_VISUALS_FF_FPS = 'FPS during Fast-Forward',
SETTINGS_VISUALS_FF_FPS_TOOLTIP = 'The FPS to render at when fast-forwarding. Decrease to increase performance.',
SETTINGS_VISUALS_UPDATE_EVERY_VI = 'Update every VI',
Expand All @@ -144,12 +146,14 @@ This action cannot be undone.
SETTINGS_VARWATCH_ANGLE_FORMAT_SHORT = 'Short',
SETTINGS_VARWATCH_ANGLE_FORMAT_DEGREE = 'Degree',
SETTINGS_VARWATCH_DECIMAL_POINTS = 'Decimal points',
SETTINGS_VARWATCH_ANGLE_FORMAT_TOOLTIP = 'The formatting style for angle variables.\n Short: Formats angles like signed shorts (0-65535)\n Degree: Formats angles in degrees (0-360)',
SETTINGS_VARWATCH_ANGLE_FORMAT_TOOLTIP =
'The formatting style for angle variables.\n Short: Formats angles like signed shorts (0-65535)\n Degree: Formats angles in degrees (0-360)',
SETTINGS_VARWATCH_DECIMAL_POINTS_TOOLTIP = 'The maximum number of decimal places displayed in numbers.',
SETTINGS_VARWATCH_SPD_EFFICIENCY = 'Speed Efficiency Visualization',
SETTINGS_VARWATCH_SPD_EFFICIENCY_PERCENTAGE = 'Percentage',
SETTINGS_VARWATCH_SPD_EFFICIENCY_FRACTION = 'Fraction',
SETTINGS_VARWATCH_SPD_EFFICIENCY_TOOLTIP = 'The formatting style for the speed efficiency variable.\n Percentage: Shows the speed efficiency as a percentage (0-100%)\n Fraction: Shows the speed efficiency as a mathematical fraction (e.g. 1/4)',
SETTINGS_VARWATCH_SPD_EFFICIENCY_TOOLTIP =
'The formatting style for the speed efficiency variable.\n Percentage: Shows the speed efficiency as a percentage (0-100%)\n Fraction: Shows the speed efficiency as a mathematical fraction (e.g. 1/4)',
SETTINGS_MEMORY_FILE_SELECT = 'Select map file...',
SETTINGS_MEMORY_DETECT_NOW = 'Autodetect now',
SETTINGS_MEMORY_DETECT_ON_START = 'Autodetect on start',
Expand Down Expand Up @@ -189,25 +193,28 @@ This action cannot be undone.
TIMER_MANUAL = 'Manual',
TIMER_AUTO = 'Auto',
-- Varwatch
VARWATCH_FACING_YAW = 'Facing Yaw: %s (O: %s)',
VARWATCH_INTENDED_YAW = 'Intended Yaw: %s (O: %s)',
VARWATCH_H_SPEED = 'H Spd: %s (S: %s)',
VARWATCH_H_SLIDING = 'H Sliding Spd: %s',
VARWATCH_Y_SPEED = 'Y Spd: %s',
VARWATCH_SPD_EFFICIENCY = 'Spd Efficiency: %s',
VARWATCH_POS_X = 'X: %s',
VARWATCH_POS_Y = 'Y: %s',
VARWATCH_POS_Z = 'Z: %s',
VARWATCH_PITCH = 'Pitch: %s',
VARWATCH_YAW_VEL = 'Yaw Vel: %s',
VARWATCH_PITCH_VEL = 'Pitch Vel: %s',
VARWATCH_XZ_MOVEMENT = 'XZ Movement: %s',
VARWATCH_ACTION = 'Action: ',
VARWATCH_UNKNOWN_ACTION = 'Unknown action ',
VARWATCH_RNG = 'RNG: ',
VARWATCH_RNG_INDEX = 'Index: ',
VARWATCH_GLOBAL_TIMER = 'Global Timer: %s',
VARWATCH_DIST_MOVED = 'Dist Moved: %s',
VARWATCH_FACING_YAW_LABEL = "Facing Yaw",
VARWATCH_FACING_YAW = '%s (O: %s)',
VARWATCH_INTENDED_YAW_LABEL = "Intended Yaw",
VARWATCH_INTENDED_YAW = '%s (O: %s)',
VARWATCH_H_SPEED_LABEL = "H Spd",
VARWATCH_H_SPEED = '%s (S: %s)',
VARWATCH_H_SLIDING_LABEL = 'H Sliding Spd',
VARWATCH_Y_SPEED_LABEL = 'Y Spd',
VARWATCH_SPD_EFFICIENCY_LABEL = 'Spd Efficiency',
VARWATCH_POS_X_LABEL = 'X',
VARWATCH_POS_Y_LABEL = 'Y',
VARWATCH_POS_Z_LABEL = 'Z',
VARWATCH_PITCH_LABEL = 'Pitch',
VARWATCH_YAW_VEL_LABEL = 'Yaw Vel',
VARWATCH_PITCH_VEL_LABEL = 'Pitch Vel',
VARWATCH_XZ_MOVEMENT_LABEL = 'XZ Movement',
VARWATCH_ACTION_LABEL = 'Action',
VARWATCH_RNG_LABEL = 'RNG',
VARWATCH_RNG_INDEX_LABEL = 'Index',
VARWATCH_GLOBAL_TIMER_LABEL = 'Global Timer',
VARWATCH_DIST_MOVED_LABEL = 'Dist Moved',
VARWATCH_UNKNOWN_ACTION = 'unknown action',
-- Memory addresses
ADDRESS_USA = 'USA',
ADDRESS_JAPAN = 'Japan',
Expand Down
1 change: 1 addition & 0 deletions src/res/lang/fr_FR.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ return {
SETTINGS_TAB_NAME = 'Paramètres',
TOOLS_TAB_NAME = 'Outils',
TIMER_TAB_NAME = 'Chronomètre',
VISUALIZER_TAB_NAME = 'Visualiseur',
PRESET = 'Préréglage ',
-- Preset Context Menu
PRESET_CONTEXT_MENU_DELETE_ALL = 'Tout supprimer',
Expand Down
Loading