From 29b94274dadac342951879c795e366f0a675ac8c Mon Sep 17 00:00:00 2001 From: raymoo Date: Sat, 9 Jan 2016 02:23:44 -0800 Subject: [PATCH] Change effect_set around --- effect_set.lua | 87 +++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/effect_set.lua b/effect_set.lua index 92809f9..c382f6a 100644 --- a/effect_set.lua +++ b/effect_set.lua @@ -20,8 +20,6 @@ -- -- A duration (duration), either the string "perm" or a number of seconds -- --- The time it started (time_started) --- -- -- Effect Set -- @@ -178,20 +176,15 @@ local function setmap_union(smap1, smap2) end -monoidal_effects.static = 1 -monoidal_effects.dynamic = 2 - - local function record(dyn, effect_type, players, tags, monoids, dur, values) return { dynamic = dyn, effect_type = effect_type, players = players, tags = tags, - monoids = monoids + monoids = monoids, values = values, duration = dur, - time_started = os.time() } end @@ -225,7 +218,7 @@ end -- Returns a set of UIDs that match the given index local function effect_set_index_set(db, table_name, index) - return db.tables[table_name][index] + return db.tables[table_name][index] or {} end @@ -242,40 +235,6 @@ local function fill_tables(db) end end - -local function add_methods(eset) - eset.get = effect_set_get - eset.effects = effect_set_effects - eset.insert = insert_record - eset.delete = delete_record - eset.size = function(self) - return #(self.uid_table) - end - eset.with_index = effect_set_index_set -end - - -local function make_db() - - local db = {} - - db.version = db_version - - db.next_id = 0 - - db.tables = {} - - db.uid_table = {} - db.tables.player = {} - db.tables.tag = {} - db.tables.monoid = {} - db.tables.name = {} - db.tables.perm = {} - - add_methods(db) -end - - -- Mutates the DB to have the new record local function insert_record_with_uid(uid, db, record) db.uid_table[uid] = record @@ -323,6 +282,43 @@ local function delete_record(db, uid) end +local function add_methods(eset) + eset.get = effect_set_get + eset.effects = effect_set_effects + eset.insert = insert_record + eset.delete = delete_record + eset.size = function(self) + return #(self.uid_table) + end + eset.with_index = effect_set_index_set +end + + +local function make_db() + + local db = {} + + db.version = db_version + + db.next_id = 0 + + db.tables = {} + + db.uid_table = {} + db.tables.player = {} + db.tables.tag = {} + db.tables.monoid = {} + db.tables.name = {} + db.tables.perm = {} + + add_methods(db) + + return db +end + + + + local function serialize_effect_set(eset) local serialize_this = shallow_copy(eset.uid_table) @@ -380,5 +376,10 @@ effectset.union = function(es1, es2) return es end +effectset.set_intersect = set_intersect +effectset.set_union = set_union + +effectset.record = record + return effectset