· 4 years ago · Mar 24, 2021, 10:54 PM
1"Lightweight Instance": {
2 "description": "Lightweight Instance Template",
3 "prefix": [ "/instance" ],
4 "body": [
5 "--[[",
6 " $TM_FILENAME",
7 " FriendlyBiscuit",
8 " Created on $CURRENT_MONTH/$CURRENT_DATE/$CURRENT_YEAR @ $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
9 " ",
10 " Description:",
11 " No description provided.",
12 " ",
13 " Documentation:",
14 " No documentation provided.",
15 "--]]",
16 "",
17 "--= Class Base Config =--",
18 "local CLASS_NAME = '$TM_FILENAME_BASE'",
19 "local SHARED = '@shared/'",
20 "local CLASSES = 'classes/'",
21 "local LIB = 'lib/'",
22 "local UTIL = 'util/'",
23 "local CONFIG = 'config/'",
24 "",
25 "--= Module Loader =--",
26 "require(game.ReplicatedStorage:WaitForChild('ModuleLoader'))()",
27 "",
28 "--= Class Root =--",
29 "local $TM_FILENAME_BASE = { }",
30 "$TM_FILENAME_BASE.ClassName = CLASS_NAME",
31 "",
32 "--= Controllers =--",
33 "",
34 "--= Other Classes =--",
35 "",
36 "--= Modules & Config =--",
37 "local resource = require(SHARED .. LIB .. 'Resources')",
38 "local maid = require(SHARED .. LIB .. 'Maid')",
39 "local fetch = require(SHARED .. UTIL .. 'FetchSync')",
40 "local get = require(SHARED .. UTIL .. 'EasyGet')",
41 "local set = require(SHARED .. UTIL .. 'EasySet')",
42 "local map = require(LIB .. 'Math').map",
43 "local spring = require(LIB .. 'Spring')",
44 "local spring_util = require(LIB .. 'SpringUtils')",
45 "local step_util = require(LIB .. 'StepUtils')",
46 "local cache_alpha = require(UTIL .. 'CacheTransparency')",
47 "",
48 "--= Roblox Services =--",
49 "",
50 "--= Instance References =--",
51 "local local_player = game.Players.LocalPlayer",
52 "local player_gui = local_player:WaitForChild('PlayerGui')",
53 "",
54 "--= Constants =--",
55 "local res_key = '$TM_FILENAME_BASE'",
56 "local debug_asset = false",
57 "",
58 "--= Variables =--",
59 "",
60 "--= Shorthands =--",
61 "",
62 "--= Functions =--",
63 "function nil_err()",
64 " error(('Cannot use or modify a %s after you have destroyed it.'):format(CLASS_NAME), 2)",
65 "end",
66 "",
67 "--= Class Properties =--",
68 "$TM_FILENAME_BASE.__properties = {",
69 " PropertyName = {",
70 " get = function(self)",
71 " ",
72 " end,",
73 " set = function(self, value)",
74 " ",
75 " end",
76 " }",
77 "}",
78 "",
79 "--= Internal Property Handler =--",
80 "$TM_FILENAME_BASE.__index = function(self, key)",
81 " local property = rawget($TM_FILENAME_BASE, '__properties')[key]",
82 " ",
83 " if property and property.get then",
84 " return property.get(self)",
85 " elseif rawget($TM_FILENAME_BASE, key) ~= nil then",
86 " return rawget($TM_FILENAME_BASE, key)",
87 " end",
88 " ",
89 " error(('%s is not a member of %s'):format(key, CLASS_NAME), 2)",
90 "end",
91 "",
92 "$TM_FILENAME_BASE.__newindex = function(self, key, value)",
93 " local property = rawget($TM_FILENAME_BASE, '__properties')[key]",
94 " ",
95 " if property then",
96 " if property.set then",
97 " property.set(self, value)",
98 " return",
99 " else",
100 " error(('%s member of %s is read-only.'):format(key, CLASS_NAME), 2)",
101 " end",
102 " end",
103 " ",
104 " rawset(self, key, value)",
105 "end",
106 "",
107 "--= Class Internal =--",
108 "function $TM_FILENAME_BASE:_update()",
109 " local active, p = spring_util.IsAnimating(self._spring)",
110 " local inv = 1 - p",
111 " ",
112 " for object, data in pairs(self._alpha_cache) do",
113 " object.BackgroundTransparency = data[1] + inv",
114 " ",
115 " if data[2] then",
116 " object.ImageTransparency = data[2] + inv",
117 " end",
118 " ",
119 " if data[3] and data[4] then",
120 " object.TextTransparency = data[3] + inv",
121 " object.TextStrokeTransparency = data[4] + inv",
122 " end",
123 " end",
124 " ",
125 " return active",
126 "end",
127 "",
128 "--= Class API =--",
129 "function $TM_FILENAME_BASE:Destroy(animate: bool)",
130 " if animate then",
131 " self._spring.t = 0",
132 " spring_util.WaitForCompletion(self._spring)",
133 " end",
134 " ",
135 " self._maid:Clean()",
136 " ",
137 " for index, _ in pairs(self) do",
138 " self[index] = nil",
139 " end",
140 " ",
141 " setmetatable(self, {",
142 " __index = nil_err,",
143 " __newindex = nil_err",
144 " })",
145 "end",
146 "",
147 "--= Class Constructor =--",
148 "function $TM_FILENAME_BASE.new(parent: Instance)",
149 " local self = setmetatable({ }, $TM_FILENAME_BASE)",
150 " self._maid = maid.new()",
151 " self._spring = spring.new(0)",
152 " self._spring.s = 40",
153 " self._spring.d = 1",
154 " self._animate_main, self._stop_main = step_util.BindToRenderStep(self._update)",
155 " self._instance = debug_asset and player_gui:WaitForChild(res_key) or resource:Fetch('ui/' .. res_key)",
156 " self._instance.Parent = parent and parent or nil",
157 " self._alpha_cache = cache_alpha(self._instance)",
158 " ",
159 " self:_animate_main()",
160 " return self",
161 "end",
162 "",
163 "--= Return Class =--",
164 "return $TM_FILENAME_BASE"
165 ]
166 }