From 30a3ec195d41609ec5f29277d0f3e5706c973b7a Mon Sep 17 00:00:00 2001 From: tomasklaen Date: Mon, 10 Oct 2022 10:20:46 +0200 Subject: [PATCH] feat: move `@` in control badge props from prefix to suffix for consistency The old `@prop` syntax will still work, but consider it deprecated. --- README.md | 22 ++++++++-------------- scripts/uosc.lua | 4 +++- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 18165e5..1c78e2e 100644 --- a/README.md +++ b/README.md @@ -519,26 +519,14 @@ In your script, set the value of `foo` to `1`. mp.commandv('script-message-to', 'uosc', 'set', 'foo', 1) ``` -This property can now be used as a control button badge by prefixing it with `@`. - -``` -controls=command:icon_name:command_name#@foo?My foo button -``` - -It can also be used as a `toggle` or `cycle` property name by specifying its owner with a `@{script_name}` suffix: +`foo` can now be used as a `toggle` or `cycle` property by specifying its owner with a `@{script_name}` suffix: ``` toggle:icon_name:foo@script_name cycle:icon_name:foo@script_name:no/yes! ``` -If user clicks this `toggle` or `cycle` button, uosc will send this `set` message back to the script owner: - -```lua -mp.commandv('script-message-to', 'script_name', 'set', 'foo', new_value) -``` - -You can then listen to this message, do what you need with the new value, and update uosc state accordingly: +If user clicks this `toggle` or `cycle` button, uosc will send a `set` message back to the script owner. You can then listen to this message, do what you need with the new value, and update uosc state accordingly: ```lua -- Send initial value so that the button has a correct active state @@ -551,6 +539,12 @@ mp.register_script_message('set', function(prop, value) end) ``` +External properties can also be used as control button badges: + +``` +controls=command:icon_name:command_name#foo@script_name?My foo button +``` + ## Why _uosc_? It stood for micro osc as it used to render just a couple rectangles before it grew to what it is today. And now it means a minimalist UI design direction where everything is out of your way until needed. diff --git a/scripts/uosc.lua b/scripts/uosc.lua index 3f9608f..323785a 100644 --- a/scripts/uosc.lua +++ b/scripts/uosc.lua @@ -3438,7 +3438,9 @@ function Controls:register_badge_updater(badge, element) return count end else - if prop:sub(1, 1) == '@' then prop, is_external_prop = prop:sub(2), true end + local parts = split(prop, '@') + -- Support both new `prop@owner` and old `@prop` syntaxes + if #parts > 1 then prop, is_external_prop = parts[1] ~= '' and parts[1] or parts[2], true end serializer = function(value) return value and (type(value) == 'table' and #value or tostring(value)) or nil end end