Skip to content

Commit

Permalink
Can only add one custom variable at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemoore committed Apr 11, 2012
1 parent e5ca1f4 commit e1fd68f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Binary file modified bin-debug/StructureCreator.swf
Binary file not shown.
7 changes: 7 additions & 0 deletions src/com/structurecreator/MainContext.as
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.structurecreator
import com.structurecreator.controller.DatabaseCommand;
import com.structurecreator.controller.FileCommand;
import com.structurecreator.controller.ProfileCommand;
import com.structurecreator.events.CustomVarsEvent;
import com.structurecreator.events.FileEvent;
import com.structurecreator.events.ProfileEvent;
import com.structurecreator.events.StructureCreatorEvent;
Expand Down Expand Up @@ -85,10 +86,16 @@ package com.structurecreator
eventDispatcher.dispatchEvent(new StructureCreatorEvent(StructureCreatorEvent.APP_STARTED));
eventDispatcher.addEventListener(ProfileEvent.OPEN_SAVE_WINDOW, onOpenSaveProfile);
eventDispatcher.addEventListener(ProfileEvent.SAVE_PROFILE, onSaveProfile);
eventDispatcher.addEventListener(CustomVarsEvent.CANNOT_ADD_VAR, onCannotAddVar);

super.startup();
}

private function onCannotAddVar(e:CustomVarsEvent):void
{
Alert.show("You can't add a new custom variable until the previous one is filled in", "Can't add Custom Variable");
}

/**
* Opens Save Profile window
*/
Expand Down
1 change: 1 addition & 0 deletions src/com/structurecreator/events/CustomVarsEvent.as
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.structurecreator.events
public class CustomVarsEvent extends Event
{
public static var CUSTOM_VAR_ADDED:String = 'customVarAdded';
public static var CANNOT_ADD_VAR:String = 'cannotAddVar';

public function CustomVarsEvent(type:String)
{
Expand Down
15 changes: 11 additions & 4 deletions src/com/structurecreator/model/CustomVariableModel.as
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ package com.structurecreator.model
{
trace("Add a custom variable");
//TODO check if last is empty

var cv:CustomVariableVO = new CustomVariableVO();
customVars.push(cv);
eventDispatcher.dispatchEvent(new CustomVarsEvent(CustomVarsEvent.CUSTOM_VAR_ADDED));
var lastItem:CustomVariableVO = customVars.length > 0 ? customVars[customVars.length - 1] as CustomVariableVO : null;
if (lastItem && lastItem.value == 'value' && lastItem.variable == 'variable')
{
eventDispatcher.dispatchEvent(new CustomVarsEvent(CustomVarsEvent.CANNOT_ADD_VAR));
}
else
{
var cv:CustomVariableVO = new CustomVariableVO();
customVars.push(cv);
eventDispatcher.dispatchEvent(new CustomVarsEvent(CustomVarsEvent.CUSTOM_VAR_ADDED));
}
}
}
}

0 comments on commit e1fd68f

Please sign in to comment.