-
- import cocos
- import pyglet
-
- import lib.constants as c
-
- from lib.common import parse_file
-
-
- class BaseCutscene(cocos.layer.Layer):
- """Base class for all cutscenes done in the nvl style."""
-
- is_event_handler = True
-
- def __init__(self, files, scenes, hypervisor, logic, director, handle, name):
- """Parameters:
-
- hypervisor = game class
-
- logic = logic class
-
- handle = file handler
-
- scenes = scenes to be executed
- """
-
- super(BaseCutscene, self ).__init__()
-
- self.hypervisor = hypervisor
- self.director = director
- self.handle = handle
- self.name = name
-
- self.files = files
- self.scenes = scenes
-
- self.done = False
- self.cprogress = 0
-
- if len(self.scenes) == "":
- raise RuntimeError("Empty scene not supported.")
-
- if len(self.files) > 0:
- # Changing paths so it will work on all systems
- for item in self.files:
- self.files[item] = parse_file(self.files[item])
-
- # commands
- self.map = {
-
- "scene ":self.scene
-
- }
-
- # transitions
- self.transitions = {
- "fade": cocos.actions.interval_actions.FadeIn(1),
- "fade_long": cocos.actions.interval_actions.FadeIn(2),
- }
-
-
- self.waiting = False
- self.waiting_actions = None
- self.return_point = None
- self.return_args = None
- self.current_state = None
- self.skipping = False
-
- self.text = ""
- self.back_log = []
- self.background = None
- self.sprite_left = None
- self.sprite_right = None
- self.sprite_center = None
- self.frame = None
-
- # add to events
- self.schedule(self.run_script)
-
- def passed(self):
- return "next"
-
- def scene(self, arguments):
- raw_input()
-
- args = arguments.split(" ")
- trans = None
- if len(arguments) > 1:
- # we check for transitions
-
- for transition in self.transitions:
- if args[-1] == transition:
- trans = args.pop()
- break
-
- img_name = ""
- for part in args:
- img_name += part + " "
-
- print repr(img_name), len(img_name)
-
- img_name = img_name[:len(img_name)-1]
-
- print repr(img_name)
- print args
-
- if img_name not in self.files.keys():
- raise RuntimeError("Unknown image: %s" %img_name)
-
- img_object = self.handle.request("file", self.files[img_name], self.name)
- img = pyglet.image.load(self.files[img_name], file=img_object)
-
- if self.frame is not None:
- self.frame.do(cocos.actions.instant_actions.Hide())
-
- nb = cocos.sprite.Sprite(img, position=(0, 0))
- self.add(nb)
-
- self.waiting_actions = nb
- self.return_args = (nb,)
- self.return_point = self.scene_cont
-
- if (not self.skipping) and (trans is not None):
- nb.do(self.transitions[trans])
-
-
- def scene_cont(self, nb):
- if self.background is None:
- self.remove(nb)
- self.background = nb
- self.add(self.background)
- else:
- self.remove(nb)
- self.background.kill()
- self.background = None
- self.background = nb
- self.add(self.background)
-
- if self.frame is not None:
- self.frame.do(cocos.actions.instant_actions.Show())
-
- raw_input()
-
-
- def moot(self, *args, **kwargs):
- """/dev/null of calls"""
- pass
-
-
- def run_script(self, *args, **kwargs):
- if self.waiting:
- return
- elif self.waiting_actions is not None:
- if self.waiting_actions.are_actions_running():
- print "doing", self.waiting_actions, self.waiting_actions.actions
- return
- else:
- self.waiting_actions = None
- if len(self.return_args) > 0:
- self.return_point(*self.return_args)
- else:
- self.return_point()
- self.return_args = None
- self.return_point = None
- else:
- if self.cprogress > len(self.scenes) - 1:
- self.done = True
- return
- # we grab new line from script
- line = self.scenes[self.cprogress]
- self.cprogress += 1
-
- for key in self.map:
- isacommand = False
-
- if line.startswith(key):
- isacommand = True
- self.map[key](line[len(key):])
-
- if not isacommand:
- raise RuntimeError("Syntax Error, unsupported command: %s" %line)
-