Skip to content

Commit

Permalink
proxy property fixes
Browse files Browse the repository at this point in the history
promote ExpressionOnHide to code_proxy panel class

if luapad is active, mirror changes from normal property text field to the luapad screen (the link is now bidirectional)

convert vectors when pasting so they work out of the box with commas and no unnecessary trailing zeros, this is also to prevent an error where it tried to string trim a vector
  • Loading branch information
pingu7867 committed Dec 25, 2024
1 parent 6546e12 commit 2c9dd52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lua/pac3/core/client/parts/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BUILDER:StartStorableVars()
BUILDER:GetSet("PreviewOutput", false, {description = "Previews the proxy's output (for yourself) next to the nearest owner entity in the game"})

BUILDER:SetPropertyGroup("extra expressions")
BUILDER:GetSet("ExpressionOnHide", "", {description = "Math to apply once, when the proxy is hidden. It computes once, so it will not move."})
BUILDER:GetSet("ExpressionOnHide", "", {description = "Math to apply once, when the proxy is hidden. It computes once, so it will not move.", editor_panel = "code_proxy"})
BUILDER:GetSet("Extra1", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra1() or var1() to save space, or by another proxy as extra1(\"uid or name\") or var1(\"uid or name\")", editor_panel = "code_proxy"})
BUILDER:GetSet("Extra2", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra2() or var2() to save space, or by another proxy as extra2(\"uid or name\") or var2(\"uid or name\")", editor_panel = "code_proxy"})
BUILDER:GetSet("Extra3", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra3() or var3() to save space, or by another proxy as extra3(\"uid or name\") or var3(\"uid or name\")", editor_panel = "code_proxy"})
Expand Down Expand Up @@ -1596,6 +1596,13 @@ local allowed = {

function PART:SetExpression(str, slot)
str = string.Trim(str,"\n")
if self == pace.current_part and (pace.ActiveSpecialPanel and pace.ActiveSpecialPanel.luapad) and str ~= "" then
--update luapad text if we update the expression from the properties
if slot == pace.ActiveSpecialPanel.luapad.keynumber then --this check prevents cross-contamination
pace.ActiveSpecialPanel.luapad:SetText(str)
end
end

if not slot then --that's the default expression
self.Expression = str
self.ExpressionFunc = nil
Expand Down Expand Up @@ -1660,31 +1667,26 @@ function PART:SetExpression(str, slot)
end

function PART:SetExpressionOnHide(str)
str = string.Trim(str,"\n")
self.ExpressionOnHide = str
self:SetExpression(str, 0)
end

function PART:SetExtra1(str)
str = string.Trim(str,"\n")
self.Extra1 = str
self:SetExpression(str, 1)
end

function PART:SetExtra2(str)
str = string.Trim(str,"\n")
self.Extra2 = str
self:SetExpression(str, 2)
end

function PART:SetExtra3(str)
str = string.Trim(str,"\n")
self.Extra3 = str
self:SetExpression(str, 3)
end

function PART:SetExtra4(str)
str = string.Trim(str,"\n")
self.Extra4 = str
self:SetExpression(str, 4)
end
Expand Down
18 changes: 18 additions & 0 deletions lua/pac3/editor/client/panels/extra_properties.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,15 @@ do -- script proxy
if isnumber(value) then
-- visually round numbers so 0.6 doesn't show up as 0.600000000001231231 on wear
value = math.Round(value, 7)
elseif isvector(var) then
var = math.Round(var.x,3) .. "," .. math.Round(var.y,3) .. "," .. math.Round(var.z,3)
value = var
elseif isangle(var) then
var = math.Round(var.p,3) .. "," .. math.Round(var.y,3) .. "," .. math.Round(var.r,3)
value = var
elseif IsColor(var) then
var = math.Round(var.r,3) .. "," .. math.Round(var.g,3) .. "," .. math.Round(var.b,3)
value = var
end
local str = tostring(value)
local original_str = string.Trim(str,"\n")
Expand Down Expand Up @@ -1111,6 +1120,15 @@ do -- script proxy
frame:SetSizable(true)

local editor = vgui.Create("pace_luapad", frame)
local slots = {
["ExpressionOnHide"] = 0,
["Extra1"] = 1,
["Extra2"] = 2,
["Extra3"] = 3,
["Extra4"] = 4,
["Extra5"] = 5,
}
editor.keynumber = slots[self.CurrentKey]
frame.luapad = editor
install_fontsize_buttons(frame, editor)
editor:Dock(FILL)
Expand Down

0 comments on commit 2c9dd52

Please sign in to comment.