Skip to content

Commit

Permalink
Merge pull request #10 from DRincs-Productions/9-typify-python
Browse files Browse the repository at this point in the history
9 typify python
  • Loading branch information
BlackRam-oss committed Jul 9, 2022
2 parents 1203572 + 57d4800 commit 845073a
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 191 deletions.
35 changes: 14 additions & 21 deletions game/tool/action.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ init -5 python:
icon: str,
label: str,
icon_selected: str = None,
sp_room: str = None,
room: str = None,
tm_start: int = 0,
tm_stop: int = 25,
day_start: int = -1,
Expand All @@ -28,7 +28,7 @@ init -5 python:
self.day_deadline = day_deadline
self.day_start = day_start
# it is used only in sp_actions
self.sp_room = sp_room
self.room = room
# Is an action that is started by clicking on an image in the room.
self.is_in_room = is_in_room
self.xpos = xpos
Expand All @@ -40,35 +40,28 @@ init -5 python:
"Warn: You have set day_deadline < 0, so it will be ignored")


# TODO: add the type a sp_actions & df_actions
def getActions(room: Room, sp_actions: dict, df_actions: dict, tm: TimeHandler):
def getActions(actions: dict[str, Action], room: Room, tm: TimeHandler):
"""Return all possible actions in a certain room (ATTENTION: give a Room object as parameter, and not the id)"""
acts: list[Action] = []
acts.clear()
for act in sp_actions.values():
if room.id == act.sp_room:
for act_id, act in actions.items():
if room.id == act.room:
if (tm.now_is_between(start=act.tm_start, end=act.tm_stop) and (act.day_start < 0 | tm.day >= act.day_start)):
acts.append(act)
for act_id in room.id_actions:
if act_id in df_actions:
act = df_actions.get(act_id)
elif act_id in room.id_actions:
if (tm.now_is_between(start=act.tm_start, end=act.tm_stop) and (act.day_start < 0 | tm.day >= act.day_start)):
acts.append(act)
del act
return acts


# TODO: add the type a sp_actions & df_actions
def clearExpiredSPActions(sp_actions: dict):
def clearExpiredSPActions(sp_actions: dict[str, Action], tm: TimeHandler):
"""Delete Expired Actions"""
alist = []
alist.clear()
actions_to_del = []
for id, act in sp_actions.items():
if (act.day_deadline != None and act.day_deadline <= tm.day):
alist.append(id)
for act_id in alist:
alist.pop(act_id)
del alist
return
if (act.day_deadline and act.day_deadline <= tm.day):
actions_to_del.append(id)
for act_id in actions_to_del:
del sp_actions[act_id]
del actions_to_del
return sp_actions

# TODO: Add a function that updates Actions after a load
8 changes: 4 additions & 4 deletions game/tool/action_label.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ label development:
label order_product:
mc "OK! Let's see, let's look for a book...."
mc "Here's R****, for $1. Just the thing for me."
$ sp_actions.pop('order_product')
$ del sp_actions['order_product']
$ quests["alice"].next_stage()
call screen room_navigation

label add_product:
$ sp_actions["take_product"] = Action(_("Take product"), "/interface/action-box.webp", label = "take_product", sp_room='terrace')
$ sp_actions["take_product"] = Action(_("Take product"), "/interface/action-box.webp", label = "take_product", room='terrace')
call screen room_navigation

label take_product:
$ sp_actions.pop('take_product')
$ del sp_actions['take_product']
$ quests["alice"].next_stage()
call screen room_navigation

label take_key:
mc "Are these the car keys?! Well... I should try to access the car!"
$ bl_values["goout"] = True
$ sp_actions.pop('take_key')
$ del sp_actions['take_key']
$ quests["ann"].next_stage()
call screen room_navigation

Expand Down
40 changes: 24 additions & 16 deletions game/tool/action_talk.rpy
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
init -9 python:
define DEFAULT_LABEL_TALK = "talk"

init -11 python:
class TalkObject(object):
"""At the inside of the class there are the values used for the talk() function,
(all this could be done in Commitment(), but I preferred not to use a dictionary)"""

def __init__(self,
ch_secondary = [],
bg_before_after=None,
after_label_event=None,
bg_talk=None,
label_talk=None):
ch_secondary: list[str] = [],
bg_before_after: str = None,
after_label_event: str = None,
bg_talk: str = None,
label_talk: str = None):

self.ch_secondary = ch_secondary
self.bg_before_after = bg_before_after
Expand All @@ -18,10 +21,11 @@ init -9 python:
def talk(self):
"""Inside you can find the labels and images to start talk()"""
# if label_talk == None does the default procedure
if self.label_talk == None:
renpy.jump('talk')
else:
if not isNullOrEmpty(self.label_talk):
renpy.jump(self.label_talk)
elif not isNullOrEmpty(DEFAULT_LABEL_TALK):
renpy.jump(DEFAULT_LABEL_TALK)
return

def getTalkImage(self):
"""Returns the image during a conversation"""
Expand All @@ -35,12 +39,13 @@ init -9 python:
"""Returns the background image used after a conversation,
but if after_label_event is not null it passes to after_label_event.
((the latter can be used in case the room is no longer accessible and thus takes you to another room))"""
if self.after_label_event != None:
renpy.jump(after_label_event)
if not isNullOrEmpty(self.after_label_event):
renpy.jump(self.after_label_event)
else:
return self.bg_before_after

def addTalkChoice(ch, choice_text, label):

def addTalkChoice(ch, choice_text, label, talkch_choices: dict[str, list]): # TODO: add a type for list
"""Add the "choice" in the character's talkch_choices."""
if (ch in talkch_choices.keys()):
talkch_choices[ch].append((choice_text, label))
Expand All @@ -51,15 +56,18 @@ init -9 python:
del talk_choices
return

def delTalkChoice(ch, choice_text):

def delTalkChoice(ch, choice_text, talkch_choices: dict[str, list]): # TODO: add a type for list
"""Deletes the "choice" in the character's talkch_choices."""
val = 0
ch_to_del = ch
for cur_choice in talkch_choices[ch]:
if cur_choice[0] == choice_text:
talkch_choices[ch].pop(val)
del val
return
ch_to_del = ch
break
else:
val = val+1
talkch_choices[ch].pop(val)
del val
del ch_to_del
return
10 changes: 5 additions & 5 deletions game/tool/action_talk_label.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ label stage_talkalice:
mc "Ok"
a "Thanks"

$ addTalkChoice(ch = "alice", choice_text = _("About the book"), label = "stage_talkalice")
$ addTalkChoice(ch = "alice", choice_text = _("About the book"), label = "stage_talkalice", talkch_choices = talkch_choices)

$ sp_actions["order_product"] = Action(_("Order product"), "/interface/action-pc.webp", label = "order_product", sp_room='my_room')
$ sp_actions["order_product"] = Action(_("Order product"), "/interface/action-pc.webp", label = "order_product", room='my_room')

$ quests["alice"].next_stage()
elif (quests_levels["alice"] == 1):
Expand All @@ -96,7 +96,7 @@ label stage_talkalice:
mc "Here's your book."
a "Thank you, I can finally read something new."
$ quests["alice"].next_stage()
$ delTalkChoice(ch = "alice", choice_text = _("About the book"))
$ delTalkChoice(ch = "alice", choice_text = _("About the book"), talkch_choices = talkch_choices)
return

# Quest "ann"
Expand All @@ -107,9 +107,9 @@ label stage_talkalice_aboutann:
a "Yes, of course. You can find the keys on the keyhole in the hall."
mc "Thanks!"
a "Don't ruin it..."
$ sp_actions["take_key"] = Action(_("KEY"), "/action-key.webp", label = "take_key", sp_room='lounge',
$ sp_actions["take_key"] = Action(_("KEY"), "/action-key.webp", label = "take_key", room='lounge',
is_in_room = True, xpos = 608, ypos = 667)

$ quests["ann"].next_stage()
$ delTalkChoice(ch = "alice", choice_text = _("About the Ann"))
$ delTalkChoice(ch = "alice", choice_text = _("About the Ann"), talkch_choices = talkch_choices)
return
8 changes: 4 additions & 4 deletions game/tool/action_value.rpy
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# "special" actions:
# they are not usual actions, but actions inserted and removed for a specific reason, for example for a quest.
# IMPORTANT: specify in sp_room the id of the room where the action will take place
# IMPORTANT: specify in room the id of the room where the action will take place
default sp_actions = {}

# habitual actions
define df_actions = {
"nap" : Action(_("Nap"), "/interface/action-sleep.webp", label = "nap", tm_start=5, tm_stop=23),
"sleep" : Action(_("Sleep"), "/interface/action-alarm.webp", label = "sleep", tm_start=23, tm_stop=5),
}
"nap" : Action(_("Nap"), "/interface/action-sleep.webp", label = "nap", tm_start=5, tm_stop=23),
"sleep" : Action(_("Sleep"), "/interface/action-alarm.webp", label = "sleep", tm_start=23, tm_stop=5),
}
6 changes: 3 additions & 3 deletions game/tool/core.rpy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
label after_load:
$ updateTimeHandler()
$ clearExpiredSPActions()
$ clearExpiredSPRoutine()
$ tm = updateTimeHandler(tm)
$ sp_actions = clearExpiredSPActions(sp_actions, tm)
$ clearExpiredSPRoutine(sp_routine, tm)
$ updateBL()
return
50 changes: 29 additions & 21 deletions game/tool/nav_class.rpy
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# list of closed rooms is checked change_room
# is composed of id = room_id and Commitment()
# expired elements are checked in after_wait, if you don't want an expiration: tm_stop = None
default closed_rooms = {}

init -9 python:
class Room:
"""Class of a Room"""

def __init__(self,
id,
id_location,
name=None,
icon=None,
bg=None,
id_actions=[]):
id: str,
id_location: str,
name: str = None,
icon: str = None,
bg: str = None,
id_actions: list[str] = []):

self.id = id
self.id_location = id_location
Expand All @@ -16,17 +22,19 @@ init -9 python:
self.bg = bg
self.id_actions = id_actions


class Location:
"""Class of a Location"""
# TODO: undiscovered locations

def __init__(self,
id,
key_map,
id_externalroom,
name=None,
icon=None,
xalign=0,
yalign=0):
id: str,
key_map: str,
id_externalroom: str,
name: str = None,
icon: str = None,
xalign: int = 0,
yalign: int = 0):

self.id = id
self.key_map = key_map
Expand All @@ -36,14 +44,14 @@ init -9 python:
self.xalign = xalign
self.yalign = yalign

# list of closed rooms is checked change_room
# is composed of id = room_id and Commitment()
# expired elements are checked in after_wait, if you don't want an expiration: tm_stop = None
default closed_rooms = {}
init -9 python:
def clearClosedRooms():

def clearClosedRooms(closed_rooms: dict[str, Commitment]):
"Deletes expired locked rooms. you want to add a room with no expiry date: tm_stop = None"
closed_rooms_to_del = []
for id, item in closed_rooms.items():
if (item.tm_stop != None and tm.now_is_between(start=item.tm_start, end=item.tm_stop) == False):
closed_rooms.pop(id)
return
closed_rooms_to_del.append(id)
for id in closed_rooms_to_del:
del closed_rooms[id]
del closed_rooms_to_del
return closed_rooms
8 changes: 4 additions & 4 deletions game/tool/nav_value.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ define rooms = [
Room(id="terrace", id_location="house", name=_("Terrace"), icon="icon terrace", bg="bg terrace"),
Room(id="ann_room", id_location="house_Ann", name=_("Ann room"), icon="icon annroom", bg="bg annroom"),
Room(id="courtyard", id_location="house_Ann", name=_("Courtyard"), icon="icon courtyard", bg="bg courtyard"),
]
]

define locations = {
"house" : Location(id = "house", key_map="map", id_externalroom="terrace", name=_("MC house"), icon="icon map home", xalign=0.3, yalign=0.2),
}
}

define map_images = {
"map" : "bg map",
}
}

define ch_icons = {
"alice" : "icon/Alice.webp",
"ann" : "icon/Ann.webp",
}
}

default cur_room = rooms[0]
default cur_location = locations[cur_room.id_location]
Expand Down
Loading

0 comments on commit 845073a

Please sign in to comment.