Add 'studio/story.py'
This commit is contained in:
parent
1193a902fd
commit
9af4596da0
1 changed files with 183 additions and 0 deletions
183
studio/story.py
Normal file
183
studio/story.py
Normal file
|
@ -0,0 +1,183 @@
|
|||
# THIS FILE IS A PART OF VCStudio
|
||||
# PYTHON 3
|
||||
|
||||
import os
|
||||
import datetime
|
||||
|
||||
|
||||
def get_legacy(project_location):
|
||||
|
||||
# This function will read the .bos (Blender-Organizer Story) files. Primarily
|
||||
# to convert them to .vcss (VCStudio Story) files.
|
||||
# The concept is similar. But in order to work with them outside of reading
|
||||
# and writting the file directly. I want to make a dictionary format with in
|
||||
# the python. (Similarly to how I did with checklists and analytics)
|
||||
|
||||
# In the .bos file there was what I thought was clever at the time but
|
||||
# ultimatly a dumb idea to make EVENTS and not scenes. The idea was that in
|
||||
# a single event could be multiple scenes. But in reality it very rearly used
|
||||
# and creating scenes with in events created a potential user error situation.
|
||||
|
||||
# So I want to get rid of all the EVENTS and read Scenes directly. Unless
|
||||
# the event is empty of scenes. In which case to create a scene with the
|
||||
# text of that event.
|
||||
|
||||
data = {
|
||||
"fraction": 0.0, # Percentage of the Scenes finished.
|
||||
"camera" : [0,0], # The position of where the user left
|
||||
"scenes" : {}, # List of scenes.
|
||||
"arrows" : [], # List of connections. (A LIST. NOT DICT.)
|
||||
"files" : {}, # List of links to files.
|
||||
"markers": {}, # List of markers.
|
||||
"events" : {} # List of frame like containers. (It will have similar)
|
||||
} # function as events. But will have no text data with in
|
||||
# it. It will be more like Blender's node editor's Frame.
|
||||
|
||||
# Even tho I want to change radically the idea of events. We still need to
|
||||
# think in the events terms. Because we are parsing and old file. Funny how
|
||||
# I will need to write this thing twice. For both file-types.
|
||||
|
||||
# I can't read it the way I read most other files. Because it's not line-
|
||||
# based. But more something like HTML file. So it's going to be a little
|
||||
# issue.
|
||||
|
||||
bos = open(project_location+"/pln/main.bos")
|
||||
bos = bos.read()
|
||||
|
||||
if "</camera>" in bos:
|
||||
camera = bos[bos.find("<camera>")+8:]
|
||||
camera = camera[:camera.find("</camera>")]
|
||||
camera = camera.split(",")
|
||||
|
||||
for num, val in enumerate(camera):
|
||||
try:
|
||||
camera[num] = float(val)
|
||||
except:
|
||||
camera[num] = 0.0
|
||||
|
||||
# Some stupid me made decision early in a story editor's life to use
|
||||
# per-pixel X coordinates and per line Y coordinates. Which is something
|
||||
# like 100 times the difference. Okay 50 ish is a default value for Y.
|
||||
|
||||
# I'm not going to do anything about it right now. Maximum a bit later.
|
||||
|
||||
camera = [camera[0], camera[1]] # I don't want scale to exist here.
|
||||
|
||||
data["camera"] = camera
|
||||
|
||||
|
||||
# Events. They are very important. Now in the Blender-Organizer I used an
|
||||
# HTML like format to mark shots and assets with in the text. But it's not
|
||||
# a very efficient way of doing it. Because it requiered constant parsing
|
||||
# of the text in real time. Which caused quite a noticable lag. And also
|
||||
# every time I needed to read a part of it. I had to do parsing of the text.
|
||||
|
||||
# So I guess the VCSS file format will be designed to deal with this kind of
|
||||
# thing. I'm actually more toward putting the text into separate files. Simple
|
||||
# text documents. And making the VCSS a linking system.
|
||||
|
||||
if "</event>" in bos:
|
||||
for event in bos.split("</event>")[:-1]:
|
||||
event = event[event.find("<event>")+8:]
|
||||
|
||||
# Now we have text of the event. Let's parse out of it folowing
|
||||
# stuff. We will need it if there are multiple scenes. Or when
|
||||
# there are no scenes at all.
|
||||
|
||||
eventname = event[event.find('"')+1:event.replace('"'," ",1).find('"')]
|
||||
|
||||
# Let's parse the coordinates.
|
||||
|
||||
c = event[event.find('[')+1:event.find(']')]
|
||||
c = c.split(",")
|
||||
|
||||
eventpositon = [float(c[0]),float(c[2])]
|
||||
eventsize = [float(c[1]),30.0]
|
||||
|
||||
# Now since we know the name of the event and the sizes. We can
|
||||
# start parsing the scenes from the text with in the event.
|
||||
|
||||
eventtext = event[event.find(']')+2:-1]
|
||||
|
||||
# Now basically have to do the same exact thing with <scene> and
|
||||
# later with <shot>, <item> to make all work.
|
||||
|
||||
# But first let's record a scene if it has no scene in it.
|
||||
|
||||
if not "<scene>" in eventtext:
|
||||
|
||||
if eventname in data["scenes"]:
|
||||
eventname = eventname + "_copy"
|
||||
|
||||
data["scenes"][eventname] = {
|
||||
"fraction":0.0, # Percentage
|
||||
"position":eventpositon,
|
||||
"size":eventsize,
|
||||
"parent":"", # For when it's in a Frame (Event)
|
||||
"links":{}, # Assets, Images, Files etc.
|
||||
"shots":{},
|
||||
"frases":{}, # For dialogues.
|
||||
"text":eventtext
|
||||
}
|
||||
|
||||
else:
|
||||
|
||||
# If there are more then 1 scene per event. We want to create
|
||||
# an event, frame thing for them.
|
||||
|
||||
parent = "" #This will be it's name
|
||||
|
||||
if eventtext.count("<scene>") > 1:
|
||||
parent = eventname
|
||||
|
||||
data["events"][eventname] = {
|
||||
"position":eventpositon
|
||||
}
|
||||
|
||||
# Now let's continue parsing the scenes.
|
||||
|
||||
for scene in eventtext.split("</scene>")[:-1]:
|
||||
|
||||
scenename = scene[scene.find('"')+1:scene.replace('"'," ",1).find('"')]
|
||||
scenetext = scene[scene.find('"')+2:-1]
|
||||
|
||||
# Okay so we have both scene name and scene text. So it's
|
||||
# time so send this data into the main data thingy, right?
|
||||
# Wrong. Now we need to parse pointers to the shots, assets
|
||||
# and other stuff. This file format gonna take a while.
|
||||
|
||||
# I guess we should do it one by one. Using the technique
|
||||
# from the Blender-Organizer.
|
||||
|
||||
# This step requires a huge concentration because a good
|
||||
# amount of bugs can be created by not thinking about
|
||||
# all kinds of ways that the user might input stuff into
|
||||
# the story editor.
|
||||
|
||||
# Basically the idea is to read the part of the story from
|
||||
# beginning to end and gradually removing tags from it.
|
||||
|
||||
# Oh no... I'ts harder then I thought. I think we will have
|
||||
# to make quite an algorythm here. If I remove <shot> from
|
||||
# the text. I just removed 6 characters. If I do that again
|
||||
# later with <item> it's another 6 characters. So any
|
||||
# pointer system will be terrible with this kind of thing.
|
||||
|
||||
# Also imagine typing while having this kind of system.
|
||||
# On each new typed character. ALL the pointers should be
|
||||
# off setted. Hm... I think here is where I take a nap.
|
||||
# Because this decision should not be done quickly. I need
|
||||
# to figure out how to store this data.
|
||||
return data
|
||||
|
||||
this = get_legacy("/home/vcs/Projects/Films/Shorts/MoriasRace")
|
||||
for i in this:
|
||||
if i == "scenes":
|
||||
print("scenes {")
|
||||
for b in this[i]:
|
||||
print(" ", b, " { ")
|
||||
for c in this[i][b]:
|
||||
print(" ", c ," : ", str(this[i][b][c])[:50])
|
||||
print("}")
|
||||
else:
|
||||
print(i, " : " ,this[i])
|
Loading…
Add table
Reference in a new issue