-- Compiled with roblox-ts v3.0.0 local TS = _G[script] local _core = TS.import(script, TS.getModule(script, "@flamework", "core").out) local Modding = _core.Modding local Reflect = _core.Reflect local _utility = TS.import(script, script.Parent.Parent.Parent, "utility") local IsExtended = _utility.IsExtended local ModifyConstructorMethod = _utility.ModifyConstructorMethod local getIdFromSpecifier = TS.import(script, TS.getModule(script, "@flamework", "components").out.utility).getIdFromSpecifier local INJECT_KEY = "Inject-tycoon" local context = nil -- eslint-disable-next-line @typescript-eslint/no-explicit-any local DefineContext = function(component) context = component end local ClearContext = function() context = nil return context end --* @metadata flamework:type local InjectTycoon = function(ctor, property) local injectedType = Reflect.getMetadata(ctor, "flamework:type", property) assert(injectedType ~= "" and injectedType, "Injected type not found") local injected = Reflect.getMetadata(ctor, INJECT_KEY) if injected then local _injected = injected local _property = property _injected[_property] = injectedType return nil end injected = {} local _injected = injected local _property = property _injected[_property] = injectedType Reflect.defineMetadata(ctor, INJECT_KEY, injected) ModifyConstructorMethod(ctor, "constructor", function(originalConstructor) return function(self, ...) local args = { ... } if context == nil then return nil end local injectTypes = Reflect.getMetadata(ctor, INJECT_KEY) local myContructor = getmetatable(context) -- ▼ ReadonlyMap.forEach ▼ local _callback = function(injectedType, property) local injectingConstructor = Modding.getObjectFromId(injectedType) local _arg0 = IsExtended(myContructor, injectingConstructor) local _arg1 = `The injected type "{injectedType}" does not extend the current tycoon "{getIdFromSpecifier(myContructor)}" type` assert(_arg0, _arg1) self[property] = context end for _k, _v in injectTypes do _callback(_v, _k, injectTypes) end -- ▲ ReadonlyMap.forEach ▲ ClearContext() return originalConstructor(self, unpack(args)) end end) end return { DefineContext = DefineContext, ClearContext = ClearContext, InjectTycoon = InjectTycoon, }