turn off teletype option, navigating function, obs next/prev/reset hotkeys, obs properties with bool frontend

This commit is contained in:
nx 2021-04-27 09:33:39 +01:00
parent 139d4bac27
commit 356582cde2
1 changed files with 75 additions and 85 deletions

View File

@ -1,38 +1,21 @@
obs = obslua
next_newsitem_hotkey_id = obs.OBS_INVALID_HOTKEY_ID
prev_newsitem_hotkey_id = obs.OBS_INVALID_HOTKEY_ID
reset_hotkey_id = obs.OBS_INVALID_HOTKEY_ID
-- Teletype News Ticker Script
-- By Phoebe Zeitler
-- phoebe.zeitler@gmail.com
-- Support: https://obsproject.com/forum/resources/teletype-news-ticker.725/
-- begin properties variables
source_name = ""
file_name = ""
noteletype = true -- teletype effect on/off
teletype_delay_ds = 1
full_display_s = 10
reload_on_loop = true
prefix_chars = ""
use_cursor = false
use_rand_cursor = false
use_cursor_char = "_"
-- end properties variables
-- begin internal use variables
lines_stack = {}
current_delay = 0
current_line = 1
current_char = 1
teletype_mode = false
timer_deployed = false
-- end internal use variables
-- begin user configurable options
default_path = "C:\\"
-- IMPORTANT: use only basic ASCII characters here-- UTF-8 not yet supported
rand_cursor_chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-=+_)(*&^%$#@![]{}|,<.>/? "
-- end user configurable options
-- end user configurable options
-- begin imported functions
@ -77,27 +60,6 @@ function lines_from(file)
return lines
end
--functions courtesy Superlou (modified by Phoebe Zeitler)
--https://github.com/superlou/obs-newsroom/blob/master/dsk_tool.lua
function find_source_by_name_in_list(source_list, name)
for i, source in pairs(source_list) do
local source_name = obs.obs_source_get_name(source)
if source_name == name then
return source
end
end
--print ("Source " .. source_name .. " was not found")
return nil
end
function source_is_active(dsk_name)
local sources = obs.obs_enum_sources()
local dsk = find_source_by_name_in_list(sources, dsk_name)
local is_active = obs.obs_source_active(dsk)
obs.source_list_release(sources)
return is_active
end
-- end imported functions
-- begin OBS required functions
@ -120,14 +82,11 @@ function script_properties()
end
obs.source_list_release(sources)
obs.obs_properties_add_path(props, "file_name", "Source File", obs.OBS_PATH_FILE, "Text Files (*.txt)", default_path)
obs.obs_properties_add_bool(props, "reload_on_loop", "When EOF reached, Reload File")
obs.obs_properties_add_path(props, "file_name", "Source File", obs.OBS_PATH_FILE, "Text Files (*.txt)", nil)
obs.obs_properties_add_int(props, "teletype_delay_ds", "Teletype Delay (0.1 seconds)", 0, 11, 1)
obs.obs_properties_add_int(props, "full_display_s", "Full Line Display Time (seconds)", 1, 31, 1)
obs.obs_properties_add_text(props, "prefix_chars", "Line Prefix Character(s)", obs.OBS_TEXT_DEFAULT)
obs.obs_properties_add_bool(props, "use_cursor", "Use Cursor Trailer Character When Teletyping")
obs.obs_properties_add_bool(props, "use_rand_cursor", "Randomize Cursor Character")
obs.obs_properties_add_text(props, "use_cursor_char", "Static Cursor Character(s)", obs.OBS_TEXT_DEFAULT)
obs.obs_properties_add_int(props, "full_display_s", "Full Line Display Time (seconds)", 1, 60000, 1)
obs.obs_properties_add_bool(props, "teletype", "Teletype effect on/off")
return props
end
@ -135,12 +94,13 @@ end
function script_defaults(settings)
obs.obs_data_set_default_int(settings, "teletype_delay_ds", 1)
obs.obs_data_set_default_int(settings, "full_display_s", 10)
obs.obs_data_set_default_bool(settings, "teletype", ( not noteletype))
end
-- A function named script_description returns the description shown to
-- the user
function script_description()
return "Creates a teletype-effect rotating file reader. \n\nAuthor: Phoebe Zeitler (See source for additional code acknowledgements)"
return "Creates a teletype-effect rotating file reader. \n\nAuthor: Phoebe Zeitler, modifications by Spongycake (See source for additional code acknowledgements)"
end
@ -148,30 +108,58 @@ end
function script_update(settings)
source_name = obs.obs_data_get_string(settings, "source_name")
file_name = obs.obs_data_get_string(settings, "file_name")
reload_on_loop = obs.obs_data_get_bool(settings, "reload_on_loop")
teletype_delay_ds = obs.obs_data_get_int(settings, "teletype_delay_ds")
full_display_s = obs.obs_data_get_int(settings, "full_display_s")
prefix_chars = obs.obs_data_get_string(settings, "prefix_chars")
use_cursor = obs.obs_data_get_bool(settings, "use_cursor")
use_rand_cursor = obs.obs_data_get_bool(settings, "use_rand_cursor")
use_cursor_char = obs.obs_data_get_string(settings, "use_cursor_char")
noteletype = not obs.obs_data_get_bool(settings, "teletype")
reset()
end
function script_load(settings)
--- Register hotkeys
next_newsitem_hotkey_id = obs.obs_hotkey_register_frontend("next_newsitem.trigger", "Move Next News", function(pressed)
navigate_news(pressed, "next")
end)
local next_hotkey_save_array = obs.obs_data_get_array(settings, "next_newsitem.trigger")
obs.obs_hotkey_load(next_newsitem_hotkey_id, next_hotkey_save_array)
obs.obs_data_array_release(next_hotkey_save_array)
prev_newsitem_hotkey_id = obs.obs_hotkey_register_frontend("prev_newsitem.trigger", "Move Prev News", function(pressed)
navigate_news(pressed, "previous")
end)
local prev_hotkey_save_array = obs.obs_data_get_array(settings, "prev_newsitem.trigger")
obs.obs_hotkey_load(prev_newsitem_hotkey_id, prev_hotkey_save_array)
obs.obs_data_array_release(prev_hotkey_save_array)
reset_hotkey_id = obs.obs_hotkey_register_frontend("reset_newsitems.trigger", "Reset News Teletype", reset)
local reset_hotkey_save_array = obs.obs_data_get_array(settings, "reset_newsitems.trigger")
obs.obs_hotkey_load(reset_hotkey_id, reset_hotkey_save_array)
obs.obs_data_array_release(reset_hotkey_save_array)
end
function script_save(settings)
local next_hotkey_save_array = obs.obs_hotkey_save(next_newsitem_hotkey_id)
obs.obs_data_set_array(settings, "next_newsitem.trigger", next_hotkey_save_array)
obs.obs_data_array_release(next_hotkey_save_array)
local prev_hotkey_save_array = obs.obs_hotkey_save(prev_newsitem_hotkey_id)
obs.obs_data_set_array(settings, "prev_newsitem.trigger", prev_hotkey_save_array)
obs.obs_data_array_release(prev_hotkey_save_array)
local reset_hotkey_save_array = obs.obs_hotkey_save(reset_hotkey_id)
obs.obs_data_set_array(settings, "reset_newsitems.trigger", reset_hotkey_save_array)
obs.obs_data_array_release(reset_hotkey_save_array)
end
-- end OBS required functions
-- begin application-specific functions
function reset()
math.randomseed(os.time())
if timer_deployed then
obs.timer_remove(timer_callback)
end
lines_stack = lines_from(file_name)
current_delay = teletype_delay_ds
@ -182,31 +170,25 @@ function reset()
--print("File loaded: " .. file_name)
--print("Lines in file: " .. #lines_stack)
if #lines_stack > 0 then
if #lines_stack > 0 and noteletype == false then
obs.timer_add(timer_callback, 100)
timer_deployed = true
end
end
update_display()
end
function timer_callback()
if not source_is_active(source_name) then
--print("Source " .. source_name .. " is not active")
return
end
current_delay = current_delay - 1
if current_delay <= 0 then
if not teletype_mode then
current_line = current_line + 1
if current_line > #lines_stack then
if reload_on_loop then
lines_stack = lines_from(file_name)
end
current_line = 1
end
current_char = 1
teletype_mode = true
current_delay = teletype_delay_ds
current_char = 1
teletype_mode = true
current_delay = teletype_delay_ds
else
current_char = current_char + 1
if current_char > string.len(lines_stack[current_line]) then
@ -220,15 +202,11 @@ end
function update_display()
local text_to_display = ""
if teletype_mode then
if teletype_mode and noteletype == false then
text_to_display = string.sub(lines_stack[current_line], 1, current_char)
if use_cursor then
text_to_display = text_to_display .. get_cursor_char()
end
else
text_to_display = lines_stack[current_line]
end
text_to_display = prefix_chars .. text_to_display
local source = obs.obs_get_source_by_name(source_name)
if source ~= nil then
local settings = obs.obs_data_create()
@ -239,17 +217,29 @@ function update_display()
end
end
function get_cursor_char()
local retval = use_cursor_char
if use_rand_cursor then
local charnum = math.random(string.len(rand_cursor_chars))
retval = string.sub(rand_cursor_chars, charnum, charnum)
function navigate_news(pressed, direction)
if not pressed then
return
end
if not (type(direction) == "string") then
return nil, "argument must be string"
end
if direction == "next" then
print("go forward")
if #lines_stack > current_line then
current_line = current_line + 1
end
return retval
end
end
if direction == "previous" then
print("go back")
if current_line > 0 then
current_line = current_line -1
end
end
update_display()
end
-- end application-specific functions