Skip to content

Commit

Permalink
Convert remaining entities to use entity definition macros
Browse files Browse the repository at this point in the history
  • Loading branch information
boskoramen committed Oct 3, 2024
1 parent 402d83c commit d704403
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 374 deletions.
1 change: 0 additions & 1 deletion code/datums/_ndatabase/subsystems/entity_manager.dm
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ GLOBAL_REAL(SSentity_manager, /datum/controller/subsystem/entity_manager)
if(entity_meta.key_field)
adapter.sync_index("keyfield_index_[entity_meta.key_field::name]", entity_meta.table_name, list(entity_meta.key_field::name), TRUE, TRUE)


/datum/controller/subsystem/entity_manager/fire(resumed = FALSE)
if (!resumed)
currentrun = tables_unsorted.Copy()
Expand Down
63 changes: 18 additions & 45 deletions code/datums/entities/chemical_information.dm
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
/datum/entity/chemical_information
var/nutriment_factor
var/custom_metabolism
var/overdose
var/overdose_critical
var/color
var/explosive
var/power
var/falloff_modifier
var/chemfiresupp
var/intensitymod
var/durationmod
var/radiusmod
var/burncolor
var/burncolormod
var/properties_text
var/spent_chemical

DEFINE_ENTITY(chemical_information, "chemical_information")
var/list/properties
FIELD_STRING_SMALL(chemical_information, color)
FIELD_INT(chemical_information, explosive)
FIELD_DECIMAL(chemical_information, power)
FIELD_DECIMAL(chemical_information, falloff_modifier)
FIELD_INT(chemical_information, chemfiresupp)
FIELD_DECIMAL(chemical_information, intensitymod)
FIELD_DECIMAL(chemical_information, durationmod)
FIELD_DECIMAL(chemical_information, radiusmod)
FIELD_STRING_SMALL(chemical_information, burncolor)
FIELD_INT(chemical_information, burncolormod)
FIELD_STRING_MAX(chemical_information, properties_text)
FIELD_INT(chemical_information, spent_chemical)

/datum/entity_meta/chemical_information
entity_type = /datum/entity/chemical_information
table_name = "chemical_information"
field_typepaths = list(
"nutriment_factor" = DB_FIELDTYPE_DECIMAL,
"custom_metabolism" = DB_FIELDTYPE_DECIMAL,
"overdose" = DB_FIELDTYPE_INT,
"overdose_critical" = DB_FIELDTYPE_INT,
"color" = DB_FIELDTYPE_STRING_SMALL,
"explosive" = DB_FIELDTYPE_INT,
"power" = DB_FIELDTYPE_DECIMAL,
"falloff_modifier" = DB_FIELDTYPE_DECIMAL,
"chemfiresupp" = DB_FIELDTYPE_INT,
"intensitymod" = DB_FIELDTYPE_DECIMAL,
"durationmod" = DB_FIELDTYPE_DECIMAL,
"radiusmod" = DB_FIELDTYPE_DECIMAL,
"burncolor" = DB_FIELDTYPE_STRING_SMALL,
"burncolormod" = DB_FIELDTYPE_INT,
"properties_text" = DB_FIELDTYPE_STRING_MAX,
"spent_chemical" = DB_FIELDTYPE_INT,
)

/datum/entity_meta/chemical_information/map(datum/entity/chemical_information/ET, list/values)
/datum/entity_meta/chemical_information/map(datum/entity/chemical_information/entity, list/values)
..()
if(values["properties_text"])
ET.properties = json_decode(values["properties_text"])
entity.properties = json_decode(values["properties_text"])

/datum/entity_meta/chemical_information/unmap(datum/entity/chemical_information/ET)
/datum/entity_meta/chemical_information/unmap(datum/entity/chemical_information/entity)
. = ..()
if(length(ET.properties))
.["properties_text"] = json_encode(ET.properties)
if(length(entity.properties))
.["properties_text"] = json_encode(entity.properties)
2 changes: 0 additions & 2 deletions code/datums/entities/discord_link.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ KEY_FIELD(discord_link, discord_id)
parent_entity = /datum/entity/player
child_entity = /datum/entity/discord_link
child_foreign_key = "player_id"


30 changes: 8 additions & 22 deletions code/datums/entities/login_triplets.dm
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
/datum/entity/login_triplet
var/ckey
var/ip1
var/ip2
var/ip3
var/ip4

var/last_known_cid
var/login_date

/datum/entity_meta/login_triplet
entity_type = /datum/entity/login_triplet
table_name = "login_triplets"
field_typepaths = list(
"ckey" = DB_FIELDTYPE_STRING_MEDIUM,
"ip1" = DB_FIELDTYPE_INT,
"ip2" = DB_FIELDTYPE_INT,
"ip3" = DB_FIELDTYPE_INT,
"ip4" = DB_FIELDTYPE_INT,
"last_known_cid" = DB_FIELDTYPE_STRING_SMALL,
"login_date" = DB_FIELDTYPE_DATE,
)
DEFINE_ENTITY(login_triplet, "login_triplets")
FIELD_STRING_MEDIUM(login_triplet, ckey)
FIELD_INT(login_triplet, ip1)
FIELD_INT(login_triplet, ip2)
FIELD_INT(login_triplet, ip3)
FIELD_INT(login_triplet, ip4)
FIELD_STRING_SMALL(login_triplet, last_known_cid)
FIELD_DATE(login_triplet, login_date)

/datum/view_record/login_triplet
var/ckey
Expand Down
16 changes: 4 additions & 12 deletions code/datums/entities/map_votes.dm
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/datum/entity/map_vote
var/map_name
var/total_votes


/datum/entity_meta/map_vote
entity_type = /datum/entity/map_vote
table_name = "map_vote"
field_typepaths = list(
"map_name"=DB_FIELDTYPE_STRING_LARGE,
"total_votes"=DB_FIELDTYPE_BIGINT,
)
DEFINE_ENTITY(map_vote, "map_vote")
FIELD_STRING_LARGE(map_vote, map_name)
FIELD_BIGINT(map_vote, total_votes)

// TODO: have this handled automatically by virtue of type (deserialization)
/datum/entity_meta/map_vote/on_read(datum/entity/map_vote/vote)
vote.total_votes = text2num("[vote.total_votes]")
16 changes: 4 additions & 12 deletions code/datums/entities/mc_controller.dm
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
/datum/entity/mc_controller
var/controller_type
var/wait_time

/datum/entity_meta/mc_controller
entity_type = /datum/entity/mc_controller
table_name = "mc_controller"
key_field = "controller_type"
field_typepaths = list(
"controller_type"=DB_FIELDTYPE_STRING_LARGE,
"wait_time"=DB_FIELDTYPE_INT,
)
DEFINE_ENTITY(mc_controller, "mc_controller")
FIELD_STRING_LARGE(mc_controller, controller_type)
FIELD_INT(mc_controller, wait_time)
KEY_FIELD(mc_controller, controller_type)
20 changes: 5 additions & 15 deletions code/datums/entities/mc_record.dm
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
/datum/entity/mc_record
var/round_time
var/round_id
var/controller_id
var/time_taken

/datum/entity_meta/mc_record
entity_type = /datum/entity/mc_record
table_name = "mc_record"
field_typepaths = list(
"round_time"=DB_FIELDTYPE_BIGINT,
"round_id"=DB_FIELDTYPE_BIGINT,
"controller_id"=DB_FIELDTYPE_BIGINT,
"time_taken"=DB_FIELDTYPE_INT,
)
DEFINE_ENTITY(mc_record, "mc_record")
FIELD_BIGINT(mc_record, round_time)
FIELD_BIGINT(mc_record, round_id)
FIELD_BIGINT(mc_record, controller_id)
FIELD_INT(mc_record, time_taken)
11 changes: 2 additions & 9 deletions code/datums/entities/mc_round.dm
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
/datum/entity/mc_round
var/map_name

/datum/entity_meta/mc_round
entity_type = /datum/entity/mc_round
table_name = "mc_round"
field_typepaths = list(
"map_name"=DB_FIELDTYPE_STRING_LARGE,
)
DEFINE_ENTITY(mc_round, "mc_round")
FIELD_STRING_LARGE(mc_round, map_name)
26 changes: 7 additions & 19 deletions code/datums/entities/mc_timing_info.dm
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
/datum/entity/mc_timing_info
var/round_id
var/round_time
var/client_count
var/human_count
var/xeno_count
var/total_time_taken

/datum/entity_meta/mc_timing_info
entity_type = /datum/entity/mc_timing_info
table_name = "mc_timing_info"
field_typepaths = list(
"round_id"=DB_FIELDTYPE_BIGINT,
"round_time"=DB_FIELDTYPE_INT,
"client_count"=DB_FIELDTYPE_INT,
"human_count"=DB_FIELDTYPE_INT,
"xeno_count"=DB_FIELDTYPE_INT,
"total_time_taken"=DB_FIELDTYPE_BIGINT,
)
DEFINE_ENTITY(mc_timing_info, "mc_timing_info")
FIELD_BIGINT(mc_timing_info, round_id)
FIELD_INT(mc_timing_info, round_time)
FIELD_INT(mc_timing_info, client_count)
FIELD_INT(mc_timing_info, human_count)
FIELD_INT(mc_timing_info, xeno_count)
FIELD_BIGINT(mc_timing_info, total_time_taken)
86 changes: 24 additions & 62 deletions code/datums/entities/player.dm
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
#define MINUTES_STAMP ((world.realtime / 10) / 60)

/datum/entity/player
var/ckey
var/last_known_ip
var/last_known_cid

var/whitelist_status
var/whitelist_flags

var/discord_link_id

var/last_login

var/is_permabanned = FALSE
var/permaban_reason
var/permaban_date
var/permaban_admin_id

var/is_time_banned = FALSE
var/time_ban_reason
var/time_ban_admin_id
var/time_ban_expiration
var/time_ban_date

var/migrated_notes = FALSE
var/migrated_bans = FALSE
var/migrated_jobbans = FALSE

var/stickyban_whitelisted = FALSE

var/byond_account_age
var/first_join_date


// UNTRACKED FIELDS
DEFINE_ENTITY(player, "players")
var/name // Used for NanoUI statistics menu

var/warning_count = 0
Expand All @@ -44,6 +11,7 @@
var/migrating_notes = FALSE
var/migrating_bans = FALSE
var/migrating_jobbans = FALSE
var/whitelist_flags

var/datum/entity/discord_link/discord_link
var/datum/entity/player/permaban_admin
Expand All @@ -54,37 +22,31 @@
var/list/datum/entity/player_stat/stats
var/list/playtime_data // For the NanoUI menu
var/client/owning_client
FIELD_STRING_MEDIUM(player, ckey)
FIELD_STRING_SMALL(player, last_known_ip)
FIELD_STRING_SMALL(player, last_known_cid)
FIELD_STRING_LARGE(player, last_login)
FIELD_DEFAULT_VALUE_INT(player, is_permabanned, FALSE)
FIELD_STRING_MAX(player, permaban_reason)
FIELD_STRING_LARGE(player, permaban_date)
FIELD_STRING_MAX(player, whitelist_status)
FIELD_BIGINT(player, discord_link_id)
FIELD_BIGINT(player, permaban_admin_id)
FIELD_DEFAULT_VALUE_INT(player, is_time_banned, FALSE)
FIELD_STRING_MAX(player, time_ban_reason)
FIELD_BIGINT(player, time_ban_expiration)
FIELD_BIGINT(player, time_ban_admin_id)
FIELD_STRING_LARGE(player, time_ban_date)
FIELD_DEFAULT_VALUE_INT(player, migrated_notes, FALSE)
FIELD_DEFAULT_VALUE_INT(player, migrated_bans, FALSE)
FIELD_DEFAULT_VALUE_INT(player, migrated_jobbans, FALSE)
FIELD_DEFAULT_VALUE_INT(player, stickyban_whitelisted, FALSE)
FIELD_STRING_MEDIUM(player, byond_account_age)
FIELD_STRING_MEDIUM(player, first_join_date)
KEY_FIELD(player, ckey)

BSQL_PROTECT_DATUM(/datum/entity/player)

/datum/entity_meta/player
entity_type = /datum/entity/player
table_name = "players"
key_field = "ckey"
field_typepaths = list(
"ckey" = DB_FIELDTYPE_STRING_MEDIUM,
"last_known_ip" = DB_FIELDTYPE_STRING_SMALL,
"last_known_cid" = DB_FIELDTYPE_STRING_SMALL,
"last_login" = DB_FIELDTYPE_STRING_LARGE,
"is_permabanned" = DB_FIELDTYPE_INT,
"permaban_reason" = DB_FIELDTYPE_STRING_MAX,
"permaban_date" = DB_FIELDTYPE_STRING_LARGE,
"whitelist_status" = DB_FIELDTYPE_STRING_MAX,
"discord_link_id" = DB_FIELDTYPE_BIGINT,
"permaban_admin_id" = DB_FIELDTYPE_BIGINT,
"is_time_banned" = DB_FIELDTYPE_INT,
"time_ban_reason" = DB_FIELDTYPE_STRING_MAX,
"time_ban_expiration" = DB_FIELDTYPE_BIGINT,
"time_ban_admin_id" = DB_FIELDTYPE_BIGINT,
"time_ban_date" = DB_FIELDTYPE_STRING_LARGE,
"migrated_notes" = DB_FIELDTYPE_INT,
"migrated_bans" = DB_FIELDTYPE_INT,
"migrated_jobbans" = DB_FIELDTYPE_INT,
"stickyban_whitelisted" = DB_FIELDTYPE_INT,
"byond_account_age" = DB_FIELDTYPE_STRING_MEDIUM,
"first_join_date" = DB_FIELDTYPE_STRING_MEDIUM,
)

// NOTE: good example of database operations using NDatabase, so it is well commented
// is_ban DOES NOT MEAN THAT NOTE IS _THE_ BAN, IT MEANS THAT NOTE WAS CREATED FOR A BAN
/datum/entity/player/proc/add_note(note_text, is_confidential, note_category = NOTE_ADMIN, is_ban = FALSE, duration = null)
Expand Down
51 changes: 20 additions & 31 deletions code/datums/entities/player_job_ban.dm
Original file line number Diff line number Diff line change
@@ -1,45 +1,34 @@
/datum/entity/player_job_ban
var/player_id
var/admin_id
var/text
var/date
var/ban_time
var/expiration // in minute format
var/role // role string

DEFINE_ENTITY(player_job_ban, "player_job_bans")
// TODO: have this automatically handled by the link (weakref)
var/datum/entity/player/player
var/datum/entity/player/admin
FIELD_BIGINT(player_job_ban, player_id)
FIELD_BIGINT(player_job_ban, admin_id)
FIELD_STRING_MAX(player_job_ban, text)
FIELD_STRING_LARGE(player_job_ban, date)
FIELD_INT(player_job_ban, ban_time)
// In minute format
FIELD_BIGINT(player_job_ban, expiration)
// Role string
FIELD_STRING_MEDIUM(player_job_ban, role)

BSQL_PROTECT_DATUM(/datum/entity/player_job_ban)

/datum/entity_meta/player_job_ban
entity_type = /datum/entity/player_job_ban
table_name = "player_job_bans"
field_typepaths = list(
"player_id"=DB_FIELDTYPE_BIGINT,
"admin_id"=DB_FIELDTYPE_BIGINT,
"text"=DB_FIELDTYPE_STRING_MAX,
"date"=DB_FIELDTYPE_STRING_LARGE,
"ban_time"=DB_FIELDTYPE_INT,
"expiration"=DB_FIELDTYPE_BIGINT,
"role"=DB_FIELDTYPE_STRING_MEDIUM,
)

/datum/entity_meta/player_job_ban/on_read(datum/entity/player_job_ban/ban)
if(ban.player_id)
ban.player = DB_ENTITY(/datum/entity/player, ban.player_id)
ban.expiration = text2num("[ban.expiration]")
ban.player = DB_ENTITY(/datum/entity/player, ban.player_id)
ban.expiration = text2num("[ban.expiration]")

/datum/entity/player_job_ban/proc/load_refs()
if(admin_id)
admin = DB_ENTITY(/datum/entity/player, admin_id)
admin = DB_ENTITY(/datum/entity/player, admin_id)

/datum/entity_link/player_to_player_job_bans
parent_entity = /datum/entity/player
child_entity = /datum/entity/player_job_ban
child_foreign_key = "player_id"
parent_entity = /datum/entity/player
child_entity = /datum/entity/player_job_ban
child_foreign_key = "player_id"

/datum/entity_link/admin_to_player_job_bans
parent_entity = /datum/entity/player
child_entity = /datum/entity/player_job_ban
child_foreign_key = "admin_id"
parent_entity = /datum/entity/player
child_entity = /datum/entity/player_job_ban
child_foreign_key = "admin_id"
Loading

0 comments on commit d704403

Please sign in to comment.