2022-05-17 21:05:27 +00:00
|
|
|
|
|
|
|
init -1 python:
|
|
|
|
class EventQueue(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.queue = []
|
|
|
|
self.freeze = False
|
|
|
|
|
|
|
|
def get_events(self, raw=False):
|
|
|
|
return self.queue if raw else [x for x in self.queue if x.wait < 1]
|
|
|
|
|
|
|
|
def freeze(self):
|
|
|
|
self.freeze = True
|
|
|
|
|
|
|
|
def unfreeze(self):
|
|
|
|
self.freeze = False
|
|
|
|
|
|
|
|
def delay(self, n):
|
|
|
|
for i in self.queue:
|
|
|
|
i.wait += n
|
|
|
|
|
|
|
|
def tick(self):
|
|
|
|
"""Causes time to pass."""
|
|
|
|
if self.freeze:
|
|
|
|
return
|
|
|
|
|
|
|
|
for i in self.queue:
|
|
|
|
i.wait -= 1
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
queue = self.queue
|
2022-05-19 15:44:36 +00:00
|
|
|
queue = filter(lambda x: (x.wait <= 0) and (x.daytime == game.daytime), queue)
|
2022-05-17 21:05:27 +00:00
|
|
|
queue.sort(key=lambda x: x.priority)
|
|
|
|
|
|
|
|
for ev in queue:
|
|
|
|
if not ev.requirements_met():
|
|
|
|
continue
|
|
|
|
|
2022-05-19 15:44:36 +00:00
|
|
|
ev.start()
|
|
|
|
|
2022-05-17 21:05:27 +00:00
|
|
|
if ev.label:
|
|
|
|
break
|
|
|
|
|
|
|
|
def is_in_queue(self, ev):
|
|
|
|
if isinstance(ev, str):
|
|
|
|
return any(i.id == ev for i in self.queue)
|
|
|
|
return ev in self.queue
|
|
|
|
|
|
|
|
class Event(object):
|
|
|
|
"""
|
|
|
|
Queue is universal for all instanced objects.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, id, wait=0, priority=5, daytime=True, req=None, label=None, func=None):
|
|
|
|
self.queued = False
|
|
|
|
self.id = id
|
|
|
|
self.wait = wait
|
|
|
|
self.priority = priority
|
|
|
|
self.daytime = daytime
|
|
|
|
self.req = req
|
|
|
|
self.label = label
|
|
|
|
self.func = func
|
|
|
|
self.queue = eventqueue.queue
|
|
|
|
|
|
|
|
if not renpy.has_label(self.label):
|
|
|
|
raise Exception("Supplied label does not exist.")
|
|
|
|
|
2022-05-19 15:44:36 +00:00
|
|
|
def enqueue(self):
|
2022-05-17 21:05:27 +00:00
|
|
|
self.queued = True
|
|
|
|
|
|
|
|
if not self in self.queue:
|
|
|
|
self.queue.append(self)
|
|
|
|
|
|
|
|
def requirements_met(self):
|
|
|
|
if self.req:
|
|
|
|
return eval(self.req)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
if self in self.queue:
|
|
|
|
self.queue.remove(self)
|
|
|
|
|
|
|
|
if self.func:
|
|
|
|
self.func()
|
|
|
|
|
|
|
|
if self.label:
|
|
|
|
renpy.jump(self.label)
|
|
|
|
|
2022-05-19 15:44:36 +00:00
|
|
|
init offset = -5
|
|
|
|
|
2022-05-17 21:05:27 +00:00
|
|
|
default eventqueue = EventQueue()
|