Created
January 13, 2020 02:15
-
-
Save spotco/e67c4cf82392ce342b5d47983ca0fe9a to your computer and use it in GitHub Desktop.
SPChatCoreScript.ModuleScript.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local DebugOut = require(game.ReplicatedStorage.Local.DebugOut) | |
local StarterGui = game:GetService("StarterGui") | |
local SPChatCorescript = {} | |
function SPChatCorescript:new(_target) | |
local self = {} | |
local _container_table = {} | |
local _fn_on_chatbar_focus_changed | |
local _fn_on_visibility_state_changed | |
local _fn_on_messages_changed | |
local _fn_on_messages_posted | |
function self:cons() | |
_container_table.ChatWindow = {} | |
_container_table.SetCore = {} | |
_container_table.GetCore = {} | |
_container_table.ChatWindow.ChatTypes = {} | |
_container_table.ChatWindow.ChatTypes.BubbleChatEnabled = true | |
_container_table.ChatWindow.ChatTypes.ClassicChatEnabled = true | |
local function ConnectEvent(name, fn) | |
local event = Instance.new("BindableEvent") | |
event.Name = name | |
_container_table.ChatWindow[name] = event | |
event.Event:connect(function(...) fn(...) end) | |
end | |
local function ConnectFunction(name, fn) | |
local func = Instance.new("BindableFunction") | |
func.Name = name | |
_container_table.ChatWindow[name] = func | |
func.OnInvoke = function(...) return fn(...) end | |
end | |
local function ReverseConnectEvent(name) | |
local event = Instance.new("BindableEvent") | |
event.Name = name | |
_container_table.ChatWindow[name] = event | |
return function(...) event:Fire(...) end | |
end | |
local function ConnectSetCore(name, fn) | |
local event = Instance.new("BindableEvent") | |
event.Name = name | |
_container_table.SetCore[name] = event | |
event.Event:connect(function(...) fn(...) end) | |
end | |
local function ConnectGetCore(name, fn) | |
local func = Instance.new("BindableFunction") | |
func.Name = name | |
_container_table.GetCore[name] = func | |
func.OnInvoke = function(...) return fn(...) end | |
end | |
ConnectEvent("ToggleVisibility", function() _target:set_visible(not _target:get_visible()) end) | |
ConnectEvent("SetVisible", function(val) _target:set_visible(val) end) | |
ConnectEvent("FocusChatBar", function(val) _target:focus_chat_bar() end) | |
ConnectEvent("TopbarEnabledChanged", function(val) DebugOut:puts("SPChatCorescript:TopbarEnabledChanged(%s)",tostring(val)) end) | |
ConnectEvent("CoreGuiEnabled", function(val) DebugOut:puts("SPChatCorescript:CoreGuiEnabled(%s)",tostring(val)) end) | |
ConnectFunction("GetVisibility", function() return _target:get_visible() end) | |
ConnectFunction("GetMessageCount", function() return _target:get_message_count() end) | |
ConnectFunction("IsFocused", function() return _target:is_focused() end) | |
_fn_on_chatbar_focus_changed = ReverseConnectEvent("ChatBarFocusChanged") | |
_fn_on_visibility_state_changed = ReverseConnectEvent("VisibilityStateChanged") | |
_fn_on_messages_changed = ReverseConnectEvent("MessagesChanged") | |
_fn_on_messages_posted = ReverseConnectEvent("MessagePosted") | |
ConnectSetCore("ChatMakeSystemMessage", function(val) DebugOut:puts("SPChatCorescript:ChatMakeSystemMessage(%s)", tostring(val)) end) | |
ConnectSetCore("ChatWindowPosition", function(val) DebugOut:puts("SPChatCorescript:ChatMakeSystemMessage(%s)", tostring(val)) end) | |
ConnectSetCore("ChatWindowSize", function(val) DebugOut:puts("SPChatCorescript:ChatMakeSystemMessage(%s)", tostring(val)) end) | |
ConnectSetCore("ChatBarDisabled", function(val) DebugOut:puts("SPChatCorescript:ChatMakeSystemMessage(%s)", tostring(val)) end) | |
ConnectGetCore("ChatWindowPosition", function() return _target:get_position() end) | |
ConnectGetCore("ChatWindowSize", function() return _target:get_size() end) | |
ConnectGetCore("ChatBarDisabled", function() return _target:get_chat_bar_disabled() end) | |
end | |
self:cons() | |
return self | |
end | |
return SPChatCorescript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment