Untitled
unknown
lua
a year ago
5.0 kB
6
Indexable
Never
-- addObjectAttribute is an amazing function that adds an attribute to an object. Hold your applause, please. -- @param attributeName: The name of the attribute to add, as a string. Like "chid", which definitely means something important. -- @param attributeFunction: A function that defines what the attribute does. This is the magic potion of our spell. awful.addObjectAttribute = awful.addObjectAttribute or function(attributeName, attributeFunction) -- Some implementation here end -- -------------------------------------------------------------- -- Start: addObjectAttribute for "chid" -- -------------------------------------------------------------- -- Add an attribute named "chid" to an object. -- We are doing something super complicated here. Better sit down for this one. awful.addObjectAttribute("chid", function(obj) -- Check if the object is currently casting a spell. -- This is like asking, "Hey, are you busy throwing some magic around?" if obj.casting then -- If the object is casting, then return the ID of the cast. -- It's like asking for the spell's social security number. return obj.castID end -- Check if the object is channeling a spell. -- This is slightly different from casting; it's like the object is on a call with the spell. if obj.channel then -- If the object is channeling, then return the ID of the channel. -- Again, we are after that social security number, but for the channeling spell this time. return obj.channelID end -- If the object is neither casting nor channeling, we return false. -- Because, you know, we found nothing. Like a detective who lost his magnifying glass. return false end) -- -------------------------------------------------------------- -- End: addObjectAttribute for "chid" -- -------------------------------------------------------------- -- -------------------------------------------------------------- -- Start: addObjectAttribute for "cRemains" -- -------------------------------------------------------------- -- Add an attribute named "cRemains" to an object. -- I bet you can't guess what this one does. I'll give you a hint: it's related to time remaining. awful.addObjectAttribute("cRemains", function(obj) -- Check if the object is currently casting a spell. -- We are back with our casting inquiry. Old habits die hard. if obj.casting then -- If the object is casting, then return the remaining time of the cast. -- This is like asking, "How much longer until your magic trick is done?" return obj.castRemains end -- Check if the object is channeling a spell. -- Oh, look! The channeling question again. Someone give us an award for consistency. if obj.channel then -- If the object is channeling, then return the remaining time of the channel. -- Basically asking, "Are you done talking to that spell yet?" return obj.channelRemains end -- If the object is neither casting nor channeling, we return 0. -- Because 0 is the amount of patience we have left for this object not doing anything magical. return 0 end) -- -------------------------------------------------------------- -- End: addObjectAttribute for "cRemains" -- -------------------------------------------------------------- -- -------------------------------------------------------------- -- Start: addObjectAttribute for "cTotal" -- -------------------------------------------------------------- -- Add an attribute named "cTotal" to an object. -- The grand finale, the pièce de résistance, the third attribute we are adding! awful.addObjectAttribute("cTotal", function(obj) -- Check if the object is currently casting a spell. -- Yes, yes, we are still asking this question. Can't stop, won't stop. if obj.casting then -- If the object is casting, return the total time required for the cast to complete. -- We're essentially asking, "What's the deadline for your magic homework?" return obj.castTimeComplete end -- Check if the object is channeling a spell. -- We've asked this question so many times, the object and the channeling spell are probably BFFs now. if obj.channel then -- If the object is channeling, then return the total time required for the channel to complete. -- Like asking, "How long is this spell phone call going to take?" return obj.channelTimeComplete end -- If the object is neither casting nor channeling, we return 0. -- Zero, zilch, nada, nothing. Just like the number of times this object has impressed us. return 0 end) -- -------------------------------------------------------------- -- End: addObjectAttribute for "cTotal" -- --------------------------------------------------------------