// MichaelMcElroy.NET // Copyright 2007, Michael McElroy. // All rights are reserved. // Entity function Entity () {} this . prototype = Entity . prototype; this . prototype . superclass = null; // Methods this . prototype . initialize = function () { return; }; this . prototype . finalize = function () { return; }; this . prototype . graft = function (that) { var property; // Copy each property from 'this' to 'that'. for (property in this) { if (typeof (that [property]) == "undefined") { that [property] = this [property]; } } // Assign a superclass to each function in 'that'. for (property in that) { if (typeof (that [property]) == "function") { that [property] . superclass = this; } } return; }; // Delegate function Delegate () {} this . prototype = Delegate . prototype; this . prototype . superclass = Entity . prototype; // Members this . prototype . proxy = null; this . prototype . entity = null; this . prototype . method = null; // Methods this . prototype . initialize = function () { arguments . callee . superclass . initialize . apply (this); return; }; this . prototype . act = function () { return (this . proxy . apply (this, arguments)); }; this . prototype . getProxy = function () { return (this . proxy); }; this . prototype . setEntity = function (entity) { this . entity = entity; this . updateProxy (); return; }; this . prototype . setMethod = function (method) { this . method = method; this . updateProxy (); return; }; this . prototype . updateProxy = function () { var entity; var method; entity = this . entity; method = this . method; if ((entity != null) && (method != null)) { this . proxy = function () {return (method . apply (entity, arguments));}; } else { this . proxy = function () {return;}; } return; }; this . prototype . register = function (entity, event) { if (entity . addEventListener) { entity . addEventListener (event, this . getProxy (), false); } else if (entity . attachEvent) { entity . attachEvent ("on" + event, this . getProxy ()); } else { entity ["on" + event] = this . getProxy (); } return; }; this . prototype . unregister = function (entity, event) { if (entity . removeEventListener) { entity . removeEventListener (event, this . getProxy (), false); } else if (entity . detatchEvent) { entity . detachEvent ("on" + entity, this . getProxy ()); } else if (entity ["on" + event] == this . getProxy ()) { entity ["on" + event] = null; } return; }; this . prototype . superclass . graft (this . prototype); // Stars function Stars () {} this . prototype = Stars . prototype; this . prototype . superclass = Entity . prototype; // Members this . prototype . address = null; this . prototype . starsInterface = null; // Methods this . prototype . initialize = function (address) { arguments . callee . superclass . initialize . apply (this); this . starsInterface = new Interface (); this . starsInterface . initialize (address); return; }; this . prototype . getGraphics = function () { var graphics; graphics = null; if (this . starsInterface != null) { graphics = this . starsInterface . getGraphics (); } return (graphics); }; this . prototype . superclass . graft (this . prototype); // Interface function Interface () {} this . prototype = Interface . prototype; this . prototype . superclass = Entity . prototype; // Members this . prototype . picturesAddress = "resources"; this . prototype . dimStarPictureName = "star.dim.png"; this . prototype . brightStarPictureName = "star.bright.png"; this . prototype . zoomPictureName = "zoom.png"; this . prototype . activeZoomKnobPictureName = "knob.active.png"; this . prototype . inactiveZoomKnobPictureName = "knob.inactive.png"; this . prototype . address = null; this . prototype . engine = null; this . prototype . zoom = null; this . prototype . zoomActive = null; this . prototype . pixelRatio = null; this . prototype . borderThickness = null; this . prototype . rowDimension = null; this . prototype . columnDimension = null; this . prototype . boardRowDimension = null; this . prototype . boardColumnDimension = null; this . prototype . arenaRowDimension = null; this . prototype . arenaColumnDimension = null; this . prototype . zoomRowDimension = null; this . prototype . zoomColumnDimension = null; this . prototype . spaceRowDimension = null; this . prototype . graphics = null; this . prototype . brightStarGraphics = null; this . prototype . dimStarGraphics = null; this . prototype . boardGraphics = null; this . prototype . arenaGraphics = null; this . prototype . zoomGraphics = null; this . prototype . zoomKnobGraphics = null; this . prototype . zoomGlassGraphics = null; this . prototype . activateZoomDelegate = null; this . prototype . deactivateZoomDelegate = null; this . prototype . selectZoomDelegate = null; this . prototype . selectStarDelegate = null; // Methods this . prototype . initialize = function (address) { arguments . callee . superclass . initialize . apply (this); this . setAddress (address); this . initializeQueries (); this . initializeEngine (); this . initializeValues (); this . initializeGraphics (); this . initializeDelegates (); this . reset (); return; }; this . prototype . initializeQueries = function () { return; }; this . prototype . initializeEngine = function () { this . engine = new Engine (); this . engine . initialize (); return; }; this . prototype . initializeValues = function () { this . zoom = 1.00; this . zoomActive = 0; this . pixelRatio = 0; // 1 unit = [pixelRatio] pixels. this . minimumPixelRatio = 50; this . maximumPixelRatio = 100; this . borderThickness = 0.00; //0.32; this . rowDimension = this . engine . getRowDimension () + this . borderThickness + this . borderThickness; this . columnDimension = this . engine . getColumnDimension () + this . borderThickness + this . borderThickness; this . boardRowDimension = this . rowDimension - this . borderThickness - this . borderThickness; this . boardColumnDimension = this . columnDimension - this . borderThickness - this . borderThickness; this . arenaRowDimension = this . rowDimension - this . borderThickness - this . borderThickness; this . arenaColumnDimension = this . columnDimension - this . borderThickness - this . borderThickness; this . glassRowDimension = this . arenaRowDimension; this . glassColumnDimension = this . arenaColumnDimension; this . starRowDimension = 2.7; this . starColumnDimension = 2.7; this . zoomRowDimension = 0.00; 0.16; this . zoomColumnDimension = 1.00; this . spaceRowDimension = 0.08; return; }; this . prototype . initializeGraphics = function () { this . graphics = document . createElement ("div"); this . graphics . style . zIndex = "0"; this . graphics . style . position = "relative"; this . graphics . render = 1; this . boardGraphics = document . createElement ("div"); this . boardGraphics . style . zIndex = "1"; this . boardGraphics . style . position = "absolute"; this . boardGraphics . style . backgroundColor = "#000000"; //"#ecece2"; this . boardGraphics . style . overflow = "hidden"; this . boardGraphics . style . marginLeft = "50%"; this . arenaGraphics = document . createElement ("div"); this . arenaGraphics . style . zIndex = "2"; this . arenaGraphics . style . position = "absolute"; this . arenaGraphics . style . backgroundColor = "#030c1d"; this . arenaGraphics . style . overflow = "hidden"; this . arenaGraphics . style . marginLeft = "50%"; this . glassGraphics = document . createElement ("div"); this . glassGraphics . style . zIndex = "3"; this . glassGraphics . style . position = "absolute"; this . glassGraphics . style . overflow = "hidden"; this . glassGraphics . style . cursor = "pointer"; this . glassGraphics . style . marginLeft = "50%"; this . zoomGraphics = document . createElement ("div"); this . zoomGraphics . style . zIndex = "10"; this . zoomGraphics . style . position = "absolute"; this . zoomGraphics . style . marginLeft = "50%"; this . zoomGraphics . style . backgroundImage = "url('" + this . address + "/" + this . picturesAddress + "/" + this . zoomPictureName + "')"; this . zoomGraphics . style . display = "none"; this . zoomKnobGraphics = document . createElement ("div"); this . zoomKnobGraphics . style . zIndex = "1"; this . zoomKnobGraphics . style . position = "absolute"; this . zoomKnobGraphics . style . overflow = "hidden"; this . zoomGlassGraphics = document . createElement ("div"); this . zoomGlassGraphics . style . zIndex = "2"; this . zoomGlassGraphics . style . position = "absolute"; this . zoomGlassGraphics . style . overflow = "hidden"; this . zoomGlassGraphics . style . cursor = "pointer"; this . dimStarGraphics = new Array (); this . brightStarGraphics = new Array (); for (var rowIndex = 0; rowIndex < this . engine . getRowDimension (); rowIndex = rowIndex + 1) { this . dimStarGraphics [rowIndex] = new Array (); this . brightStarGraphics [rowIndex] = new Array (); for (var columnIndex = 0; columnIndex < this . engine . getColumnDimension (); columnIndex = columnIndex + 1) { this . dimStarGraphics [rowIndex] [columnIndex] = document . createElement ("img"); this . dimStarGraphics [rowIndex] [columnIndex] . style . zIndex = "0"; this . dimStarGraphics [rowIndex] [columnIndex] . style . position = "absolute"; this . dimStarGraphics [rowIndex] [columnIndex] . src = this . address + "/" + this . picturesAddress + "/" + this . dimStarPictureName; this . dimStarGraphics [rowIndex] [columnIndex] . alt = "(Loading the dim star picture ...)"; this . brightStarGraphics [rowIndex] [columnIndex] = document . createElement ("img"); this . brightStarGraphics [rowIndex] [columnIndex] . style . zIndex = "0"; this . brightStarGraphics [rowIndex] [columnIndex] . style . position = "absolute"; this . brightStarGraphics [rowIndex] [columnIndex] . src = this . address + "/" + this . picturesAddress + "/" + this . brightStarPictureName; this . brightStarGraphics [rowIndex] [columnIndex] . alt = "(Loading the bright star picture ...)"; } } this . assembleGraphics (); return; }; this . prototype . initializeDelegates = function () { this . activateZoomDelegate = new Delegate (); this . activateZoomDelegate . initialize (); this . activateZoomDelegate . setEntity (this); this . activateZoomDelegate . setMethod (this . activateZoom); this . deactivateZoomDelegate = new Delegate (); this . deactivateZoomDelegate . initialize (); this . deactivateZoomDelegate . setEntity (this); this . deactivateZoomDelegate . setMethod (this . deactivateZoom); this . selectZoomDelegate = new Delegate (); this . selectZoomDelegate . initialize (); this . selectZoomDelegate . setEntity (this); this . selectZoomDelegate . setMethod (this . selectZoom); this . selectStarDelegate = new Delegate (); this . selectStarDelegate . initialize (); this . selectStarDelegate . setEntity (this); this . selectStarDelegate . setMethod (this . selectStar); return; }; this . prototype . assembleGraphics = function () { this . graphics . appendChild (this . zoomGraphics); this . graphics . appendChild (this . boardGraphics); this . graphics . appendChild (this . arenaGraphics); this . graphics . appendChild (this . glassGraphics); this . zoomGraphics . appendChild (this . zoomKnobGraphics); this . zoomGraphics . appendChild (this . zoomGlassGraphics); for (var rowIndex = 0; rowIndex < this . engine . getRowDimension (); rowIndex = rowIndex + 1) { for (var columnIndex = 0; columnIndex < this . engine . getColumnDimension (); columnIndex = columnIndex + 1) { this . arenaGraphics . appendChild (this . dimStarGraphics [rowIndex] [columnIndex]); this . arenaGraphics . appendChild (this . brightStarGraphics [rowIndex] [columnIndex]); } } return; }; this . prototype . reset = function (event) { this . activateZoomDelegate . register (this . zoomGlassGraphics, "mousedown"); this . deactivateZoomDelegate . register (this . zoomGlassGraphics, "mouseup"); this . deactivateZoomDelegate . register (this . zoomGlassGraphics, "mouseout"); this . selectZoomDelegate . register (this . zoomGlassGraphics, "mousedown"); this . selectZoomDelegate . register (this . zoomGlassGraphics, "mousemove"); this . selectStarDelegate . register (this . glassGraphics, "click"); this . render (); // event . stopPropagation (); // event . preventDefault (); return; }; this . prototype . setAddress = function (address) { this . address = (address != null) ? address : ""; return; }; this . prototype . activateZoom = function (event) { this . zoomActive = 1; this . graphics . render = 1; this . render (); // event . stopPropagation (); // event . preventDefault (); event . cancelBubble = true; return; }; this . prototype . deactivateZoom = function (event) { this . zoomActive = 0; this . graphics . render = 1; this . render (); // event . stopPropagation (); // event . preventDefault (); event . cancelBubble = true; return; }; this . prototype . selectZoom = function (event) { var columnCoordinate; var columnIndex; if (this . zoomActive) { columnCoordinate = this . getColumnCoordinate (event); this . zoom = columnCoordinate / this . zoomColumnDimension / 100; this . zoom = (this . zoom < 0) ? 0 : this . zoom; this . zoom = (this . zoom > 1) ? 1 : this . zoom; this . graphics . render = 1; this . render (); } // event . stopPropagation (); // event . preventDefault (); event . cancelBubble = true; return (false); }; this . prototype . selectStar = function (event) { var rowCoordinate; var columnCoordinate; var rowIndex; var columnIndex; rowCoordinate = this . getRowCoordinate (event); columnCoordinate = this . getColumnCoordinate (event); rowIndex = this . getRowIndex (rowCoordinate); columnIndex = this . getColumnIndex (columnCoordinate); this . engine . selectStar (rowIndex, columnIndex); this . render (); event . stopPropagation (); event . preventDefault (); event . cancelBubble = true; return (false); }; this . prototype . getRowIndex = function (coordinate) { var index; index = null; if ((typeof (coordinate) != "undefined") && (coordinate != null)) { index = Math . floor (coordinate / (Math . floor (this . glassRowDimension * this . pixelRatio) / this . engine . getRowDimension ())); } return (index); }; this . prototype . getColumnIndex = function (coordinate) { var index; index = null; if ((typeof (coordinate) != "undefined") && (coordinate != null)) { index = Math . floor (coordinate / (Math . floor (this . glassColumnDimension * this . pixelRatio) / this . engine . getColumnDimension ())); } return (index); }; this . prototype . getRowCoordinate = function (event) { var rowCoordinate; rowCoordinate = null; if ((typeof (event) != "undefined") && (event != null)) { if (typeof (event . offsetY) != "undefined") { rowCoordinate = event . offsetY; } if (typeof (event . layerY) != "undefined") { rowCoordinate = event . layerY; } } return (rowCoordinate); }; this . prototype . getColumnCoordinate = function (event) { var columnCoordinate; columnCoordinate = null; if ((typeof (event) != "undefined") && (event != null)) { if (typeof (event . offsetX) != "undefined") { columnCoordinate = event . offsetX; } if (typeof (event . layerX) != "undefined") { columnCoordinate = event . layerX; } } return (columnCoordinate); }; this . prototype . getQueries = function () { var queries; var queryText; var queryPairs; queries = new Object (); queryText = window . location . search . substring (1); queryPairs = queryText . split ("&"); for (var pairIndex = 0; pairIndex < queryPairs . length; pairIndex = pairIndex + 1) { var name; var value; name = queryPairs [pairIndex] . split ("=") [0]; value = queryPairs [pairIndex] . split ("=") [1]; queries [name] = value; } return (queries); }; this . prototype . getGraphics = function () { return (this . graphics); }; this . prototype . getPixels = function (units, ratio) { var pixels; pixels = 0; if ((typeof (units) != "undefined") && (units != null) && (typeof (ratio) != "undefined") && (ratio != null)) { pixels = units * ratio; } pixels = Math . round (pixels); return (pixels); }; this . prototype . render = function () { if (this . graphics != null) { // Zoom this . pixelRatio = (this . maximumPixelRatio - this . minimumPixelRatio) * this . zoom + this . minimumPixelRatio; this . pixelRatio = (this . pixelRatio < this . minimumPixelRatio) ? this . minimumPixelRatio : this . pixelRatio; this . pixelRatio = (this . pixelRatio > this . maximumPixelRatio) ? this . maximumPixelRatio : this . pixelRatio; // Static this . zoomKnobGraphics . style . top = "0px"; this . zoomKnobGraphics . style . left = this . getPixels (this . zoom * this . zoomColumnDimension - this . zoomRowDimension / 2, this . maximumPixelRatio) + "px"; this . zoomKnobGraphics . style . height = this . getPixels (this . zoomRowDimension, this . maximumPixelRatio) + "px"; this . zoomKnobGraphics . style . width = this . getPixels (this . zoomRowDimension, this . maximumPixelRatio) + "px"; this . zoomKnobGraphics . style . backgroundImage = "url('" + this . address + "/" + this . picturesAddress + "/" + (this . zoomActive ? this . activeZoomKnobPictureName : this . inactiveZoomKnobPictureName) + "')"; if (this . graphics . render) { this . graphics . render = 0; this . graphics . style . top = "0px"; this . graphics . style . left = "0px"; this . graphics . style . height = this . getPixels (this . zoomRowDimension + this . spaceRowDimension, this . maximumPixelRatio) + this . getPixels (this . rowDimension, this . pixelRatio) + "px"; this . graphics . style . width = this . getPixels (this . zoomRowDimension + this . spaceRowDimension, this . maximumPixelRatio) + this . getPixels (this . columnDimension, this . maximumPixelRatio) + "px"; this . zoomGraphics . style . top = "0px"; this . zoomGraphics . style . left = - this . getPixels (this . zoomColumnDimension / 2, this . maximumPixelRatio) + "px"; this . zoomGraphics . style . height = this . getPixels (this . zoomRowDimension, this . maximumPixelRatio) + "px"; this . zoomGraphics . style . width = this . getPixels (this . zoomColumnDimension, this . maximumPixelRatio) + "px"; this . zoomGlassGraphics . style . top = "0px"; this . zoomGlassGraphics . style . left = "0px"; this . zoomGlassGraphics . style . height = this . getPixels (this . zoomRowDimension, this . maximumPixelRatio) + "px"; this . zoomGlassGraphics . style . width = this . getPixels (this . zoomColumnDimension, this . maximumPixelRatio) + "px"; this . boardGraphics . style . top = this . getPixels (this . zoomRowDimension + this . spaceRowDimension, this . maximumPixelRatio) + "px"; this . boardGraphics . style . left = - this . getPixels (this . columnDimension / 2, this . pixelRatio) + "px"; this . boardGraphics . style . height = this . getPixels (this . boardRowDimension, this . pixelRatio) + "px"; this . boardGraphics . style . width = this . getPixels (this . boardColumnDimension, this . pixelRatio) + "px"; this . arenaGraphics . style . top = this . getPixels (this . zoomRowDimension + this . spaceRowDimension, this . maximumPixelRatio) + this . getPixels (this . borderThickness, this . pixelRatio) + "px"; this . arenaGraphics . style . left = - this . getPixels (this . columnDimension / 2 - this . borderThickness, this . pixelRatio) + "px"; this . arenaGraphics . style . height = this . getPixels (this . arenaRowDimension, this . pixelRatio) + "px"; this . arenaGraphics . style . width = this . getPixels (this . arenaColumnDimension, this . pixelRatio) + "px"; this . glassGraphics . style . top = this . getPixels (this . zoomRowDimension + this . spaceRowDimension, this . maximumPixelRatio) + this . getPixels (this . borderThickness, this . pixelRatio) + "px"; this . glassGraphics . style . left = - this . getPixels (this . columnDimension / 2 - this . borderThickness, this . pixelRatio) + "px"; this . glassGraphics . style . height = this . getPixels (this . glassRowDimension, this . pixelRatio) + "px"; this . glassGraphics . style . width = this . getPixels (this . glassColumnDimension, this . pixelRatio) + "px"; for (var rowIndex = 0; rowIndex < this . engine . getRowDimension (); rowIndex = rowIndex + 1) { for (var columnIndex = 0; columnIndex < this . engine . getColumnDimension (); columnIndex = columnIndex + 1) { this . dimStarGraphics [rowIndex] [columnIndex] . style . top = this . getPixels (rowIndex - (this . starRowDimension - this . glassRowDimension / this . engine . getRowDimension ()) / 2, this . pixelRatio) + "px"; this . dimStarGraphics [rowIndex] [columnIndex] . style . left = this . getPixels (columnIndex - (this . starColumnDimension - this . glassColumnDimension / this . engine . getColumnDimension ()) / 2, this . pixelRatio) + "px"; this . dimStarGraphics [rowIndex] [columnIndex] . style . height = this . getPixels (this . starRowDimension, this . pixelRatio) + "px"; this . dimStarGraphics [rowIndex] [columnIndex] . style . width = this . getPixels (this . starColumnDimension, this . pixelRatio) + "px"; this . brightStarGraphics [rowIndex] [columnIndex] . style . top = this . getPixels (rowIndex - (this . starRowDimension - this . glassRowDimension / this . engine . getRowDimension ()) / 2, this . pixelRatio) + "px"; this . brightStarGraphics [rowIndex] [columnIndex] . style . left = this . getPixels (columnIndex - (this . starColumnDimension - this . glassColumnDimension / this . engine . getColumnDimension ()) / 2, this . pixelRatio) + "px"; this . brightStarGraphics [rowIndex] [columnIndex] . style . height = this . getPixels (this . starRowDimension, this . pixelRatio) + "px"; this . brightStarGraphics [rowIndex] [columnIndex] . style . width = this . getPixels (this . starColumnDimension, this . pixelRatio) + "px"; } } } // Dynamic for (var rowIndex = 0; rowIndex < this . engine . getRowDimension (); rowIndex = rowIndex + 1) { for (var columnIndex = 0; columnIndex < this . engine . getColumnDimension (); columnIndex = columnIndex + 1) { if (this . engine . getStarCode (rowIndex, columnIndex) == this . engine . getDimStarCode ()) { this . dimStarGraphics [rowIndex] [columnIndex] . style . display = "block"; this . brightStarGraphics [rowIndex] [columnIndex] . style . display = "none"; } else { this . dimStarGraphics [rowIndex] [columnIndex] . style . display = "none"; this . brightStarGraphics [rowIndex] [columnIndex] . style . display = "block"; } } } } return; }; this . prototype . superclass . graft (this . prototype); // Engine function Engine () {} this . prototype = Engine . prototype; this . prototype . superclass = Entity . prototype; // Members this . prototype . rowDimension = 5; this . prototype . columnDimension = 5; this . prototype . dimStarCode = 0; this . prototype . brightStarCode = 1; this . prototype . matrix = null; // Methods this . prototype . initialize = function (address) { arguments . callee . superclass . initialize . apply (this); this . initializeMatrix (); this . copyPattern (); return; }; this . prototype . reset = function () { this . copyPattern (); return; }; this . prototype . initializeMatrix = function () { this . matrix = null; this . matrix = new Array (); for (var rowIndex = 0; rowIndex < this . rowDimension; rowIndex = rowIndex + 1) { this . matrix [rowIndex] = new Array (); for (var columnIndex = 0; columnIndex < this . columnDimension; columnIndex = columnIndex + 1) { this . matrix [rowIndex] [columnIndex] = 0; } } return; }; this . prototype . copyPattern = function (pattern) { // The pattern parameter is ignored for now. // The default pattern has all the edge stars dim and the center stars bright. for (var rowIndex = 0; rowIndex < this . rowDimension; rowIndex = rowIndex + 1) { for (var columnIndex = 0; columnIndex < this . columnDimension; columnIndex = columnIndex + 1) { if ((rowIndex == 0) || (rowIndex == (this . rowDimension - 1)) || (columnIndex == 0) || (columnIndex == (this . columnDimension - 1))) { this . matrix [rowIndex] [columnIndex] = this . dimStarCode; } else { this . matrix [rowIndex] [columnIndex] = this . brightStarCode; } } } return; }; this . prototype . getRowDimension = function () { return (this . rowDimension); }; this . prototype . getColumnDimension = function () { return (this . columnDimension); }; this . prototype . getDimStarCode = function () { return (this . dimStarCode); }; this . prototype . getBrightStarCode = function () { return (this . brightStarCode); }; this . prototype . getStarCode = function (rowIndex, columnIndex) { var starCode; starCode = null; if ((this . matrix != null) && (rowIndex >= 0) && (rowIndex < this . rowDimension) && (columnIndex >= 0) && (columnIndex < this . columnDimension)) { starCode = this . matrix [rowIndex] [columnIndex]; } return (starCode); }; this . prototype . selectStar = function (rowIndex, columnIndex) { if (this . matrix != null) { this . invertStar (rowIndex - 1, columnIndex + 0); this . invertStar (rowIndex + 0, columnIndex - 1); this . invertStar (rowIndex + 0, columnIndex + 0); this . invertStar (rowIndex + 0, columnIndex + 1); this . invertStar (rowIndex + 1, columnIndex + 0); } return; }; this . prototype . invertStar = function (rowIndex, columnIndex) { if ((rowIndex >= 0) && (rowIndex < this . rowDimension) && (columnIndex >= 0) && (columnIndex < this . columnDimension)) { this . matrix [rowIndex] [columnIndex] = (this . matrix [rowIndex] [columnIndex] == this . dimStarCode) ? this . brightStarCode : this . dimStarCode; } return; }; this . prototype . superclass . graft (this . prototype);