Skip to content

Commit

Permalink
Add "show_in_dark=2" which will show that evidence ONLY in darkness
Browse files Browse the repository at this point in the history
Fix /lights not updating people's evidence lists properly
  • Loading branch information
Crystalwarrior committed Nov 5, 2024
1 parent c29d0bf commit bd5cba2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions server/commands/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ def ooc_cmd_lights(client, arg):
pos = client.area.pos_dark
c.send_command("BN", bg, pos)
client.send_ooc(f"This area is {stat} dark.")
client.area.broadcast_evidence_list()


def ooc_cmd_auto_pair(client, arg):
Expand Down
37 changes: 25 additions & 12 deletions server/evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EvidenceList:
class Evidence:
"""Represents a single evidence item."""

def __init__(self, name, desc, image, pos, can_hide_in=False, show_in_dark=False):
def __init__(self, name, desc, image, pos, can_hide_in=False, show_in_dark=0):
self.name = name
self.desc = desc
self.image = image
Expand Down Expand Up @@ -139,7 +139,7 @@ def correct_format(self, client, desc):
return True
return False

def desc_to_pos(self, desc):
def parse_desc(self, desc):
for match in re.findall(r"<.*?=.*?>", desc):
args = match.strip("<>").split("=")
if len(args) < 2:
Expand All @@ -152,7 +152,8 @@ def desc_to_pos(self, desc):
if key == "can_hide_in":
can_hide_in = value == "1"
if key == "show_in_dark":
show_in_dark = value == "1"
print(value)
show_in_dark = int(value)

desc = re.sub(r"<.*?=.*?>\n?", '', desc)
return desc, poses, can_hide_in, show_in_dark
Expand All @@ -179,16 +180,16 @@ def add_evidence(self, client, name, desc, image, pos="all"):
)
return
can_hide_in = False
show_in_dark = False
show_in_dark = 0
pos = "all"

if client.area.evidence_mod == "HiddenCM":
if client in client.area.owners or client.is_mod:
pos = "hidden"
if self.correct_format(client, desc):
desc, pos, can_hide_in, show_in_dark = self.desc_to_pos(desc)
desc, pos, can_hide_in, show_in_dark = self.parse_desc(desc)
else:
if len(client.area.pos_lock) > 0:
if len(client.area.pos_lock) > 0 and client.pos in client.area.pos_lock:
pos = client.pos

self.evidences.append(self.Evidence(
Expand Down Expand Up @@ -268,14 +269,22 @@ def create_evi_list(self, client):
self.Evidence(evi.name, desc, evi.image,
evi.pos).to_tuple()
)
elif (not client.area.dark or self.evidences[i].show_in_dark) and self.can_see(self.evidences[i], client.pos):
elif self.can_see(self.evidences[i], client.pos):
# show_in_dark:
# 0 - Do not show evidence in dark areas.
# 1 - Show evidence in dark areas.
# 2 - ONLY show evidence in dark areas. Will be hidden in non-dark areas.
if client.area.dark and self.evidences[i].show_in_dark == 0:
continue
if not client.area.dark and self.evidences[i].show_in_dark == 2:
continue
nums_list.append(i + 1)
evi_list.append(self.evidences[i].to_tuple())
return nums_list, evi_list

def import_evidence(self, data):
for evi in data:
name, desc, image, pos, can_hide_in, show_in_dark = "<name>", "<desc>", "", "all", False, False
name, desc, image, pos, can_hide_in, show_in_dark = "<name>", "<desc>", "", "all", False, 0
if "name" in evi:
name = evi["name"]
if "desc" in evi:
Expand All @@ -287,7 +296,7 @@ def import_evidence(self, data):
if "can_hide_in" in evi:
can_hide_in = evi["can_hide_in"] is True
if "show_in_dark" in evi:
show_in_dark = evi["show_in_dark"] is True
show_in_dark = int(evi["show_in_dark"])
self.evidences.append(self.Evidence(
name, desc, image, pos, can_hide_in, show_in_dark))

Expand Down Expand Up @@ -362,7 +371,7 @@ def edit_evidence(self, client, id, arg):
pos = arg[3]

can_hide_in = False
show_in_dark = False
show_in_dark = 0
if client in client.area.owners or client.is_mod:
if id not in range(len(self.evidences)):
return
Expand All @@ -378,7 +387,7 @@ def edit_evidence(self, client, id, arg):

if client.area.evidence_mod == "HiddenCM":
if self.correct_format(client, desc):
desc, pos, can_hide_in, show_in_dark = self.desc_to_pos(desc)
desc, pos, can_hide_in, show_in_dark = self.parse_desc(desc)
else:
client.send_ooc(
'You entered a bad pos - evidence hidden! Make sure to have <owner=pos> at the top, where "pos" is the /pos this evidence should show up in. Put in "all" if you want it to show up in all pos, or "hidden" for no pos.'
Expand All @@ -396,7 +405,11 @@ def edit_evidence(self, client, id, arg):
if id not in range(len(self.evidences)):
return
evi = self.evidences[id]
if client.area.dark and not evi.show_in_dark:
# 0 - Do not show evidence in dark areas.
if client.area.dark and evi.show_in_dark == 0:
return
# 2 - ONLY show evidence in dark areas. Will be hidden in non-dark areas.
if not client.area.dark and evi.show_in_dark == 2:
return
old_name = evi.name
# If any of the args are *, keep the old entry
Expand Down

0 comments on commit bd5cba2

Please sign in to comment.