Thanks for the reassurance, Cliff!
Ok, I will post a review for the book, when Im done reading it.
The Bugs:
1.
RangeError: Error #1125: The index -1 is out of range 0.
at ...\StoryArchitect\src\com\futurescale\sa\controller\command\story\EditStoryCommand.as:42]
In Details/ItemInfo View: If you keep deleting all the items until just the parent (Story) remains, then you go on and save the changes, when you try to edit the story again it throws an error like the one above.
Thats the case of a Simple Story, where a Scene is the direct descendant of a Story. story.scenes.length is 0, therefore story.scenes.length-1 is -1. And thats because the xml file contains no Scenes, just a Cast and a Milieu.
The same happens with a Normal and/or a Complex Story, but this time the arrays in question are story.chapters and story.parts, the first descendants of a Story that EditStoryCommand is trying to set.
- So my first workaround was concentrated on EditStoryCommand and I simply checked the length of the arrays and if it was 0 I added the missing parts to their parents.
For a Simple Story it would look like this:
if (story.scenes.length == 0)
{
scene=new SceneVO();
story.addScene(scene);
}
else
{
scene=story.scenes[story.scenes.length - 1];
}
Here the modified code for EditStoryCommand:
https://gist.github.com/1524621- Then I saw that StoryVO has these methods: getNewScene(),getNewChapter(),getNewPart() and I used them like this:
https://gist.github.com/1533524It solves the problem, but it doesnt feel quite right.
When you create new stories the flow looks like this:
Simple
StoryVO.getNewScene()
SceneVO.getNewDraft()
SceneVO.addDraft(draft)
StoryVO.addScene(scene)
Normal
StoryVO.getNewChapter()
ChapterVO.getNewScene()
SceneVO.getNewDraft()
SceneVO.addDraft(draft)
ChapterVO.addScene(scene)
StoryVO.addChapter(chapter)
Complex
StoryVO.getNewPart()
PartVO.getNewChapter()
ChapterVO.getNewScene()
SceneVO.getNewDraft()
SceneVO.addDraft(draft)
ChapterVO.addScene(scene)
PartVO.addChapter(chapter)
StoryVO.addPart(part)
So it should be enough to call
scene=story.getNewScene();when story.scenes.length == 0 for a simple story,
chapter=story.getNewChapter (); when story.chapters.length == 0 for a normal story,
or part=story.getNewPart(); when story.parts.length == 0 for a complex story
like when you create a new Story.
But it doesnt work, and right now I cant see why. As I said, Im not familiar enough with the code yet, so I just modified EditStoryCommand to make it work .
Anyway, I think that I made the changes in the wrong class.
Maybe the real solution would be to prevent saving an empty Story in the first place? Does it make sense to have a Story with no Scene or Chapter or Part, depending on the type of the Story?
I will investigate this chain:
ItemInfo.deleteItem()
DeleteItemCommand
StoryVO.deletePart
StoryTile.changeStorySelection(selection)
StoryTile.removeTiles()
StoryTile.createTiles()
to see what happens in the VOs after deleting an item.
Im sure there is a very simple and more elegant solution to this and Im curious to hear it from you.
2.
Then there were the following situations, which I cant reproduce anymore right now:
a. a totally empty XML file has been saved on the hard disk. If you try to edit it, a new Story, called Story 0, gets created and the xml file is empty. Now there are 2 empty stories, which cannot be deleted or edited (RTE)
Also in StoryProxy. loadStory() storyStub.uid is the id listed in index.xml while story.uid is different (a new uid). I dont understand the logic in there yet.
Quick and dirty solution(no idea if it wont produce other bugs elsewhere):
if (storyStub.uid == story.uid)
cacheProxy=new Proxy(story.uid, story);
else
cacheProxy=new Proxy(storyStub.uid, storyStub);
b. the story/index.xml contains stories that dont exist in that folder. Of course, when you try to load such a story it throws an error.
So my quick and dirty workaround was this:
AbstractProxy
private function readFile(file:File, voStub:ValueObject=null):XML
{
var stream:FileStream=new FileStream();
var xml:XML=new XML();
if (file.exists)
{
stream.open(file, FileMode.READ);
xml=XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
}
return xml;
}
I think something goes wrong with the updating of the index file (synchronisation between the list of stories in the index and the files on disk)
Im sorry that I cant provide more accurate info at this stage. I know that my solutions arent good, and they only show how limited my understanding of the code is, but at least youll have some hints at the vulnerable parts of the app.
Ondina