joo.classLoader.prepare("package net.jangaron.ui",[

"import joo.lang.JOObject",
"import joo.util.PropertyAware",
"import joo.css.Color",
"import net.jangaron.KeyMap",
"import net.jangaron.Vector",
"import net.jangaron.TeamColor",""],

"public class Player extends JOObject",function($jooPublic,$jooPrivate){with(net.jangaron.ui)with($jooPublic)with($jooPrivate)return[function(){joo.classLoader.init(TeamColor);},

"private static const",{DEBUG:false},

"public function Player",function(props){
this[$super]();
PropertyAware.setProperties(this,props);
if(!this.keyMap){
this.keyMap=new KeyMap();
}
},

"public function isUser",function(){
return this.user;
},

"public function setUser",function(user){
this.user=user;
},

"public function isVisible",function(){
return this.visible;
},

"public function setVisible",function(visible){
this.visible=visible;
},

"public function getName",function(){
return this.name;
},

"public function setName",function(name){
this.name=name;
},

"public function getTeam",function(){
return this.getTeamColor().getTeam();
},

"public function getColor",function(){
return this.getTeamColor().getColor();
},

"public function getTeamColor",function(){
return this.teamColor;
},

"public function setTeamColor",function(teamColor){
this.teamColor=teamColor;
},

"public function getKeyMap",function(){
return this.keyMap;
},

"public function setKeyMap",function(keyMap){
this.keyMap=keyMap;
},

"public function getMinSpeed",function(){
return this.minSpeed;
},

"public function setMinSpeed",function(minSpeed){
this.minSpeed=minSpeed;
},

"public function getMaxSpeed",function(){
return this.maxSpeed;
},

"public function setMaxSpeed",function(maxSpeed){
this.maxSpeed=maxSpeed;
},

"public function getHasViewPort",function(){
var hasViewPort=this.isVisible()||this.isUser();
if(DEBUG)
trace("Player["+this+"].getHasViewPort("+hasViewPort+")="+hasViewPort);
return hasViewPort;
},

"public function setHasViewPort",function(hasViewPort){
if(DEBUG)
trace("Player["+this+"].setHasViewPort("+hasViewPort+")");
return this.setVisible(hasViewPort);
},

"override public function hashCode",function(){
return this.id;
},

"override public function equals",function(player){
return player&&this.id===player["id"];
},

"override public function toString",function(){
return this.name;
},

"public var",{id: undefined},
"public var",{user: undefined},
"public var",{visible: undefined},
"public var",{name: undefined},
"public var",{teamColor:function(){return(TeamColor.GOLD_ORANGE);}},
"public var",{keyMap: undefined},
"public var",{minSpeed: undefined},
"public var",{maxSpeed: undefined},
"public var",{startVector: undefined},
"public var",{style: undefined},
];},[]
);joo.classLoader.prepare("package net.jangaron.ui",[

"import joo.css.Color",
"import joo.lang.JOObject",
"import joo.util.TimedExecutor",
"import joo.util.Arrays",
"import joo.http.Cookie",
"import joo.html.Browser",
"import joo.html.Document2",
"import joo.html.Element2",
"import joo.css.URL",
"import joo.css.BackgroundRepeat",
"import joo.css.BackgroundPosition",
"import joo.sound.Sound",
"import joox.faces.component.UIComponent",
"import joox.faces.component.UIViewRoot",
"import joox.faces.component.UIData",
"import joox.faces.component.UIOutput",
"import joox.cache.DependencyTracker",
"import joox.cache.DependencyAwareAspect",
"import net.jangaron.Direction",
"import net.jangaron.Vector",
"import net.jangaron.TeamColor",
"import net.jangaron.KeyMap",
"import net.jangaron.Grid",
"import net.jangaron.ui.Player",
"import KeyEvent",""],

"public class Settings extends JOObject",function($jooPublic,$jooPrivate){with(net.jangaron.ui)with($jooPublic)with($jooPrivate)return[function(){joo.classLoader.init(UIData,Browser,KeyEvent,BackgroundRepeat,TeamColor,Player,URL,Direction,Color);},

"private static const",{DEBUG:false},function()

{
DependencyAwareAspect.instrumentClass(Settings);
DependencyAwareAspect.instrumentClass(Player);
},

"private static const",{TEAM_PRESETS:function(){return({
"One on One":[TeamColor.GOLD_ORANGE,TeamColor.BLUE_BLUE,TeamColor.GREEN_GREEN,
TeamColor.EARTH_BROWN,TeamColor.WATER_AQUA,TeamColor.PINK_PINK],
"Users vs. MCP":[TeamColor.GOLD_ORANGE,TeamColor.GOLD_RED,TeamColor.GOLD_YELLOW,
TeamColor.BLUE_VIOLET,TeamColor.BLUE_BLUE,TeamColor.BLUE_BLUE],
"Lone Hero":[TeamColor.GOLD_ORANGE,
TeamColor.BLUE_VIOLET,TeamColor.BLUE_BLUE,
TeamColor.BLUE_BLUE,TeamColor.BLUE_BLUE,TeamColor.BLUE_BLUE],
"Pairs":[TeamColor.GOLD_ORANGE,TeamColor.GOLD_RED,
TeamColor.BLUE_VIOLET,TeamColor.BLUE_BLUE,
TeamColor.EARTH_BROWN,TeamColor.EARTH_SILICON]
});}},
"private static const",{TEAM_PRESET_NAMES:function(){
var names=[];
for(var name in TEAM_PRESETS){
names.push(name);
}
return names;
}},

"private const",{initializers:function(){return([
new Player({id:"1",user:true,visible:true,name:"Flynn",teamColor:TeamColor.GOLD_ORANGE,
keyMap:new KeyMap({
left:KeyEvent.DOM_VK_LEFT,right:KeyEvent.DOM_VK_RIGHT,
lookLeft:KeyEvent.DOM_VK_1,lookRight:KeyEvent.DOM_VK_3,lookBackwards:KeyEvent.DOM_VK_2,
changeView:KeyEvent.DOM_VK_4,
faster:KeyEvent.DOM_VK_UP,slower:KeyEvent.DOM_VK_DOWN}),
minSpeed:25,maxSpeed:80}),
new Player({id:"2",user:false,visible:false,name:"Sark",teamColor:TeamColor.BLUE_VIOLET,
keyMap:new KeyMap({
left:KeyEvent.DOM_VK_A,right:KeyEvent.DOM_VK_D,
lookLeft:KeyEvent.DOM_VK_Q,lookRight:KeyEvent.DOM_VK_E,lookBackwards:KeyEvent.DOM_VK_X,
changeView:KeyEvent.DOM_VK_Y,
faster:KeyEvent.DOM_VK_W,slower:KeyEvent.DOM_VK_S}),
minSpeed:28,maxSpeed:80}),
new Player({id:"3",user:false,visible:false,name:"Tron",teamColor:TeamColor.GOLD_RED,
keyMap:new KeyMap({
left:KeyEvent.DOM_VK_F,right:KeyEvent.DOM_VK_H,
lookLeft:KeyEvent.DOM_VK_R,lookRight:KeyEvent.DOM_VK_Z,lookBackwards:KeyEvent.DOM_VK_B,
changeView:KeyEvent.DOM_VK_V,
faster:KeyEvent.DOM_VK_T,slower:KeyEvent.DOM_VK_G}),
minSpeed:27,maxSpeed:80}),
new Player({id:"4",user:false,visible:false,name:"Blue 1",teamColor:TeamColor.BLUE_BLUE,
keyMap:new KeyMap({
left:KeyEvent.DOM_VK_J,right:KeyEvent.DOM_VK_L,
lookLeft:KeyEvent.DOM_VK_U,lookRight:KeyEvent.DOM_VK_O,lookBackwards:KeyEvent.DOM_VK_M,
changeView:KeyEvent.DOM_VK_M,
faster:KeyEvent.DOM_VK_I,slower:KeyEvent.DOM_VK_K}),
minSpeed:26,maxSpeed:80}),
new Player({id:"5",user:false,visible:false,name:"Ram",teamColor:TeamColor.GOLD_YELLOW,
minSpeed:24,maxSpeed:80}),
new Player({id:"6",user:false,visible:false,name:"Blue 2",teamColor:TeamColor.BLUE_BLUE,
minSpeed:25,maxSpeed:80})
]);}},

"public function Settings",function(){
this[$super]();
this[$createGridAnimationTimer]();
for(var i=0;i<this[$initializers].length;++i){
this.players.push(this[$initializers][i]);
}
this.teamColors=TeamColor.TEAMS_AND_COLORS;
var storedSettingsStr=new Cookie("jangaron").load();
if(storedSettingsStr){
var storedSettings=JOObject.fromJsonString(storedSettingsStr);
if(DEBUG){
trace("retrieved settings, json:");
window["console"].dir(storedSettings);
}
this.fromJson(storedSettings);
if(this.menuGridAnimated){
this[$gridAnimationTimer].start();
}
}
if(this.isSoundAvailable()){
this[$music]=new Sound("settings/ambient.mp3");
this[$sounds]={
click:new Sound("game/beep.mp3"),
yes:new Sound("settings/yes.mp3"),
no:new Sound("settings/no.mp3"),
transform:new Sound("settings/transform.mp3")
};
this[$updateSoundVolume]();
this[$music].setVolume(this.musicVolume);
if(this.musicEnabled){
this[$music].start(0,32767);
}
}
window["settings"]=this;
},

"private function createGridAnimationTimer",function(){
var body=Document2.getInstance().getBody();
var gridOffset=new Vector(33,33,Direction.NORTH);
body.setStyle({
backgroundImage:new URL("settings/grid-large.png"),
backgroundRepeat:BackgroundRepeat.REPEAT,
backgroundPosition:BackgroundPosition.fromString(gridOffset.toString())
});
this[$gridAnimationTimer]=new TimedExecutor(function(){
var turn=Math.random();
if(turn<0.005){
gridOffset.turnLeft();
}else if(turn>0.995){
gridOffset.turnRight();
}
gridOffset.move(1);
gridOffset.x=(gridOffset.x+100)%100;
gridOffset.y=(gridOffset.y+100)%100;
body.getStyle().setBackgroundPosition(BackgroundPosition.fromString(gridOffset.toString()));
return undefined;
},40);
},

"private function removeGridAnimation",function(){
this[$gridAnimationTimer].stop();
this[$gridAnimationTimer]=null;
Document2.getInstance().getBody().getStyle().setBackgroundImage(URL.NONE);
},

"public function isMenuGridAnimated",function(){
return this.menuGridAnimated;
},

"public function setMenuGridAnimated",function(animate){
if(this[$setBoolean]("menuGridAnimated",animate)){
if(animate)
this[$gridAnimationTimer].start();
else
this[$gridAnimationTimer].stop();
}
},

"public function getEngine",function(){
return Browser.ENGINE;
},

"private static function USER_PREDICATE",function(p){
return p.isUser();
},

"public function getUserPlayers",function(){
return this.getPlayers().filter(USER_PREDICATE);
},

"public function getFirstUserPlayerColor",function(){
var firstUserPlayer=this.getUserPlayers()[0];
return firstUserPlayer?firstUserPlayer.getColor():Color.GRAY;
},

"private static function comparePlayers",function(p1,p2){
if(p1==p2)
return 0;
var p1tc=p1.getTeamColor();
var p2tc=p2.getTeamColor();
if(p1tc.equals(p2tc)){
return p1.id<p2.id?-1:1;
}
return p1tc.index-p2tc.index;
},

"public function getPlayers",function(){
this.players.sort(comparePlayers);
return this.players;
},

"public function setPlayers",function(players){
this.players=players;
},

"public function getNumberOfPlayers",function(){
return this.getPlayers().length;
},

"public function setNumberOfPlayers",function(n){
var delta=n-this.players.length;
if(delta>0){
this.addPlayers(delta);
}else if(delta<0){
this.deletePlayers(n,-delta);
}
},

"public function getSelectedTab",function(){
return this.selectedTab;
},

"public function setSelectedTab",function(selectedTab){
this.selectedTab=selectedTab;
},

"public function selectTab",function(actionEvent){
var tab=actionEvent.component;
this.setSelectedTab(tab.getValue());
},

"public function getTeamPresetNames",function(){
return TEAM_PRESET_NAMES;
},

"public function getTeamPresetName",function(){
return"";
},

"public function setTeamPresetName",function(teamPresetName){
if(teamPresetName.length>0){
var teamPreset=TEAM_PRESETS[teamPresetName];
var plrs=this.players;
for(var i=0;i<plrs.length;++i){
var p=plrs[i];
p.setTeamColor(teamPreset[i]);
}
}
},

"private function getSound",function(name){
return this[$sounds][name];
},

"public function playSound",function(name){
if(this.isSoundAvailable()&&this.soundEnabled){
this[$getSound](name).start();
}
},

"private function setBoolean",function(propertyName,value){
if(this[propertyName]!=value){
this[propertyName]=value;
if(this.isSoundAvailable()&&this.soundEnabled)
this[$getSound](value?"yes":"no").start();
return true;
}
return false;
},

"public function getHighRim",function(){
return this.highRim;
},

"public function setHighRim",function(value){
return this[$setBoolean]("highRim",value);
},

"public function getTransparentCycleWalls",function(){
return this.transparentCycleWalls;
},

"public function setTransparentCycleWalls",function(value){
return this[$setBoolean]("transparentCycleWalls",value);
},

"public function getGenerateObstacles",function(){
return this.generateObstacles;
},

"public function setGenerateObstacles",function(value){
return this[$setBoolean]("generateObstacles",value);
},

"public function isSoundAvailable",function(){
return Sound.isAvailable();
},

"public function getSoundEnabled",function(){
return this.isSoundAvailable()&&this.soundEnabled;
},

"public function setSoundEnabled",function(value){
return this[$setBoolean]("soundEnabled",value);
},

"public function getSoundVolume",function(){
return this.soundVolume;
},

"private function updateSoundVolume",function(){
var value=this.soundVolume;
for(var s in this[$sounds]){
this[$getSound](s).setVolume(value);
}
},

"public function setSoundVolume",function(value){
if(this.soundVolume!=value){
this.soundVolume=value;
this[$updateSoundVolume]();
return true;
}
return false;
},

"public function getMusicEnabled",function(){
return this.isSoundAvailable()&&this.musicEnabled;
},

"public function setMusicEnabled",function(value){
if(this[$setBoolean]("musicEnabled",value)){
if(value){
this[$music].start(0,32767);
}else{
this[$music].stop();
}
return true;
}
return false;
},

"public function getMusicVolume",function(){
return this.musicVolume;
},

"public function setMusicVolume",function(value){
if(this.musicVolume!=value){
this.musicVolume=value;
this[$music].setVolume(value);
return true;
}
return false;
},

"public function isPlayerMaximumReached",function(){
return this.getPlayers().length>=this[$initializers].length;
},

"public function isViewMaximumReached",function(){
var plrs=this.getPlayers();
if(plrs.length>=4){
var views=0;
for(var i=0;i<plrs.length;++i){
var player=plrs[i];
if(player.getHasViewPort()){
++views;
if(views>=4){
return true;
}
}
}
}
return false;
},

"public function addPlayer",function(){
this.addPlayers(1);
},

"public function addPlayers",function(n){
for(var i=0;i<this[$initializers].length;++i){
var initializer=this[$initializers][i];
if(!Arrays.containsEquals(this.players,initializer)){
this.players.push(initializer);
if(--n==0)
break;
}
}
DependencyTracker.fireDependency(this,"players");
},

"public function deletePlayer",function(actionEvent){
var targetComponent=actionEvent.component;
while(!(is(targetComponent,UIData))){
targetComponent=targetComponent.getParent();
}
var i=(targetComponent).getRowIndex();
this.deletePlayers(i,1);
},

"public function deletePlayers",function(startIndex,n){
this.players.splice(startIndex,n);
DependencyTracker.fireDependency(this,"players");
},

"public function isStartable",function(){
var onlyTeam;
var plrs=this.getPlayers();
for(var i=0;i<plrs.length;++i){
var player=plrs[i];
var team=player.getTeam();
if(!onlyTeam){
onlyTeam=team;
}else if(team!=onlyTeam){
return true;
}
}
return false;
},

"private function doSave",function(){
var storedSettings=this.toJson();


return new Cookie("jangaron").setDuration(365).setDomain("").save(JOObject.toJsonString(storedSettings));
},

"public function save",function(){
window.alert(this[$doSave]()
?"Settings saved successfully."
:"Sorry, settings could not be saved.\n"
+"Check your browser Cookie settings.\n"
+"If Cookies are allowed, the Cookie might be too large.");
},

"public function reset",function(){
if(window.confirm("Really reset all settings to their default values?")){
if(new Cookie("jangaron").remove()){
window.location["reload"]();
}else{
window.alert("Sorry, settings could not be removed.\n"
+"Check your browser Cookie settings.\n"
+"If Cookies are allowed, there might be\n"
+"an old Cookie hanging around.\n"
+"Then please try to remove all cookies from\n"
+"domain www.jangaron.net manually.");
}
}
},

"public function start",function(actionEvent){
if(!this.isStartable()){
window.alert("Please set up at least two players\nand two different teams before\nstarting the game!");
return;
}
this[$doSave]();
var view=actionEvent.component.getView();
view.setRendered(false);
view.invalidate(view.getId());
if(this.isSoundAvailable()&&this.soundEnabled){
var transform=this[$getSound]("transform");
this[$music].fade(transform.getDuration(),0);
transform.onSoundComplete=this[$doStart];
transform.start();
}else{
if(this.isSoundAvailable()&&this.musicEnabled){
this[$music].fade(500,0);
}
this[$doStart]();
}
},

"private bound function doStart",function(){
this[$calculateStartVectors]();
this[$removeGridAnimation]();
Grid.main(Number(this.width),Number(this.height),this.highRim,
this.transparentCycleWalls?.75:1,
this.generateObstacles?this.obstacleCnt:0,
this.musicEnabled?this.musicVolume:0,
this.soundEnabled?this.soundVolume:0,
this.players,
1000/Number(this.targetFPS));
},

"private function calculateStartVectors",function(){
var startX=Math.round(this.width/2);
var startY=Math.round(this.height/2);
var startVectors=[
new Vector(startX,10,Direction.NORTH),
new Vector(startX,this.height-10,Direction.SOUTH),
new Vector(10,startY,Direction.EAST),
new Vector(this.width-10,startY,Direction.WEST),
new Vector(10,10,Direction.EAST),
new Vector(this.width-10,10,Direction.WEST)
];
var startVectorByTeam={};
for(var i=0;i<this.players.length;++i){
var player=this.players[i];
var team=player.getTeam();
var startVector=startVectorByTeam[team];
if(!startVector){
startVector=startVectorByTeam[team]=startVectors.shift();
}
player.startVector=startVector.clone();

if(startVector.dir.dy){
var deltaX=startVector.x-startX;
if(deltaX<=0)
deltaX-=10;
startVector.x=startX-deltaX;
}else{
var deltaY=startVector.y-startY;
if(deltaY<=0)
deltaY-=10;
startVector.y=startY-deltaY;
}
}
},

"public function getJangaronEMail",function(){
return["mailto:joo","jangaron.net"].join("@");
},

"public function getMusicEMail",function(){
return["mailto:avi","jangaron.net"].join("@");
},

"private static const",{JSON_PROPERTIES:function(){return(["width","height","highRim","targetFPS","transparentCycleWalls",
"generateObstacles","obstacleCnt","musicEnabled","musicVolume","soundEnabled","soundVolume",
"showHelp","menuGridAnimated","players","selectedTab"]);}},

"override protected function isJsonProperty",function(property){
return Arrays.contains(JSON_PROPERTIES,property);
},

"public var",{teamColors: undefined},
"public var",{width:200},
"public var",{height:200},
"public var",{highRim:true},
"public var",{targetFPS:25},
"public var",{obstacleCnt:10},
"public var",{showHelp:false},
"public var",{players:function(){return([]);}},
"public var",{selectedTab: undefined},
"public var",{transparentCycleWalls:false},
"public var",{generateObstacles:false},
"public var",{soundEnabled:function(){return(Browser.ENGINE!=Browser.ENGINE_OPERA);}},
"public var",{soundVolume:40},
"public var",{musicEnabled:true},
"public var",{musicVolume:40},
"private var",{music: undefined},
"private var",{sounds: undefined},
"public var",{menuGridAnimated:false},
"private var",{gridAnimationTimer: undefined},
];},[]
);joo.classLoader.prepare("package net.jangaron.ui",[""],
"public interface ISettings",function($jooPublic,$jooPrivate){with(net.jangaron.ui)with($jooPublic)with($jooPrivate)return[

,

,

,

,

,

,

];},[]
);joo.classLoader.prepare("package net.jangaron.ui",[

"import joo.sound.Sound",
"import joo.html.Document2",
"import joo.html.Element2",
"import joo.css.Color",
"import joo.util.TimedExecutor",
"import joox.faces.Transformer",
"import joox.faces.component.UIViewRoot",""],

"public class Game",function($jooPublic,$jooPrivate){with(net.jangaron.ui)with($jooPublic)with($jooPrivate)return[function(){joo.classLoader.init(UIViewRoot);},

"public static function main",function(jangaronLogoContainerId,jangaronLogoId){
Sound.init(function(soundAvailable){
var doc=Document2.getInstance();
var logoContainer=doc.getElementById(jangaronLogoContainerId);


if(soundAvailable){
new Sound("settings/prepare-to-transport.mp3",true);
}
var logo=doc.getElementById(jangaronLogoId);
var logoColor=new Color(228,108,10);
var factor=0;
new TimedExecutor(function(){
factor+=.03;
logo.getStyle().setBackgroundColor(logoColor.darker(Math.min(factor,1)));
if(factor>=1.6){
initSettingsUI(logoContainer);
return false;
}
},80).start();
});
},

"private static function initSettingsUI",function(logoContainer){
Transformer.main();
logoContainer.remove();
if(Sound.isAvailable()){

var UIViewRootRender=UIViewRoot.prototype.render;
UIViewRoot.prototype.render=function(){
var settings=window["settings"];
settings.playSound("click");
return UIViewRootRender.call(this);
};
}

},
];},["main"]
);