/* * Author: Needles * https://steamcommunity.com/profiles/76561198026257137/ */ ::Debug.Print("*** PURGE"); ::Purge <- {}; ::Purge.Purge <- class { classnameList = null; exceptionList = null; condition = null; event_onPurge = null; constructor() { classnameList = []; exceptionList = []; condition = null; event_onPurge = ::Events.Event(); } function Purge() { foreach (classname in classnameList) { local entity = null; while (entity = Entities.FindByClassname(entity, classname)) { if (exceptionList.find(entity) != null) continue; if (condition != null && condition(entity) == false) continue; event_onPurge.FireListeners({entity = entity}); entity.Destroy(); } } } function AddClassname(classname) { if (classnameList.find(classname) == null) classnameList.append(classname); } function RemoveClassname(classname) { local index = classnameList.find(classname); if (index != null) classnameList.remove(index); } function AddException(entity) { if (exceptionList.find(entity) == null) exceptionList.append(entity); } function RemoveException(entity) { local index = exceptionList.find(entity); if (index != null) exceptionList.remove(index); } function Clear() { classnameList.clear(); exceptionList.clear(); } function SetCondition(func) { condition = func; } } function Purge::QuickPurge(classnameList, condition, callback) { foreach (classname in classnameList) { local entity = null; while (entity = Entities.FindByClassname(entity, classname)) { if (condition != null && condition(entity) == false) continue; if (callback != null) callback(entity); entity.Destroy(); } } }