Created
January 31, 2017 11:19
-
-
Save aarqon/51a1047ec7c47bc2411db41d4e324570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import random | |
| from Condition import Condition | |
| class SceneProcessor(): | |
| scenelist = {} | |
| def __init__(self, scenelist=[]): | |
| for scene in scenelist: | |
| self.scenelist[scene.getName()] = scene | |
| def processScene(self, scene, actors): | |
| out = [] | |
| tokens = self.getTokens(scene) | |
| for token in tokens: | |
| t = token.split(':') | |
| if t[0] == 'actor': | |
| out.append(actors[t[1]].getName()) | |
| continue | |
| elif t[0] == 'jump': | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[1]], actors)) | |
| continue | |
| elif t[0] == 'condition': | |
| path = t[1].split('.') | |
| if 'actor' in path[0]: | |
| if path[1] == 'has': | |
| if Condition[path[2]] in self.getActorValue(actors[path[0]],('conditions',)): | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[2]], actors)) | |
| continue | |
| elif len(t) > 3: | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[3]], actors)) | |
| continue | |
| elif path[1] == 'nothas': | |
| if Condition[path[2]] not in self.getActorValue(actors[path[0]],('conditions',)): | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[2]], actors)) | |
| continue | |
| elif len(t) > 3: | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[3]], actors)) | |
| continue | |
| else: | |
| if self.getActorValue(actors[path[0]], path[1:]) >= int(t[2]): | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[3]], actors)) | |
| continue | |
| elif len(t) > 4: | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[4]], actors)) | |
| continue | |
| if path[0] == 'random': | |
| if random.randint(0,int(path[1])) >= int(t[2]): | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[3]], actors)) | |
| continue | |
| elif len(t) > 4: | |
| out.append('\n') | |
| out.append(self.processScene(self.scenelist[t[4]], actors)) | |
| continue | |
| else: | |
| out.append(token) | |
| return ''.join(out) | |
| def getTokens(self, scene): | |
| return re.split("(?:{)(.+?)(?:})", scene.getBody()) | |
| def getScenesWithNumActors(self, num): | |
| temp = [] | |
| for name, scene in self.scenelist.items(): | |
| if scene.getNumActors() <= num and not scene.isChild(): | |
| temp.append(scene) | |
| return temp | |
| def getActorValue(self, actor, path): | |
| if path[0] == 'name': return actor.getName() | |
| if path[0] == 'age': return actor.getAge() | |
| if path[0] == 'attr': return actor.getBaseAttr(path[1]) | |
| if path[0] == 'modattr': return actor.getModAttr(path[1]) | |
| if path[0] == 'body': return actor.getBaseBody(path[1]) | |
| if path[0] == 'modbody': return actor.getModBody(path[1]) | |
| if path[0] == 'conditions': return actor.getConditions() | |
| if path[0] == 'job': return actor.getJob() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment