-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodec.lua
More file actions
112 lines (95 loc) · 3.15 KB
/
codec.lua
File metadata and controls
112 lines (95 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
local PATH = (...):match("^(.-)[^%.]+$")
local mintmousse = require(PATH .. "conf")
local getDictionary = function()
-- These don't need to be perfect, but a rough idea is good enough
local words = {
"mintmousse",
-- Commands
"func", "args", "batch",
-- Proxy commands, and their arguments
"updateComponent", "id", "index", "value",
"removeComponent", "id",
"setChildrenOrder", "id", "newOrder",
"moveBefore", "id", "siblingID",
"moveAfter", "id", "siblingID",
"moveToFront", "id",
"moveToBack", "id",
"addComponent", "component",
"newTab", "id", "title", "index",
-- ThreadController commands, and their arguments
"start", "config",
"quit",
"addToWhitelist", "additions",
"removeFromWhitelist", "removals",
"clearWhitelist",
"setSchemaIcon", "icon",
"setIconFromFile", "filepath",
"setIconRaw", "icon", "iconType",
"setIconRFG", "filepath",
"setTitle", "title",
"notify", "message", "title", "text",
-- Common Component/UI Keys
"title", -- accordion
"text", "color", "isDismissible", -- alert
"color", "colorOutline", "text", "isDisabled", "width", "isCentered", "click", -- button
"color", "isContentCenter", "borderColor", "title", "text", -- card
"text", "isTransparent", -- cardFooter
"text", "isTransparent", -- cardHeader
"text", -- cardSubtitle,
"text", -- cardText
"text", -- cardTitle
"isNumbered", -- list
"percentage", "showLabel", "ariaLabel", "isStriped", "color", -- progressBar
"columnWidth", -- row
"percentage", -- stackedProgressBar,
"title", "size", -- tab,
"text", -- text
-- Logging
-- Level
"info", "warning", "debug", "error", "fatal",
-- Color
"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white",
"bright_black", "bright_red", "bright_green", "bright_yellow", "bright_blue", "bright_magenta", "bright_cyan", "bright_white",
-- Logger ancestry data
"name", "colorDef"
}
local proxy = require(PATH .. "proxy")
for _, word in ipairs(proxy.getProtectedKeys()) do -- order isn't guaranteed
table.insert(words, word)
end
-- Remove repeating
local dictionary, lookup = { }, { }
for index, word in ipairs(words) do
if not lookup[word] then
lookup[word] = true
table.insert(dictionary, word)
end
end
return dictionary
end
local createBuffer = function()
local channelDictionary = love.thread.getChannel(mintmousse.READONLY_BUFFER_DICTIONARY_ID)
channelDictionary:performAtomic(function()
if not channelDictionary:peek() then
local dictionary = getDictionary()
channelDictionary:push(dictionary)
end
end)
local dictionary = channelDictionary:peek()
local buffer = require("string.buffer").new({
dict = dictionary,
})
return buffer
end
local codec = { }
local bufferEnc
codec.encode = function(message)
if not bufferEnc then bufferEnc = createBuffer() end
return bufferEnc:reset():encode(message):get()
end
local bufferDec
codec.decode = function(encodedMessage)
if not bufferDec then bufferDec = createBuffer() end
return bufferDec:set(encodedMessage):decode()
end
return codec