forked from dylanswiggett/director-to-video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
92 lines (72 loc) · 2.32 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
from difflib import SequenceMatcher
# Stage directions:
ENTER = 0
EXIT = 1
BACKGROUND = 2
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
class Dialog:
def __init__(self, character, text):
self.character = character
self.text = text
class StageDirection:
def __init__(self, text, character=None):
self.text = text
self.character = character
self.actions = []
def addAction(self, action, obj):
self.actions.append((action, obj))
class Character:
def __init__(self, name):
self.name = name
self.image = None
self.loc = None
self.voice = 0
def setImage(self, image):
self.image = image
class Setting:
def __init__(self, name):
self.name = name
self.image = None
class Scene:
def __init__(self, description):
self.description = description
self.directions = []
self.characters = set()
self.entering = set()
self.setting = None
def addDirection(self, direction):
self.directions.append(direction)
if isinstance(direction, StageDirection):
for action in direction.actions:
action, char = action
if action == ENTER and not char in self.characters:
self.entering.add(char)
if isinstance(direction, Dialog) and not direction.character in self.entering:
self.characters.add(direction.character)
def setSetting(self, setting):
self.setting = setting
class Script:
def __init__(self):
self.scenes = []
self.characters = dict()
self.settings = dict()
def addScene(self, scene):
self.scenes.append(scene)
def addSetting(self, name):
if name in self.settings:
return False
self.settings[name] = Setting(name)
return True
def getSetting(self, name):
sims = [(similar(name,n),self.settings[n]) for n in self.settings]
return max(sims)[1]
def addCharacter(self, name):
char = Character(name)
names = name.split("/")
for subname in names:
self.characters[subname] = char
def getCharacter(self, name):
sims = [(similar(name,n),self.characters[n]) for n in self.characters]
return max(sims)[1]