Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Sven Slootweg | 7839380419 | 11 years ago |
@ -1,224 +0,0 @@
|
|||||||
/* Thanks to http://phrogz.net/js/classes/OOPinJS2.html */
|
|
||||||
Function.prototype.inheritsFrom = function(parentObject)
|
|
||||||
{
|
|
||||||
if(parentObject.constructor == Function)
|
|
||||||
{
|
|
||||||
/* Normal Inheritance */
|
|
||||||
this.prototype = new parentObject;
|
|
||||||
this.prototype.constructor = this;
|
|
||||||
this.prototype.parent = parentObject.prototype;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Pure Virtual Inheritance */
|
|
||||||
this.prototype = parentObject;
|
|
||||||
this.prototype.constructor = this;
|
|
||||||
this.prototype.parent = parentObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Class*/ RadiumEngine = function()
|
|
||||||
{
|
|
||||||
this.version = "1.0";
|
|
||||||
|
|
||||||
var /*Exception*/ Exception = this.Exception = function(message)
|
|
||||||
{
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
var /*Exception*/ Warning = this.Warning = function(message)
|
|
||||||
{
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
var /*Exception*/ ResourceException = this.ResourceException = function(message, resource, action)
|
|
||||||
{
|
|
||||||
this.resource = resource;
|
|
||||||
this.message = message;
|
|
||||||
this.action = action;
|
|
||||||
}
|
|
||||||
ResourceException.inheritsFrom(Exception);
|
|
||||||
|
|
||||||
var /*Exception*/ ResourceWarning = this.ResourceWarning = function(message, resource, action)
|
|
||||||
{
|
|
||||||
this.resource = resource;
|
|
||||||
this.message = message;
|
|
||||||
this.action = action;
|
|
||||||
}
|
|
||||||
ResourceWarning.inheritsFrom(Warning);
|
|
||||||
|
|
||||||
var /*Class*/ Player = this.Player = function()
|
|
||||||
{
|
|
||||||
this.credits = 0; /* Integer */
|
|
||||||
this.health = 1; /* Fraction */
|
|
||||||
this.resources = {}; /* Associative array -> Resource */
|
|
||||||
|
|
||||||
this.InitializeResource = function(resource, negative_allowed, min, max)
|
|
||||||
{
|
|
||||||
var resource_object = new Resource();
|
|
||||||
resource_object.name = resource;
|
|
||||||
|
|
||||||
if(negative_allowed !== undefined)
|
|
||||||
{
|
|
||||||
resource_object.negative_allowed = negative_allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(min !== undefined)
|
|
||||||
{
|
|
||||||
resource_object.minimum = min;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(min !== undefined)
|
|
||||||
{
|
|
||||||
resource_object.maximum = max;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(min != null && min > 0)
|
|
||||||
{
|
|
||||||
/* Set current amount of units to minimum boundary. */
|
|
||||||
resource_object.value = min;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.resources[resource] = resource_object;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.TakeResource = function(resource, amount)
|
|
||||||
{
|
|
||||||
if(this.resources[resource])
|
|
||||||
{
|
|
||||||
resource_object = this.resources[resource];
|
|
||||||
|
|
||||||
if(resource_object.value - amount < 0 && resource_object.negative_allowed == false)
|
|
||||||
{
|
|
||||||
throw new ResourceException("There are not enough units of this resource available.", resource, "take");
|
|
||||||
}
|
|
||||||
else if(resource_object.minimum != null && resource_object.value - amount < resource_object.minimum)
|
|
||||||
{
|
|
||||||
throw new ResourceException("Taking away this many units will violate the lower resource boundary.", resource, "take");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resource_object.value -= amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ResourceException("This resource does not exist.", resource, "take");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.GiveResource = function(resource, amount)
|
|
||||||
{
|
|
||||||
if(this.resources[resource])
|
|
||||||
{
|
|
||||||
resource_object = this.resources[resource];
|
|
||||||
|
|
||||||
if(resource_object.maximum != null && resource_object.value + amount > resource_object.maximum)
|
|
||||||
{
|
|
||||||
resource_object.value = resource_object.maximum;
|
|
||||||
throw new ResourceWarning("The upper boundary of the resource was reached.", resource, "give");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resource_object.value += amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ResourceException("This resource does not exist.", resource, "give");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.SetResource = function(resource, amount)
|
|
||||||
{
|
|
||||||
if(this.resources[resource])
|
|
||||||
{
|
|
||||||
resource_object = this.resources[resource];
|
|
||||||
|
|
||||||
if(resource_object.minimum != null && amount < resource_object.minimum)
|
|
||||||
{
|
|
||||||
throw new ResourceException("The specified amount is lower than the lower boundary of the resource.", resource, "set");
|
|
||||||
}
|
|
||||||
else if(resource_object.maximum != null && amount > resource_object.maximum)
|
|
||||||
{
|
|
||||||
throw new ResourceException("The specified amount is lower than the lower boundary of the resource.", resource, "set");
|
|
||||||
}
|
|
||||||
else if(resource_object.negative_allowed === false && amount < 0)
|
|
||||||
{
|
|
||||||
throw new ResourceException("This resource cannot be set to a negative amount.", resource, "set");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resource_object.value = amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ResourceException("This resource does not exist.", resource, "set");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var /*Class*/ Resource = this.Resource = function()
|
|
||||||
{
|
|
||||||
this.name = "Unnamed resource";
|
|
||||||
this.negative_allowed = false;
|
|
||||||
this.minimum = null;
|
|
||||||
this.maximum = null;
|
|
||||||
this.value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
var /*Static Class*/ Point = RadiumEngine.Point = function(x, y)
|
|
||||||
{
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
|
|
||||||
this.Add = function()
|
|
||||||
{
|
|
||||||
var new_point = new RadiumEngine.Point(this.x, this.y);
|
|
||||||
|
|
||||||
for (i in arguments)
|
|
||||||
{
|
|
||||||
new_point.x += arguments[i].x;
|
|
||||||
new_point.y += arguments[i].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_point;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Subtract = function()
|
|
||||||
{
|
|
||||||
var new_point = new RadiumEngine.Point(this.x, this.y);
|
|
||||||
|
|
||||||
for (i in arguments)
|
|
||||||
{
|
|
||||||
new_point.x -= arguments[i].x;
|
|
||||||
new_point.y -= arguments[i].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_point;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var /*Static*/ point_distance = RadiumEngine.point_distance = function(x1, y1, x2, y2)
|
|
||||||
{
|
|
||||||
var xL = x1 - x2;
|
|
||||||
var yL = y1 - y2;
|
|
||||||
return Math.sqrt((xL * xL) + (yL * yL));
|
|
||||||
}
|
|
||||||
|
|
||||||
RadiumEngine.dot_product = function(a, b)
|
|
||||||
{
|
|
||||||
var n = 0;
|
|
||||||
var lim = Math.min(a.length, b.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < lim; i++)
|
|
||||||
{
|
|
||||||
n += a[i] * b[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,168 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #F5F5F5;
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin-right: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2, h3, h4, h5, h6, h7
|
||||||
|
{
|
||||||
|
margin-top: 16px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.children { padding-left: 40px; }
|
||||||
|
|
||||||
|
.definition
|
||||||
|
{
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example
|
||||||
|
{
|
||||||
|
padding: 5px 6px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 15px;
|
||||||
|
background-color: #E6E6E6;
|
||||||
|
margin-top: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example > .children
|
||||||
|
{
|
||||||
|
padding-top: 11px;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example > .children > h7
|
||||||
|
{
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h7
|
||||||
|
{
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre
|
||||||
|
{
|
||||||
|
margin-top: 0px;
|
||||||
|
padding: 6px 7px;
|
||||||
|
background-color: #D9D9D9;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl
|
||||||
|
{
|
||||||
|
margin: 5px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dt
|
||||||
|
{
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd
|
||||||
|
{
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd > .children
|
||||||
|
{
|
||||||
|
font-size: 95%;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd > .children > dl > dd
|
||||||
|
{
|
||||||
|
margin-left: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.exclamation
|
||||||
|
{
|
||||||
|
padding: 7px 8px;
|
||||||
|
margin: 11px 0px;
|
||||||
|
background-color: #FFE9AA;
|
||||||
|
border: 1px solid yellow;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text
|
||||||
|
{
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc
|
||||||
|
{
|
||||||
|
border: 1px solid gray;
|
||||||
|
background-color: #E6E6E6;
|
||||||
|
padding: 8px 9px;
|
||||||
|
font-size: 15px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc h2
|
||||||
|
{
|
||||||
|
margin: 0px 0px 3px 0px;
|
||||||
|
font-size: 19px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc ul
|
||||||
|
{
|
||||||
|
margin-top: 0px;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
padding-left: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc li
|
||||||
|
{
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc .alternatives
|
||||||
|
{
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a
|
||||||
|
{
|
||||||
|
color: #292722;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a:hover
|
||||||
|
{
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed
|
||||||
|
{
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: white;
|
||||||
|
padding: 1px 4px;
|
||||||
|
border: 1px solid silver;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="children"><h1>Engine.Draw</h1><div class="text">The Draw library provides functions to draw shapes, text, and sprites on a scene.</div><div class="toc"><h2>Table of contents</h2><ul><li><a href="#Engine_Draw_Linex1y1x2y2options">Engine.Draw.Line(x1, y1, x2, y2, options)</a> Draws a line. </li><li><a href="#Engine_Draw_Rectanglex1y1x2y2options">Engine.Draw.Rectangle(x1, y1, x2, y2, options)</a> Draws a rectangle. </li></ul></div><div class="definition"><a name="Engine_Draw_Linex1y1x2y2options">Engine.Draw.Line(<em>x1</em>, <em>y1</em>, <em>x2</em>, <em>y2</em>, <em>options</em>) <div class="children"><div class="text">Draws a line.</div><dl><dt>x1</dt><dd>The X coordinate of the starting position.<div class="children"></div></dd></dl><dl><dt>y1</dt><dd>The Y coordinate of the starting position.<div class="children"></div></dd></dl><dl><dt>x2</dt><dd>The X coordinate of the ending position.<div class="children"></div></dd></dl><dl><dt>y2</dt><dd>The Y coordinate of the ending position.<div class="children"></div></dd></dl><dl><dt>options</dt><dd><em>Optional.</em> Options for drawing the line.<div class="children"><dl><dt>width</dt><dd>Width of the line in pixels.<div class="children"></div></dd></dl><dl><dt>color</dt><dd>The line <a href="../drawing.html">color</a>.<div class="children"></div></dd></dl><dl><dt>cap</dt><dd>The type of <a href="../drawing.html">line cap</a>.<div class="children"></div></dd></dl><dl><dt>alpha</dt><dd>The alpha value of the line.<div class="children"></div></dd></dl></div></dd></dl><div class="example">Example: Draw a blue line <div class="children"><h7>Code:</h7><pre class="code">Engine.Draw.Line(10, 10, 120, 120, {
|
||||||
|
color: "blue"
|
||||||
|
});</pre></div></div></div></a></div><div class="definition"><a name="Engine_Draw_Rectanglex1y1x2y2options">Engine.Draw.Rectangle(<em>x1</em>, <em>y1</em>, <em>x2</em>, <em>y2</em>, <em>options</em>) <div class="children"><div class="text">Draws a rectangle.</div><dl><dt>x1</dt><dd>The X coordinate of the top left corner.<div class="children"></div></dd></dl><dl><dt>y1</dt><dd>The Y coordinate of the top left corner.<div class="children"></div></dd></dl><dl><dt>x2</dt><dd>The X coordinate of the right bottom corner.<div class="children"></div></dd></dl><dl><dt>y2</dt><dd>The Y coordinate of the right bottom corner.<div class="children"></div></dd></dl><dl><dt>options</dt><dd><em>Optional.</em> Options for drawing the rectangle.<div class="children"><dl><dt>width</dt><dd>Width of the outline in pixels.<div class="children"></div></dd></dl><dl><dt>linecolor</dt><dd>The <a href="../drawing.html">color</a> of the outline.<div class="children"></div></dd></dl><dl><dt>cap</dt><dd>The type <a href="../drawing.html">line cap</a> for the outline.<div class="children"></div></dd></dl><dl><dt>rx</dt><dd>The horizontal radius of the corners of the rectangle.<div class="children"></div></dd></dl><dl><dt>ry</dt><dd>The vertical radius of the corners of the rectangle.<div class="children"></div></dd></dl><dl><dt>radius</dt><dd>A short-hand option that sets both <span class="fixed">rx</span> and <span class="fixed">ry</span>.<div class="children"></div></dd></dl><dl><dt>color</dt><dd>The fill color of the rectangle.<div class="children"></div></dd></dl><dl><dt>alpha</dt><dd>The alpha value of the rectangle.<div class="children"></div></dd></dl></div></dd></dl><div class="example">Example: Draw a blue rectangle with a yellow outline, rounded borders and at 70% opacity <div class="children"><h7>Code:</h7><pre class="code">Engine.Draw.Rectangle(20, 30, 150, 180, {
|
||||||
|
linecolor: "yellow",
|
||||||
|
color: "blue",
|
||||||
|
radius: 8,
|
||||||
|
alpha: 0.7
|
||||||
|
});</pre></div></div></div></a></div></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,94 @@
|
|||||||
|
# Engine.Draw
|
||||||
|
|
||||||
|
The Draw library provides functions to draw shapes, text, and sprites on a scene.
|
||||||
|
|
||||||
|
{TOC}
|
||||||
|
|
||||||
|
^ Engine.Draw.Line(**x1**, **y1**, **x2**, **y2**, **options**)
|
||||||
|
|
||||||
|
Draws a line.
|
||||||
|
|
||||||
|
x1::
|
||||||
|
The X coordinate of the starting position.
|
||||||
|
|
||||||
|
y1::
|
||||||
|
The Y coordinate of the starting position.
|
||||||
|
|
||||||
|
x2::
|
||||||
|
The X coordinate of the ending position.
|
||||||
|
|
||||||
|
y2::
|
||||||
|
The Y coordinate of the ending position.
|
||||||
|
|
||||||
|
options::
|
||||||
|
**Optional.** Options for drawing the line.
|
||||||
|
|
||||||
|
width::
|
||||||
|
Width of the line in pixels.
|
||||||
|
|
||||||
|
color::
|
||||||
|
The line {>../drawing}(color).
|
||||||
|
|
||||||
|
cap::
|
||||||
|
The type of {>../drawing}(line cap).
|
||||||
|
|
||||||
|
alpha::
|
||||||
|
The alpha value of the line.
|
||||||
|
|
||||||
|
@ Draw a blue line
|
||||||
|
|
||||||
|
$ Engine.Draw.Line(10, 10, 120, 120, {
|
||||||
|
color: "blue"
|
||||||
|
});
|
||||||
|
|
||||||
|
^ Engine.Draw.Rectangle(**x1**, **y1**, **x2**, **y2**, **options**)
|
||||||
|
|
||||||
|
Draws a rectangle.
|
||||||
|
|
||||||
|
x1::
|
||||||
|
The X coordinate of the top left corner.
|
||||||
|
|
||||||
|
y1::
|
||||||
|
The Y coordinate of the top left corner.
|
||||||
|
|
||||||
|
x2::
|
||||||
|
The X coordinate of the right bottom corner.
|
||||||
|
|
||||||
|
y2::
|
||||||
|
The Y coordinate of the right bottom corner.
|
||||||
|
|
||||||
|
options::
|
||||||
|
**Optional.** Options for drawing the rectangle.
|
||||||
|
|
||||||
|
width::
|
||||||
|
Width of the outline in pixels.
|
||||||
|
|
||||||
|
linecolor::
|
||||||
|
The {>../drawing}(color) of the outline.
|
||||||
|
|
||||||
|
cap::
|
||||||
|
The type {>../drawing}(line cap) for the outline.
|
||||||
|
|
||||||
|
rx::
|
||||||
|
The horizontal radius of the corners of the rectangle.
|
||||||
|
|
||||||
|
ry::
|
||||||
|
The vertical radius of the corners of the rectangle.
|
||||||
|
|
||||||
|
radius::
|
||||||
|
A short-hand option that sets both `rx` and `ry`.
|
||||||
|
|
||||||
|
color::
|
||||||
|
The fill color of the rectangle.
|
||||||
|
|
||||||
|
alpha::
|
||||||
|
The alpha value of the rectangle.
|
||||||
|
|
||||||
|
@ Draw a blue rectangle with a yellow outline, rounded borders and at 70% opacity
|
||||||
|
|
||||||
|
$ Engine.Draw.Rectangle(20, 30, 150, 180, {
|
||||||
|
linecolor: "yellow",
|
||||||
|
color: "blue",
|
||||||
|
radius: 8,
|
||||||
|
alpha: 0.7
|
||||||
|
});
|
@ -0,0 +1,162 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #F5F5F5;
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin-right: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2, h3, h4, h5, h6, h7
|
||||||
|
{
|
||||||
|
margin-top: 16px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.children { padding-left: 40px; }
|
||||||
|
|
||||||
|
.definition
|
||||||
|
{
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example
|
||||||
|
{
|
||||||
|
padding: 5px 6px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 15px;
|
||||||
|
background-color: #E6E6E6;
|
||||||
|
margin-top: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example > .children
|
||||||
|
{
|
||||||
|
padding-top: 11px;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example > .children > h7
|
||||||
|
{
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h7
|
||||||
|
{
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre
|
||||||
|
{
|
||||||
|
margin-top: 0px;
|
||||||
|
padding: 6px 7px;
|
||||||
|
background-color: #D9D9D9;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl
|
||||||
|
{
|
||||||
|
margin: 5px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dt
|
||||||
|
{
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd
|
||||||
|
{
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd > .children
|
||||||
|
{
|
||||||
|
font-size: 95%;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd > .children > dl > dd
|
||||||
|
{
|
||||||
|
margin-left: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.exclamation
|
||||||
|
{
|
||||||
|
padding: 7px 8px;
|
||||||
|
margin: 11px 0px;
|
||||||
|
background-color: #FFE9AA;
|
||||||
|
border: 1px solid yellow;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text
|
||||||
|
{
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc
|
||||||
|
{
|
||||||
|
border: 1px solid gray;
|
||||||
|
background-color: #E6E6E6;
|
||||||
|
padding: 8px 9px;
|
||||||
|
font-size: 15px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc h2
|
||||||
|
{
|
||||||
|
margin: 0px 0px 3px 0px;
|
||||||
|
font-size: 19px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc ul
|
||||||
|
{
|
||||||
|
margin-top: 0px;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
padding-left: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc li
|
||||||
|
{
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc .alternatives
|
||||||
|
{
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a
|
||||||
|
{
|
||||||
|
color: #292722;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a:hover
|
||||||
|
{
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed
|
||||||
|
{
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: white;
|
||||||
|
padding: 1px 4px;
|
||||||
|
border: 1px solid silver;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="children"><h1>Engine.Math</h1><div class="text">The Math library provides several functions to do mathematical operations or calculations. Most of these functions are simply aliases of the functions built into JavaScript.</div><div class="toc"><h2>Table of contents</h2><ul><li><a href="#Engine_Math_Absolutex">Engine.Math.Absolute(x)</a> Returns the absolute value of <span class="fixed">x</span>. <span class="alternatives">(also: Engine.Math.Abs(x))</span></li><li><a href="#Engine_Random_Sumitemitemitem">Engine.Random.Sum(item [, item [, item ...]])</a> Returns the sum of all supplied numbers. <span class="alternatives">(also: Engine.Random.Sum(itemarray))</span></li><li><a href="#Engine_Math_Roundx">Engine.Math.Round(x)</a> Rounds <span class="fixed">x</span> to the nearest integer. </li><li><a href="#Engine_Math_Ceilingx">Engine.Math.Ceiling(x)</a> Rounds up <span class="fixed">x</span>. <span class="alternatives">(also: Engine.Math.Ceil(x))</span></li><li><a href="#Engine_Math_Floorx">Engine.Math.Floor(x)</a> Rounds down <span class="fixed">x</span>. </li><li><a href="#Engine_Math_Tangentx">Engine.Math.Tangent(x)</a> Returns the tangent of angle <span class="fixed">x</span>. <span class="alternatives">(also: Engine.Math.Tan(x))</span></li><li><a href="#Engine_Math_Cosinex">Engine.Math.Cosine(x)</a> Returns the cosine of <span class="fixed">x</span>. <span class="alternatives">(also: Engine.Math.Cos(x))</span></li><li><a href="#Engine_Math_Sinex">Engine.Math.Sine(x)</a> Returns the sine of <span class="fixed">x</span>. <span class="alternatives">(also: Engine.Math.Sin(x))</span></li></ul></div><div class="definition"><a name="Engine_Math_Absolutex">Engine.Math.Absolute(<em>x</em>)<br>Engine.Math.Abs(<em>x</em>) <div class="children"><div class="text">Returns the absolute value of <span class="fixed">x</span>.</div><div class="text"><em>This is an alias of the standard Math.abs function in JavaScript.</em></div><dl><dt>x</dt><dd>The number.<div class="children"></div></dd></dl><div class="example">Example: Get the absolute value of a positive number <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Absolute(16);</pre><h7>Output:</h7><pre class="output">16</pre></div></div><div class="example">Example: Get the absolute value of a negative number <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Absolute(-23);</pre><h7>Output:</h7><pre class="output">23</pre></div></div></div></a></div><div class="definition"><a name="Engine_Random_Sumitemitemitem">Engine.Random.Sum(<em>item</em> [, <em>item</em> [, <em>item</em> ...]])<br>Engine.Random.Sum(<em>itemarray</em>) <div class="children"><div class="text">Returns the sum of all supplied numbers.</div><dl><dt>item</dt><dd>An individual number. itemarray:: An array of numbers.<div class="children"></div></dd></dl><div class="example">Example: Sum several numbers using individual arguments <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Sum(42, 6, 17, 2, 7);</pre><h7>Output:</h7><pre class="output">74</pre></div></div><div class="example">Example: Sum several numbers using an array <div class="children"><h7>Code:</h7><pre class="code">var numbers = [42, 6, 17, 2, 7];
|
||||||
|
Engine.Math.Sum(numbers);</pre><h7>Output:</h7><pre class="output">74</pre></div></div></div></a></div><div class="definition"><a name="Engine_Math_Roundx">Engine.Math.Round(<em>x</em>) <div class="children"><div class="text">Rounds <span class="fixed">x</span> to the nearest integer.</div><div class="text"><em>This is an alias of the standard Math.round function in JavaScript.</em></div><dl><dt>x</dt><dd>The value to round.<div class="children"></div></dd></dl><div class="example">Example: Rounding a number in the upper half <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Ceiling(82.62);</pre><h7>Output:</h7><pre class="output">83</pre></div></div><div class="example">Example: Rounding a number in the lower half <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Ceiling(82.13);</pre><h7>Output:</h7><pre class="output">82</pre></div></div></div></a></div><div class="definition"><a name="Engine_Math_Ceilingx">Engine.Math.Ceiling(<em>x</em>)<br>Engine.Math.Ceil(<em>x</em>) <div class="children"><div class="text">Rounds up <span class="fixed">x</span>.</div><div class="text"><em>This is an alias of the standard Math.ceil function in JavaScript.</em></div><dl><dt>x</dt><dd>The value to round up.<div class="children"></div></dd></dl><div class="example">Example: Rounding up a number <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Ceiling(614.2162);</pre><h7>Output:</h7><pre class="output">615</pre></div></div></div></a></div><div class="definition"><a name="Engine_Math_Floorx">Engine.Math.Floor(<em>x</em>) <div class="children"><div class="text">Rounds down <span class="fixed">x</span>.</div><div class="text"><em>This is an alias of the standard Math.floor function in JavaScript.</em></div><dl><dt>x</dt><dd>The value to round down.<div class="children"></div></dd></dl><div class="example">Example: Rounding down a number <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Floor(7.612);</pre><h7>Output:</h7><pre class="output">7</pre></div></div></div></a></div><div class="definition"><a name="Engine_Math_Tangentx">Engine.Math.Tangent(<em>x</em>)<br>Engine.Math.Tan(<em>x</em>) <div class="children"><div class="text">Returns the tangent of angle <span class="fixed">x</span>.</div><div class="text"><em>This is an alias of the standard Math.tan function in JavaScript.</em></div><dl><dt>x</dt><dd>The value.<div class="children"></div></dd></dl><div class="example">Example: Calculating the tangent <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Tangent(84.15);</pre><h7>Output:</h7><pre class="output">-0.7971515163204654</pre></div></div></div></a></div><div class="definition"><a name="Engine_Math_Cosinex">Engine.Math.Cosine(<em>x</em>)<br>Engine.Math.Cos(<em>x</em>) <div class="children"><div class="text">Returns the cosine of <span class="fixed">x</span>.</div><div class="text"><em>This is an alias of the standard Math.cos function in JavaScript.</em></div><dl><dt>x</dt><dd>The value (in radians).<div class="children"></div></dd></dl><div class="example">Example: Calculating the cosine <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Cosine(162.54);</pre><h7>Output:</h7><pre class="output">0.6801581420388815</pre></div></div></div></a></div><div class="definition"><a name="Engine_Math_Sinex">Engine.Math.Sine(<em>x</em>)<br>Engine.Math.Sin(<em>x</em>) <div class="children"><div class="text">Returns the sine of <span class="fixed">x</span>.</div><div class="text"><em>This is an alias of the standard Math.sin function in JavaScript.</em></div><dl><dt>x</dt><dd>The value (in radians).<div class="children"></div></dd></dl><div class="example">Example: Calculating the sine <div class="children"><h7>Code:</h7><pre class="code">Engine.Math.Sine(62.4);</pre><h7>Output:</h7><pre class="output">-0.41855446451842543</pre></div></div></div></a></div></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,150 @@
|
|||||||
|
# Engine.Math
|
||||||
|
|
||||||
|
The Math library provides several functions to do mathematical operations or calculations. Most of these functions are simply aliases of the functions built into JavaScript.
|
||||||
|
|
||||||
|
{TOC}
|
||||||
|
|
||||||
|
^ Engine.Math.Absolute(**x**)
|
||||||
|
Engine.Math.Abs(**x**)
|
||||||
|
|
||||||
|
Returns the absolute value of `x`.
|
||||||
|
|
||||||
|
**This is an alias of the standard Math.abs function in JavaScript.**
|
||||||
|
|
||||||
|
x::
|
||||||
|
The number.
|
||||||
|
|
||||||
|
@ Get the absolute value of a positive number
|
||||||
|
|
||||||
|
$ Engine.Math.Absolute(16);
|
||||||
|
|
||||||
|
> 16
|
||||||
|
|
||||||
|
@ Get the absolute value of a negative number
|
||||||
|
|
||||||
|
$ Engine.Math.Absolute(-23);
|
||||||
|
|
||||||
|
> 23
|
||||||
|
|
||||||
|
^ Engine.Random.Sum(**item** [, **item** [, **item** ...]])
|
||||||
|
Engine.Random.Sum(**itemarray**)
|
||||||
|
|
||||||
|
Returns the sum of all supplied numbers.
|
||||||
|
|
||||||
|
item::
|
||||||
|
An individual number.
|
||||||
|
itemarray::
|
||||||
|
An array of numbers.
|
||||||
|
|
||||||
|
@ Sum several numbers using individual arguments
|
||||||
|
|
||||||
|
$ Engine.Math.Sum(42, 6, 17, 2, 7);
|
||||||
|
|
||||||
|
> 74
|
||||||
|
|
||||||
|
@ Sum several numbers using an array
|
||||||
|
|
||||||
|
$ var numbers = [42, 6, 17, 2, 7];
|
||||||
|
Engine.Math.Sum(numbers);
|
||||||
|
|
||||||
|
> 74
|
||||||
|
|
||||||
|
^ Engine.Math.Round(**x**)
|
||||||
|
|
||||||
|
Rounds `x` to the nearest integer.
|
||||||
|
|
||||||
|
**This is an alias of the standard Math.round function in JavaScript.**
|
||||||
|
|
||||||
|
x::
|
||||||
|
The value to round.
|
||||||
|
|
||||||
|
@ Rounding a number in the upper half
|
||||||
|
|
||||||
|
$ Engine.Math.Ceiling(82.62);
|
||||||
|
|
||||||
|
> 83
|
||||||
|
|
||||||
|
@ Rounding a number in the lower half
|
||||||
|
|
||||||
|
$ Engine.Math.Ceiling(82.13);
|
||||||
|
|
||||||
|
> 82
|
||||||
|
|
||||||
|
^ Engine.Math.Ceiling(**x**)
|
||||||
|
Engine.Math.Ceil(**x**)
|
||||||
|
|
||||||
|
Rounds up `x`.
|
||||||
|
|
||||||
|
**This is an alias of the standard Math.ceil function in JavaScript.**
|
||||||
|
|
||||||
|
x::
|
||||||
|
The value to round up.
|
||||||
|
|
||||||
|
@ Rounding up a number
|
||||||
|
|
||||||
|
$ Engine.Math.Ceiling(614.2162);
|
||||||
|
|
||||||
|
> 615
|
||||||
|
|
||||||
|
^ Engine.Math.Floor(**x**)
|
||||||
|
|
||||||
|
Rounds down `x`.
|
||||||
|
|
||||||
|
**This is an alias of the standard Math.floor function in JavaScript.**
|
||||||
|
|
||||||
|
x::
|
||||||
|
The value to round down.
|
||||||
|
|
||||||
|
@ Rounding down a number
|
||||||
|
|
||||||
|
$ Engine.Math.Floor(7.612);
|
||||||
|
|
||||||
|
> 7
|
||||||
|
|
||||||
|
^ Engine.Math.Tangent(**x**)
|
||||||
|
Engine.Math.Tan(**x**)
|
||||||
|
|
||||||
|
Returns the tangent of angle `x`.
|
||||||
|
|
||||||
|
**This is an alias of the standard Math.tan function in JavaScript.**
|
||||||
|
|
||||||
|
x::
|
||||||
|
The value.
|
||||||
|
|
||||||
|
@ Calculating the tangent
|
||||||
|
|
||||||
|
$ Engine.Math.Tangent(84.15);
|
||||||
|
|
||||||
|
> -0.7971515163204654
|
||||||
|
|
||||||
|
^ Engine.Math.Cosine(**x**)
|
||||||
|
Engine.Math.Cos(**x**)
|
||||||
|
|
||||||
|
Returns the cosine of `x`.
|
||||||
|
|
||||||
|
**This is an alias of the standard Math.cos function in JavaScript.**
|
||||||
|
|
||||||
|
x::
|
||||||
|
The value (in radians).
|
||||||
|
|
||||||
|
@ Calculating the cosine
|
||||||
|
|
||||||
|
$ Engine.Math.Cosine(162.54);
|
||||||
|
|
||||||
|
> 0.6801581420388815
|
||||||
|
|
||||||
|
^ Engine.Math.Sine(**x**)
|
||||||
|
Engine.Math.Sin(**x**)
|
||||||
|
|
||||||
|
Returns the sine of `x`.
|
||||||
|
|
||||||
|
**This is an alias of the standard Math.sin function in JavaScript.**
|
||||||
|
|
||||||
|
x::
|
||||||
|
The value (in radians).
|
||||||
|
|
||||||
|
@ Calculating the sine
|
||||||
|
|
||||||
|
$ Engine.Math.Sine(62.4);
|
||||||
|
|
||||||
|
> -0.41855446451842543
|
@ -0,0 +1,163 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #F5F5F5;
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin-right: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2, h3, h4, h5, h6, h7
|
||||||
|
{
|
||||||
|
margin-top: 16px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.children { padding-left: 40px; }
|
||||||
|
|
||||||
|
.definition
|
||||||
|
{
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example
|
||||||
|
{
|
||||||
|
padding: 5px 6px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 15px;
|
||||||
|
background-color: #E6E6E6;
|
||||||
|
margin-top: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example > .children
|
||||||
|
{
|
||||||
|
padding-top: 11px;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example > .children > h7
|
||||||
|
{
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h7
|
||||||
|
{
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre
|
||||||
|
{
|
||||||
|
margin-top: 0px;
|
||||||
|
padding: 6px 7px;
|
||||||
|
background-color: #D9D9D9;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl
|
||||||
|
{
|
||||||
|
margin: 5px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dt
|
||||||
|
{
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd
|
||||||
|
{
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd > .children
|
||||||
|
{
|
||||||
|
font-size: 95%;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd > .children > dl > dd
|
||||||
|
{
|
||||||
|
margin-left: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.exclamation
|
||||||
|
{
|
||||||
|
padding: 7px 8px;
|
||||||
|
margin: 11px 0px;
|
||||||
|
background-color: #FFE9AA;
|
||||||
|
border: 1px solid yellow;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text
|
||||||
|
{
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc
|
||||||
|
{
|
||||||
|
border: 1px solid gray;
|
||||||
|
background-color: #E6E6E6;
|
||||||
|
padding: 8px 9px;
|
||||||
|
font-size: 15px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc h2
|
||||||
|
{
|
||||||
|
margin: 0px 0px 3px 0px;
|
||||||
|
font-size: 19px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc ul
|
||||||
|
{
|
||||||
|
margin-top: 0px;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
padding-left: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc li
|
||||||
|
{
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc .alternatives
|
||||||
|
{
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a
|
||||||
|
{
|
||||||
|
color: #292722;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a:hover
|
||||||
|
{
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed
|
||||||
|
{
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: white;
|
||||||
|
padding: 1px 4px;
|
||||||
|
border: 1px solid silver;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="children"><h1>Engine.Random</h1><div class="text">The Random library provides several functions to pick random numbers or items.</div><div class="toc"><h2>Table of contents</h2><ul><li><a href="#Engine_Random_Numberminmaxprecision">Engine.Random.Number(min, max, precision)</a> Selects a random number between <span class="fixed">min</span> and <span class="fixed">max</span>, excluding <span class="fixed">max</span> itself. </li><li><a href="#Engine_Random_Chooseitemitemitem">Engine.Random.Choose(item [, item [, item ...]])</a> Selects a random item from the supplied items. <span class="alternatives">(also: Engine.Random.Choose(itemarray))</span></li><li><a href="#Engine_Random_Pickamountitemitemitem">Engine.Random.Pick(amount, item [, item [, item ...]])</a> Selects <span class="fixed">amount</span> unique random items from the supplied items. Each item can only... <span class="alternatives">(also: Engine.Random.Pick(amount, itemarray))</span></li><li><a href="#Engine_Random_Stringlengthalphabet">Engine.Random.String(length [, alphabet])</a> Generates a random string with the specified <span class="fixed">length</span>, and optionally a custom... </li></ul></div><div class="definition"><a name="Engine_Random_Numberminmaxprecision">Engine.Random.Number(<em>min</em>, <em>max</em>, <em>precision</em>) <div class="children"><div class="text">Selects a random number between <span class="fixed">min</span> and <span class="fixed">max</span>, excluding <span class="fixed">max</span> itself.</div><dl><dt>min</dt><dd><em>Optional:</em> The minimum number. <em>Defaults to 0.</em><div class="children"></div></dd></dl><dl><dt>max</dt><dd><em>Optional:</em> The maximum number (itself excluded). <em>Defaults to 1.</em><div class="children"></div></dd></dl><dl><dt>precision</dt><dd><em>Optional:</em> The precision; this is what the result will be rounded to. <em>Defaults to 0.00000001.</em><div class="children"></div></dd></dl><div class="example">Example: Get a whole number from 0 to 9 <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Number(0, 10, 1);</pre><h7>Output:</h7><pre class="output">7</pre></div></div><div class="example">Example: Get a one-tenth-precision number from 0 to 9.9 <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Number(0, 10, 0.1);</pre><h7>Output:</h7><pre class="output">3.7</pre></div></div><div class="example">Example: Get a one-fifth-precision number from 5 to 9.8: <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Number(5, 10, 0.2);</pre><h7>Output:</h7><pre class="output">6.4</pre></div></div></div></a></div><div class="definition"><a name="Engine_Random_Chooseitemitemitem">Engine.Random.Choose(<em>item</em> [, <em>item</em> [, <em>item</em> ...]])<br>Engine.Random.Choose(<em>itemarray</em>) <div class="children"><div class="text">Selects a random item from the supplied items.</div><dl><dt>item</dt><dd>An item to choose from.<div class="children"></div></dd></dl><dl><dt>itemarray</dt><dd>An array of items to choose from.<div class="children"></div></dd></dl><div class="example">Example: Select a random color from a list using multiple arguments <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Choose("blue", "green", "red", "yellow");</pre><h7>Output:</h7><pre class="output">"green"</pre></div></div><div class="example">Example: Select a random day from a list using an array <div class="children"><h7>Code:</h7><pre class="code">var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
||||||
|
Engine.Random.Choose(days);</pre><h7>Output:</h7><pre class="output">"Thursday"</pre></div></div></div></a></div><div class="definition"><a name="Engine_Random_Pickamountitemitemitem">Engine.Random.Pick(<em>amount</em>, <em>item</em> [, <em>item</em> [, <em>item</em> ...]])<br>Engine.Random.Pick(<em>amount</em>, <em>itemarray</em>) <div class="children"><div class="text">Selects <span class="fixed">amount</span> unique random items from the supplied items. Each item can only appear in the result once.</div><div class="exclamation"><strong>Important:</strong> The <span class="fixed">amount</span> argument must always be equal to or higher than the amount of supplied items! <div class="children"></div></div><dl><dt>amount</dt><dd>The amount of items to select.<div class="children"></div></dd></dl><dl><dt>item</dt><dd>An item to choose from.<div class="children"></div></dd></dl><dl><dt>itemarray</dt><dd>An array of items to choose from.<div class="children"></div></dd></dl><div class="example">Example: Select three random colors from a list using multiple arguments <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Pick(3, "red", "green", "blue", "yellow", "purple", "brown", "black", "white", "orange");</pre><h7>Output:</h7><pre class="output">["blue", "orange", "red"]</pre></div></div><div class="example">Example: Select two vegetables from a list using an array <div class="children"><h7>Code:</h7><pre class="code">var vegetables = ["celery", "potato", "tomato", "coleslaw", "onion"];
|
||||||
|
Engine.Random.Pick(2, vegetables);</pre><h7>Output:</h7><pre class="output">["tomato", "onion"]</pre></div></div></div></a></div><div class="definition"><a name="Engine_Random_Stringlengthalphabet">Engine.Random.String(<em>length</em> [, <em>alphabet</em>]) <div class="children"><div class="text">Generates a random string with the specified <span class="fixed">length</span>, and optionally a custom alphabet.</div><dl><dt>length</dt><dd>The length of the string that has to be generated.<div class="children"></div></dd></dl><dl><dt>alphabet</dt><dd><em>Optional:</em> The alphabet (set of characters) to choose from. <em>Defaults to a-z, A-Z, 0-9.</em><div class="children"></div></dd></dl><div class="example">Example: Generate a random string with the default alphabet <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.String(14);</pre><h7>Output:</h7><pre class="output">"NCm2Y7lEleCTa5"</pre></div></div><div class="example">Example: Generate a random string with a custom alphabet <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.String(10, "abcde");</pre><h7>Output:</h7><pre class="output">"baeddebaca"</pre></div></div></div></a></div></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,123 @@
|
|||||||
|
# Engine.Random
|
||||||
|
|
||||||
|
The Random library provides several functions to pick random numbers or items.
|
||||||
|
|
||||||
|
{TOC}
|
||||||
|
|
||||||
|
^ Engine.Random.Number(**min**, **max**, **precision**)
|
||||||
|
|
||||||
|
Selects a random number between `min` and `max`, excluding `max` itself.
|
||||||
|
|
||||||
|
|
||||||
|
min::
|
||||||
|
**Optional:** The minimum number. **Defaults to 0.**
|
||||||
|
|
||||||
|
max::
|
||||||
|
**Optional:** The maximum number (itself excluded). **Defaults to 1.**
|
||||||
|
|
||||||
|
precision::
|
||||||
|
**Optional:** The precision; this is what the result will be rounded to. **Defaults to 0.00000001.**
|
||||||
|
|
||||||
|
|
||||||
|
@ Get a whole number from 0 to 9
|
||||||
|
|
||||||
|
$ Engine.Random.Number(0, 10, 1);
|
||||||
|
|
||||||
|
> 7
|
||||||
|
|
||||||
|
|
||||||
|
@ Get a one-tenth-precision number from 0 to 9.9
|
||||||
|
|
||||||
|
$ Engine.Random.Number(0, 10, 0.1);
|
||||||
|
|
||||||
|
> 3.7
|
||||||
|
|
||||||
|
|
||||||
|
@ Get a one-fifth-precision number from 5 to 9.8:
|
||||||
|
|
||||||
|
$ Engine.Random.Number(5, 10, 0.2);
|
||||||
|
|
||||||
|
> 6.4
|
||||||
|
|
||||||
|
|
||||||
|
^ Engine.Random.Choose(**item** [, **item** [, **item** ...]])
|
||||||
|
Engine.Random.Choose(**itemarray**)
|
||||||
|
|
||||||
|
Selects a random item from the supplied items.
|
||||||
|
|
||||||
|
|
||||||
|
item::
|
||||||
|
An item to choose from.
|
||||||
|
|
||||||
|
itemarray::
|
||||||
|
An array of items to choose from.
|
||||||
|
|
||||||
|
|
||||||
|
@ Select a random color from a list using multiple arguments
|
||||||
|
|
||||||
|
$ Engine.Random.Choose("blue", "green", "red", "yellow");
|
||||||
|
|
||||||
|
> "green"
|
||||||
|
|
||||||
|
|
||||||
|
@ Select a random day from a list using an array
|
||||||
|
|
||||||
|
$ var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
||||||
|
Engine.Random.Choose(days);
|
||||||
|
|
||||||
|
> "Thursday"
|
||||||
|
|
||||||
|
|
||||||
|
^ Engine.Random.Pick(**amount**, **item** [, **item** [, **item** ...]])
|
||||||
|
Engine.Random.Pick(**amount**, **itemarray**)
|
||||||
|
|
||||||
|
Selects `amount` unique random items from the supplied items. Each item can only appear in the result once.
|
||||||
|
|
||||||
|
! The `amount` argument must always be equal to or higher than the amount of supplied items!
|
||||||
|
|
||||||
|
|
||||||
|
amount::
|
||||||
|
The amount of items to select.
|
||||||
|
|
||||||
|
item::
|
||||||
|
An item to choose from.
|
||||||
|
|
||||||
|
itemarray::
|
||||||
|
An array of items to choose from.
|
||||||
|
|
||||||
|
|
||||||
|
@ Select three random colors from a list using multiple arguments
|
||||||
|
|
||||||
|
$ Engine.Random.Pick(3, "red", "green", "blue", "yellow", "purple", "brown", "black", "white", "orange");
|
||||||
|
|
||||||
|
> ["blue", "orange", "red"]
|
||||||
|
|
||||||
|
|
||||||
|
@ Select two vegetables from a list using an array
|
||||||
|
|
||||||
|
$ var vegetables = ["celery", "potato", "tomato", "coleslaw", "onion"];
|
||||||
|
Engine.Random.Pick(2, vegetables);
|
||||||
|
|
||||||
|
> ["tomato", "onion"]
|
||||||
|
|
||||||
|
^ Engine.Random.String(**length** [, **alphabet**])
|
||||||
|
|
||||||
|
Generates a random string with the specified `length`, and optionally a custom alphabet.
|
||||||
|
|
||||||
|
length::
|
||||||
|
The length of the string that has to be generated.
|
||||||
|
|
||||||
|
alphabet::
|
||||||
|
**Optional:** The alphabet (set of characters) to choose from. **Defaults to a-z, A-Z, 0-9.**
|
||||||
|
|
||||||
|
@ Generate a random string with the default alphabet
|
||||||
|
|
||||||
|
$ Engine.Random.String(14);
|
||||||
|
|
||||||
|
> "NCm2Y7lEleCTa5"
|
||||||
|
|
||||||
|
@ Generate a random string with a custom alphabet
|
||||||
|
|
||||||
|
$ Engine.Random.String(10, "abcde");
|
||||||
|
|
||||||
|
> "baeddebaca"
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,78 @@
|
|||||||
|
/** @license
|
||||||
|
*
|
||||||
|
* SoundManager 2: JavaScript Sound for the Web
|
||||||
|
* ----------------------------------------------
|
||||||
|
* http://schillmania.com/projects/soundmanager2/
|
||||||
|
*
|
||||||
|
* Copyright (c) 2007, Scott Schiller. All rights reserved.
|
||||||
|
* Code provided under the BSD License:
|
||||||
|
* http://schillmania.com/projects/soundmanager2/license.txt
|
||||||
|
*
|
||||||
|
* V2.97a.20130101
|
||||||
|
*/
|
||||||
|
(function(i,g){function R(R,fa){function S(b){return c.preferFlash&&A&&!c.ignoreFlash&&c.flash[b]!==g&&c.flash[b]}function m(b){return function(c){var d=this._s;return!d||!d._a?null:b.call(this,c)}}this.setupOptions={url:R||null,flashVersion:8,debugMode:!0,debugFlash:!1,useConsole:!0,consoleOnly:!0,waitForWindowLoad:!1,bgColor:"#ffffff",useHighPerformance:!1,flashPollingInterval:null,html5PollingInterval:null,flashLoadTimeout:1E3,wmode:null,allowScriptAccess:"always",useFlashBlock:!1,useHTML5Audio:!0,
|
||||||
|
html5Test:/^(probably|maybe)$/i,preferFlash:!0,noSWFCache:!1};this.defaultOptions={autoLoad:!1,autoPlay:!1,from:null,loops:1,onid3:null,onload:null,whileloading:null,onplay:null,onpause:null,onresume:null,whileplaying:null,onposition:null,onstop:null,onfailure:null,onfinish:null,multiShot:!0,multiShotEvents:!1,position:null,pan:0,stream:!0,to:null,type:null,usePolicyFile:!1,volume:100};this.flash9Options={isMovieStar:null,usePeakData:!1,useWaveformData:!1,useEQData:!1,onbufferchange:null,ondataerror:null};
|
||||||
|
this.movieStarOptions={bufferTime:3,serverURL:null,onconnect:null,duration:null};this.audioFormats={mp3:{type:['audio/mpeg; codecs="mp3"',"audio/mpeg","audio/mp3","audio/MPA","audio/mpa-robust"],required:!0},mp4:{related:["aac","m4a","m4b"],type:['audio/mp4; codecs="mp4a.40.2"',"audio/aac","audio/x-m4a","audio/MP4A-LATM","audio/mpeg4-generic"],required:!1},ogg:{type:["audio/ogg; codecs=vorbis"],required:!1},wav:{type:['audio/wav; codecs="1"',"audio/wav","audio/wave","audio/x-wav"],required:!1}};this.movieID=
|
||||||
|
"sm2-container";this.id=fa||"sm2movie";this.debugID="soundmanager-debug";this.debugURLParam=/([#?&])debug=1/i;this.versionNumber="V2.97a.20130101";this.altURL=this.movieURL=this.version=null;this.enabled=this.swfLoaded=!1;this.oMC=null;this.sounds={};this.soundIDs=[];this.didFlashBlock=this.muted=!1;this.filePattern=null;this.filePatterns={flash8:/\.mp3(\?.*)?$/i,flash9:/\.mp3(\?.*)?$/i};this.features={buffering:!1,peakData:!1,waveformData:!1,eqData:!1,movieStar:!1};this.sandbox={};this.html5={usingFlash:null};
|
||||||
|
this.flash={};this.ignoreFlash=this.html5Only=!1;var Ga,c=this,Ha=null,h=null,T,q=navigator.userAgent,ga=i.location.href.toString(),l=document,ha,Ia,ia,k,r=[],J=!1,K=!1,j=!1,s=!1,ja=!1,L,t,ka,U,la,B,C,D,Ja,ma,V,na,W,oa,E,pa,M,qa,X,F,Ka,ra,La,sa,Ma,N=null,ta=null,v,ua,G,Y,Z,H,p,O=!1,va=!1,Na,Oa,Pa,$=0,P=null,aa,Qa=[],u=null,Ra,ba,Q,y,wa,xa,Sa,n,db=Array.prototype.slice,w=!1,ya,A,za,Ta,x,ca=q.match(/(ipad|iphone|ipod)/i),Ua=q.match(/android/i),z=q.match(/msie/i),eb=q.match(/webkit/i),Aa=q.match(/safari/i)&&
|
||||||
|
!q.match(/chrome/i),Ba=q.match(/opera/i),Ca=q.match(/(mobile|pre\/|xoom)/i)||ca||Ua,Va=!ga.match(/usehtml5audio/i)&&!ga.match(/sm2\-ignorebadua/i)&&Aa&&!q.match(/silk/i)&&q.match(/OS X 10_6_([3-7])/i),Da=l.hasFocus!==g?l.hasFocus():null,da=Aa&&(l.hasFocus===g||!l.hasFocus()),Wa=!da,Xa=/(mp3|mp4|mpa|m4a|m4b)/i,Ea=l.location?l.location.protocol.match(/http/i):null,Ya=!Ea?"http://":"",Za=/^\s*audio\/(?:x-)?(?:mpeg4|aac|flv|mov|mp4||m4v|m4a|m4b|mp4v|3gp|3g2)\s*(?:$|;)/i,$a="mpeg4 aac flv mov mp4 m4v f4v m4a m4b mp4v 3gp 3g2".split(" "),
|
||||||
|
fb=RegExp("\\.("+$a.join("|")+")(\\?.*)?$","i");this.mimePattern=/^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i;this.useAltURL=!Ea;var Fa;try{Fa=Audio!==g&&(Ba&&opera!==g&&10>opera.version()?new Audio(null):new Audio).canPlayType!==g}catch(hb){Fa=!1}this.hasHTML5=Fa;this.setup=function(b){var e=!c.url;b!==g&&(j&&u&&c.ok()&&(b.flashVersion!==g||b.url!==g||b.html5Test!==g))&&H(v("setupLate"));ka(b);e&&(M&&b.url!==g)&&c.beginDelayedInit();!M&&(b.url!==g&&"complete"===l.readyState)&&setTimeout(E,1);return c};
|
||||||
|
this.supported=this.ok=function(){return u?j&&!s:c.useHTML5Audio&&c.hasHTML5};this.getMovie=function(b){return T(b)||l[b]||i[b]};this.createSound=function(b,e){function d(){a=Y(a);c.sounds[a.id]=new Ga(a);c.soundIDs.push(a.id);return c.sounds[a.id]}var a,f=null;if(!j||!c.ok())return H(void 0),!1;e!==g&&(b={id:b,url:e});a=t(b);a.url=aa(a.url);if(p(a.id,!0))return c.sounds[a.id];ba(a)?(f=d(),f._setup_html5(a)):(8<k&&null===a.isMovieStar&&(a.isMovieStar=!(!a.serverURL&&!(a.type&&a.type.match(Za)||a.url.match(fb)))),
|
||||||
|
a=Z(a,void 0),f=d(),8===k?h._createSound(a.id,a.loops||1,a.usePolicyFile):(h._createSound(a.id,a.url,a.usePeakData,a.useWaveformData,a.useEQData,a.isMovieStar,a.isMovieStar?a.bufferTime:!1,a.loops||1,a.serverURL,a.duration||null,a.autoPlay,!0,a.autoLoad,a.usePolicyFile),a.serverURL||(f.connected=!0,a.onconnect&&a.onconnect.apply(f))),!a.serverURL&&(a.autoLoad||a.autoPlay)&&f.load(a));!a.serverURL&&a.autoPlay&&f.play();return f};this.destroySound=function(b,e){if(!p(b))return!1;var d=c.sounds[b],a;
|
||||||
|
d._iO={};d.stop();d.unload();for(a=0;a<c.soundIDs.length;a++)if(c.soundIDs[a]===b){c.soundIDs.splice(a,1);break}e||d.destruct(!0);delete c.sounds[b];return!0};this.load=function(b,e){return!p(b)?!1:c.sounds[b].load(e)};this.unload=function(b){return!p(b)?!1:c.sounds[b].unload()};this.onposition=this.onPosition=function(b,e,d,a){return!p(b)?!1:c.sounds[b].onposition(e,d,a)};this.clearOnPosition=function(b,e,d){return!p(b)?!1:c.sounds[b].clearOnPosition(e,d)};this.start=this.play=function(b,e){var d=
|
||||||
|
!1;return!j||!c.ok()?(H("soundManager.play(): "+v(!j?"notReady":"notOK")),d):!p(b)?(e instanceof Object||(e={url:e}),e&&e.url&&(e.id=b,d=c.createSound(e).play()),d):c.sounds[b].play(e)};this.setPosition=function(b,e){return!p(b)?!1:c.sounds[b].setPosition(e)};this.stop=function(b){return!p(b)?!1:c.sounds[b].stop()};this.stopAll=function(){for(var b in c.sounds)c.sounds.hasOwnProperty(b)&&c.sounds[b].stop()};this.pause=function(b){return!p(b)?!1:c.sounds[b].pause()};this.pauseAll=function(){var b;
|
||||||
|
for(b=c.soundIDs.length-1;0<=b;b--)c.sounds[c.soundIDs[b]].pause()};this.resume=function(b){return!p(b)?!1:c.sounds[b].resume()};this.resumeAll=function(){var b;for(b=c.soundIDs.length-1;0<=b;b--)c.sounds[c.soundIDs[b]].resume()};this.togglePause=function(b){return!p(b)?!1:c.sounds[b].togglePause()};this.setPan=function(b,e){return!p(b)?!1:c.sounds[b].setPan(e)};this.setVolume=function(b,e){return!p(b)?!1:c.sounds[b].setVolume(e)};this.mute=function(b){var e=0;b instanceof String&&(b=null);if(b)return!p(b)?
|
||||||
|
!1:c.sounds[b].mute();for(e=c.soundIDs.length-1;0<=e;e--)c.sounds[c.soundIDs[e]].mute();return c.muted=!0};this.muteAll=function(){c.mute()};this.unmute=function(b){b instanceof String&&(b=null);if(b)return!p(b)?!1:c.sounds[b].unmute();for(b=c.soundIDs.length-1;0<=b;b--)c.sounds[c.soundIDs[b]].unmute();c.muted=!1;return!0};this.unmuteAll=function(){c.unmute()};this.toggleMute=function(b){return!p(b)?!1:c.sounds[b].toggleMute()};this.getMemoryUse=function(){var b=0;h&&8!==k&&(b=parseInt(h._getMemoryUse(),
|
||||||
|
10));return b};this.disable=function(b){var e;b===g&&(b=!1);if(s)return!1;s=!0;for(e=c.soundIDs.length-1;0<=e;e--)La(c.sounds[c.soundIDs[e]]);L(b);n.remove(i,"load",C);return!0};this.canPlayMIME=function(b){var e;c.hasHTML5&&(e=Q({type:b}));!e&&u&&(e=b&&c.ok()?!!(8<k&&b.match(Za)||b.match(c.mimePattern)):null);return e};this.canPlayURL=function(b){var e;c.hasHTML5&&(e=Q({url:b}));!e&&u&&(e=b&&c.ok()?!!b.match(c.filePattern):null);return e};this.canPlayLink=function(b){return b.type!==g&&b.type&&c.canPlayMIME(b.type)?
|
||||||
|
!0:c.canPlayURL(b.href)};this.getSoundById=function(b){if(!b)throw Error("soundManager.getSoundById(): sID is null/_undefined");return c.sounds[b]};this.onready=function(b,c){if("function"===typeof b)c||(c=i),la("onready",b,c),B();else throw v("needFunction","onready");return!0};this.ontimeout=function(b,c){if("function"===typeof b)c||(c=i),la("ontimeout",b,c),B({type:"ontimeout"});else throw v("needFunction","ontimeout");return!0};this._wD=this._writeDebug=function(){return!0};this._debug=function(){};
|
||||||
|
this.reboot=function(b,e){var d,a,f;for(d=c.soundIDs.length-1;0<=d;d--)c.sounds[c.soundIDs[d]].destruct();if(h)try{z&&(ta=h.innerHTML),N=h.parentNode.removeChild(h)}catch(g){}ta=N=u=h=null;c.enabled=M=j=O=va=J=K=s=w=c.swfLoaded=!1;c.soundIDs=[];c.sounds={};if(b)r=[];else for(d in r)if(r.hasOwnProperty(d)){a=0;for(f=r[d].length;a<f;a++)r[d][a].fired=!1}c.html5={usingFlash:null};c.flash={};c.html5Only=!1;c.ignoreFlash=!1;i.setTimeout(function(){oa();e||c.beginDelayedInit()},20);return c};this.reset=
|
||||||
|
function(){return c.reboot(!0,!0)};this.getMoviePercent=function(){return h&&"PercentLoaded"in h?h.PercentLoaded():null};this.beginDelayedInit=function(){ja=!0;E();setTimeout(function(){if(va)return!1;X();W();return va=!0},20);D()};this.destruct=function(){c.disable(!0)};Ga=function(b){var e,d,a=this,f,ab,i,I,l,m,q=!1,j=[],n=0,s,u,r=null;d=e=null;this.sID=this.id=b.id;this.url=b.url;this._iO=this.instanceOptions=this.options=t(b);this.pan=this.options.pan;this.volume=this.options.volume;this.isHTML5=
|
||||||
|
!1;this._a=null;this.id3={};this._debug=function(){};this.load=function(b){var c=null;b!==g?a._iO=t(b,a.options):(b=a.options,a._iO=b,r&&r!==a.url&&(a._iO.url=a.url,a.url=null));a._iO.url||(a._iO.url=a.url);a._iO.url=aa(a._iO.url);b=a.instanceOptions=a._iO;if(b.url===a.url&&0!==a.readyState&&2!==a.readyState)return 3===a.readyState&&b.onload&&b.onload.apply(a,[!!a.duration]),a;a.loaded=!1;a.readyState=1;a.playState=0;a.id3={};if(ba(b))c=a._setup_html5(b),c._called_load||(a._html5_canplay=!1,a.url!==
|
||||||
|
b.url&&(a._a.src=b.url,a.setPosition(0)),a._a.autobuffer="auto",a._a.preload="auto",a._a._called_load=!0,b.autoPlay&&a.play());else try{a.isHTML5=!1,a._iO=Z(Y(b)),b=a._iO,8===k?h._load(a.id,b.url,b.stream,b.autoPlay,b.usePolicyFile):h._load(a.id,b.url,!!b.stream,!!b.autoPlay,b.loops||1,!!b.autoLoad,b.usePolicyFile)}catch(e){F({type:"SMSOUND_LOAD_JS_EXCEPTION",fatal:!0})}a.url=b.url;return a};this.unload=function(){0!==a.readyState&&(a.isHTML5?(I(),a._a&&(a._a.pause(),wa(a._a,"about:blank"),r="about:blank")):
|
||||||
|
8===k?h._unload(a.id,"about:blank"):h._unload(a.id),f());return a};this.destruct=function(b){a.isHTML5?(I(),a._a&&(a._a.pause(),wa(a._a),w||i(),a._a._s=null,a._a=null)):(a._iO.onfailure=null,h._destroySound(a.id));b||c.destroySound(a.id,!0)};this.start=this.play=function(b,c){var e,d;d=!0;d=null;c=c===g?!0:c;b||(b={});a.url&&(a._iO.url=a.url);a._iO=t(a._iO,a.options);a._iO=t(b,a._iO);a._iO.url=aa(a._iO.url);a.instanceOptions=a._iO;if(a._iO.serverURL&&!a.connected)return a.getAutoPlay()||a.setAutoPlay(!0),
|
||||||
|
a;ba(a._iO)&&(a._setup_html5(a._iO),l());1===a.playState&&!a.paused&&((e=a._iO.multiShot)||(d=a));if(null!==d)return d;b.url&&b.url!==a.url&&a.load(a._iO);a.loaded||(0===a.readyState?(a.isHTML5||(a._iO.autoPlay=!0),a.load(a._iO),a.instanceOptions=a._iO):2===a.readyState&&(d=a));if(null!==d)return d;!a.isHTML5&&(9===k&&0<a.position&&a.position===a.duration)&&(b.position=0);if(a.paused&&0<=a.position&&(!a._iO.serverURL||0<a.position))a.resume();else{a._iO=t(b,a._iO);if(null!==a._iO.from&&null!==a._iO.to&&
|
||||||
|
0===a.instanceCount&&0===a.playState&&!a._iO.serverURL){e=function(){a._iO=t(b,a._iO);a.play(a._iO)};if(a.isHTML5&&!a._html5_canplay)a.load({oncanplay:e}),d=!1;else if(!a.isHTML5&&!a.loaded&&(!a.readyState||2!==a.readyState))a.load({onload:e}),d=!1;if(null!==d)return d;a._iO=u()}(!a.instanceCount||a._iO.multiShotEvents||!a.isHTML5&&8<k&&!a.getAutoPlay())&&a.instanceCount++;a._iO.onposition&&0===a.playState&&m(a);a.playState=1;a.paused=!1;a.position=a._iO.position!==g&&!isNaN(a._iO.position)?a._iO.position:
|
||||||
|
0;a.isHTML5||(a._iO=Z(Y(a._iO)));a._iO.onplay&&c&&(a._iO.onplay.apply(a),q=!0);a.setVolume(a._iO.volume,!0);a.setPan(a._iO.pan,!0);a.isHTML5?(l(),d=a._setup_html5(),a.setPosition(a._iO.position),d.play()):(d=h._start(a.id,a._iO.loops||1,9===k?a._iO.position:a._iO.position/1E3,a._iO.multiShot),9===k&&!d&&a._iO.onplayerror&&a._iO.onplayerror.apply(a))}return a};this.stop=function(b){var c=a._iO;1===a.playState&&(a._onbufferchange(0),a._resetOnPosition(0),a.paused=!1,a.isHTML5||(a.playState=0),s(),c.to&&
|
||||||
|
a.clearOnPosition(c.to),a.isHTML5?a._a&&(b=a.position,a.setPosition(0),a.position=b,a._a.pause(),a.playState=0,a._onTimer(),I()):(h._stop(a.id,b),c.serverURL&&a.unload()),a.instanceCount=0,a._iO={},c.onstop&&c.onstop.apply(a));return a};this.setAutoPlay=function(b){a._iO.autoPlay=b;a.isHTML5||(h._setAutoPlay(a.id,b),b&&!a.instanceCount&&1===a.readyState&&a.instanceCount++)};this.getAutoPlay=function(){return a._iO.autoPlay};this.setPosition=function(b){b===g&&(b=0);var c=a.isHTML5?Math.max(b,0):Math.min(a.duration||
|
||||||
|
a._iO.duration,Math.max(b,0));a.position=c;b=a.position/1E3;a._resetOnPosition(a.position);a._iO.position=c;if(a.isHTML5){if(a._a&&a._html5_canplay&&a._a.currentTime!==b)try{a._a.currentTime=b,(0===a.playState||a.paused)&&a._a.pause()}catch(e){}}else b=9===k?a.position:b,a.readyState&&2!==a.readyState&&h._setPosition(a.id,b,a.paused||!a.playState,a._iO.multiShot);a.isHTML5&&a.paused&&a._onTimer(!0);return a};this.pause=function(b){if(a.paused||0===a.playState&&1!==a.readyState)return a;a.paused=!0;
|
||||||
|
a.isHTML5?(a._setup_html5().pause(),I()):(b||b===g)&&h._pause(a.id,a._iO.multiShot);a._iO.onpause&&a._iO.onpause.apply(a);return a};this.resume=function(){var b=a._iO;if(!a.paused)return a;a.paused=!1;a.playState=1;a.isHTML5?(a._setup_html5().play(),l()):(b.isMovieStar&&!b.serverURL&&a.setPosition(a.position),h._pause(a.id,b.multiShot));!q&&b.onplay?(b.onplay.apply(a),q=!0):b.onresume&&b.onresume.apply(a);return a};this.togglePause=function(){if(0===a.playState)return a.play({position:9===k&&!a.isHTML5?
|
||||||
|
a.position:a.position/1E3}),a;a.paused?a.resume():a.pause();return a};this.setPan=function(b,c){b===g&&(b=0);c===g&&(c=!1);a.isHTML5||h._setPan(a.id,b);a._iO.pan=b;c||(a.pan=b,a.options.pan=b);return a};this.setVolume=function(b,e){b===g&&(b=100);e===g&&(e=!1);a.isHTML5?a._a&&(a._a.volume=Math.max(0,Math.min(1,b/100))):h._setVolume(a.id,c.muted&&!a.muted||a.muted?0:b);a._iO.volume=b;e||(a.volume=b,a.options.volume=b);return a};this.mute=function(){a.muted=!0;a.isHTML5?a._a&&(a._a.muted=!0):h._setVolume(a.id,
|
||||||
|
0);return a};this.unmute=function(){a.muted=!1;var b=a._iO.volume!==g;a.isHTML5?a._a&&(a._a.muted=!1):h._setVolume(a.id,b?a._iO.volume:a.options.volume);return a};this.toggleMute=function(){return a.muted?a.unmute():a.mute()};this.onposition=this.onPosition=function(b,c,e){j.push({position:parseInt(b,10),method:c,scope:e!==g?e:a,fired:!1});return a};this.clearOnPosition=function(a,b){var c,a=parseInt(a,10);if(isNaN(a))return!1;for(c=0;c<j.length;c++)if(a===j[c].position&&(!b||b===j[c].method))j[c].fired&&
|
||||||
|
n--,j.splice(c,1)};this._processOnPosition=function(){var b,c;b=j.length;if(!b||!a.playState||n>=b)return!1;for(b-=1;0<=b;b--)c=j[b],!c.fired&&a.position>=c.position&&(c.fired=!0,n++,c.method.apply(c.scope,[c.position]));return!0};this._resetOnPosition=function(a){var b,c;b=j.length;if(!b)return!1;for(b-=1;0<=b;b--)c=j[b],c.fired&&a<=c.position&&(c.fired=!1,n--);return!0};u=function(){var b=a._iO,c=b.from,e=b.to,d,f;f=function(){a.clearOnPosition(e,f);a.stop()};d=function(){if(null!==e&&!isNaN(e))a.onPosition(e,
|
||||||
|
f)};null!==c&&!isNaN(c)&&(b.position=c,b.multiShot=!1,d());return b};m=function(){var b,c=a._iO.onposition;if(c)for(b in c)if(c.hasOwnProperty(b))a.onPosition(parseInt(b,10),c[b])};s=function(){var b,c=a._iO.onposition;if(c)for(b in c)c.hasOwnProperty(b)&&a.clearOnPosition(parseInt(b,10))};l=function(){a.isHTML5&&Na(a)};I=function(){a.isHTML5&&Oa(a)};f=function(b){b||(j=[],n=0);q=!1;a._hasTimer=null;a._a=null;a._html5_canplay=!1;a.bytesLoaded=null;a.bytesTotal=null;a.duration=a._iO&&a._iO.duration?
|
||||||
|
a._iO.duration:null;a.durationEstimate=null;a.buffered=[];a.eqData=[];a.eqData.left=[];a.eqData.right=[];a.failures=0;a.isBuffering=!1;a.instanceOptions={};a.instanceCount=0;a.loaded=!1;a.metadata={};a.readyState=0;a.muted=!1;a.paused=!1;a.peakData={left:0,right:0};a.waveformData={left:[],right:[]};a.playState=0;a.position=null;a.id3={}};f();this._onTimer=function(b){var c,f=!1,g={};if(a._hasTimer||b){if(a._a&&(b||(0<a.playState||1===a.readyState)&&!a.paused))c=a._get_html5_duration(),c!==e&&(e=c,
|
||||||
|
a.duration=c,f=!0),a.durationEstimate=a.duration,c=1E3*a._a.currentTime||0,c!==d&&(d=c,f=!0),(f||b)&&a._whileplaying(c,g,g,g,g);return f}};this._get_html5_duration=function(){var b=a._iO;return(b=a._a&&a._a.duration?1E3*a._a.duration:b&&b.duration?b.duration:null)&&!isNaN(b)&&Infinity!==b?b:null};this._apply_loop=function(a,b){a.loop=1<b?"loop":""};this._setup_html5=function(b){var b=t(a._iO,b),c=decodeURI,e=w?Ha:a._a,d=c(b.url),g;w?d===ya&&(g=!0):d===r&&(g=!0);if(e){if(e._s)if(w)e._s&&(e._s.playState&&
|
||||||
|
!g)&&e._s.stop();else if(!w&&d===c(r))return a._apply_loop(e,b.loops),e;g||(f(!1),e.src=b.url,ya=r=a.url=b.url,e._called_load=!1)}else a._a=b.autoLoad||b.autoPlay?new Audio(b.url):Ba&&10>opera.version()?new Audio(null):new Audio,e=a._a,e._called_load=!1,w&&(Ha=e);a.isHTML5=!0;a._a=e;e._s=a;ab();a._apply_loop(e,b.loops);b.autoLoad||b.autoPlay?a.load():(e.autobuffer=!1,e.preload="auto");return e};ab=function(){if(a._a._added_events)return!1;var b;a._a._added_events=!0;for(b in x)x.hasOwnProperty(b)&&
|
||||||
|
a._a&&a._a.addEventListener(b,x[b],!1);return!0};i=function(){var b;a._a._added_events=!1;for(b in x)x.hasOwnProperty(b)&&a._a&&a._a.removeEventListener(b,x[b],!1)};this._onload=function(b){b=!!b||!a.isHTML5&&8===k&&a.duration;a.loaded=b;a.readyState=b?3:2;a._onbufferchange(0);a._iO.onload&&a._iO.onload.apply(a,[b]);return!0};this._onbufferchange=function(b){if(0===a.playState||b&&a.isBuffering||!b&&!a.isBuffering)return!1;a.isBuffering=1===b;a._iO.onbufferchange&&a._iO.onbufferchange.apply(a);return!0};
|
||||||
|
this._onsuspend=function(){a._iO.onsuspend&&a._iO.onsuspend.apply(a);return!0};this._onfailure=function(b,c,e){a.failures++;if(a._iO.onfailure&&1===a.failures)a._iO.onfailure(a,b,c,e)};this._onfinish=function(){var b=a._iO.onfinish;a._onbufferchange(0);a._resetOnPosition(0);a.instanceCount&&(a.instanceCount--,a.instanceCount||(s(),a.playState=0,a.paused=!1,a.instanceCount=0,a.instanceOptions={},a._iO={},I(),a.isHTML5&&(a.position=0)),(!a.instanceCount||a._iO.multiShotEvents)&&b&&b.apply(a))};this._whileloading=
|
||||||
|
function(b,c,e,d){var f=a._iO;a.bytesLoaded=b;a.bytesTotal=c;a.duration=Math.floor(e);a.bufferLength=d;a.durationEstimate=!a.isHTML5&&!f.isMovieStar?f.duration?a.duration>f.duration?a.duration:f.duration:parseInt(a.bytesTotal/a.bytesLoaded*a.duration,10):a.duration;a.isHTML5||(a.buffered=[{start:0,end:a.duration}]);(3!==a.readyState||a.isHTML5)&&f.whileloading&&f.whileloading.apply(a)};this._whileplaying=function(b,c,e,d,f){var h=a._iO;if(isNaN(b)||null===b)return!1;a.position=Math.max(0,b);a._processOnPosition();
|
||||||
|
!a.isHTML5&&8<k&&(h.usePeakData&&(c!==g&&c)&&(a.peakData={left:c.leftPeak,right:c.rightPeak}),h.useWaveformData&&(e!==g&&e)&&(a.waveformData={left:e.split(","),right:d.split(",")}),h.useEQData&&(f!==g&&f&&f.leftEQ)&&(b=f.leftEQ.split(","),a.eqData=b,a.eqData.left=b,f.rightEQ!==g&&f.rightEQ&&(a.eqData.right=f.rightEQ.split(","))));1===a.playState&&(!a.isHTML5&&(8===k&&!a.position&&a.isBuffering)&&a._onbufferchange(0),h.whileplaying&&h.whileplaying.apply(a));return!0};this._oncaptiondata=function(b){a.captiondata=
|
||||||
|
b;a._iO.oncaptiondata&&a._iO.oncaptiondata.apply(a,[b])};this._onmetadata=function(b,c){var e={},d,f;d=0;for(f=b.length;d<f;d++)e[b[d]]=c[d];a.metadata=e;a._iO.onmetadata&&a._iO.onmetadata.apply(a)};this._onid3=function(b,c){var e=[],d,f;d=0;for(f=b.length;d<f;d++)e[b[d]]=c[d];a.id3=t(a.id3,e);a._iO.onid3&&a._iO.onid3.apply(a)};this._onconnect=function(b){b=1===b;if(a.connected=b)a.failures=0,p(a.id)&&(a.getAutoPlay()?a.play(g,a.getAutoPlay()):a._iO.autoLoad&&a.load()),a._iO.onconnect&&a._iO.onconnect.apply(a,
|
||||||
|
[b])};this._ondataerror=function(){0<a.playState&&a._iO.ondataerror&&a._iO.ondataerror.apply(a)}};qa=function(){return l.body||l._docElement||l.getElementsByTagName("div")[0]};T=function(b){return l.getElementById(b)};t=function(b,e){var d=b||{},a,f;a=e===g?c.defaultOptions:e;for(f in a)a.hasOwnProperty(f)&&d[f]===g&&(d[f]="object"!==typeof a[f]||null===a[f]?a[f]:t(d[f],a[f]));return d};U={onready:1,ontimeout:1,defaultOptions:1,flash9Options:1,movieStarOptions:1};ka=function(b,e){var d,a=!0,f=e!==
|
||||||
|
g,h=c.setupOptions;for(d in b)if(b.hasOwnProperty(d))if("object"!==typeof b[d]||null===b[d]||b[d]instanceof Array||b[d]instanceof RegExp)f&&U[e]!==g?c[e][d]=b[d]:h[d]!==g?(c.setupOptions[d]=b[d],c[d]=b[d]):U[d]===g?(H(v(c[d]===g?"setupUndef":"setupError",d),2),a=!1):c[d]instanceof Function?c[d].apply(c,b[d]instanceof Array?b[d]:[b[d]]):c[d]=b[d];else if(U[d]===g)H(v(c[d]===g?"setupUndef":"setupError",d),2),a=!1;else return ka(b[d],d);return a};var bb=function(b){var b=db.call(b),c=b.length;ea?(b[1]=
|
||||||
|
"on"+b[1],3<c&&b.pop()):3===c&&b.push(!1);return b},cb=function(b,c){var d=b.shift(),a=[gb[c]];if(ea)d[a](b[0],b[1]);else d[a].apply(d,b)},ea=i.attachEvent,gb={add:ea?"attachEvent":"addEventListener",remove:ea?"detachEvent":"removeEventListener"};n={add:function(){cb(bb(arguments),"add")},remove:function(){cb(bb(arguments),"remove")}};x={abort:m(function(){}),canplay:m(function(){var b=this._s,c;if(b._html5_canplay)return!0;b._html5_canplay=!0;b._onbufferchange(0);c=b._iO.position!==g&&!isNaN(b._iO.position)?
|
||||||
|
b._iO.position/1E3:null;if(b.position&&this.currentTime!==c)try{this.currentTime=c}catch(d){}b._iO._oncanplay&&b._iO._oncanplay()}),canplaythrough:m(function(){var b=this._s;b.loaded||(b._onbufferchange(0),b._whileloading(b.bytesLoaded,b.bytesTotal,b._get_html5_duration()),b._onload(!0))}),ended:m(function(){this._s._onfinish()}),error:m(function(){this._s._onload(!1)}),loadeddata:m(function(){var b=this._s;!b._loaded&&!Aa&&(b.duration=b._get_html5_duration())}),loadedmetadata:m(function(){}),loadstart:m(function(){this._s._onbufferchange(1)}),
|
||||||
|
play:m(function(){this._s._onbufferchange(0)}),playing:m(function(){this._s._onbufferchange(0)}),progress:m(function(b){var c=this._s,d,a,f=0,f=b.target.buffered;d=b.loaded||0;var g=b.total||1;c.buffered=[];if(f&&f.length){d=0;for(a=f.length;d<a;d++)c.buffered.push({start:1E3*f.start(d),end:1E3*f.end(d)});f=1E3*(f.end(0)-f.start(0));d=f/(1E3*b.target.duration)}isNaN(d)||(c._onbufferchange(0),c._whileloading(d,g,c._get_html5_duration()),d&&(g&&d===g)&&x.canplaythrough.call(this,b))}),ratechange:m(function(){}),
|
||||||
|
suspend:m(function(b){var c=this._s;x.progress.call(this,b);c._onsuspend()}),stalled:m(function(){}),timeupdate:m(function(){this._s._onTimer()}),waiting:m(function(){this._s._onbufferchange(1)})};ba=function(b){return b.serverURL||b.type&&S(b.type)?!1:b.type?Q({type:b.type}):Q({url:b.url})||c.html5Only};wa=function(b,c){b&&(b.src=c,b._called_load=!1);w&&(ya=null)};Q=function(b){if(!c.useHTML5Audio||!c.hasHTML5)return!1;var e=b.url||null,b=b.type||null,d=c.audioFormats,a;if(b&&c.html5[b]!==g)return c.html5[b]&&
|
||||||
|
!S(b);if(!y){y=[];for(a in d)d.hasOwnProperty(a)&&(y.push(a),d[a].related&&(y=y.concat(d[a].related)));y=RegExp("\\.("+y.join("|")+")(\\?.*)?$","i")}a=e?e.toLowerCase().match(y):null;!a||!a.length?b&&(e=b.indexOf(";"),a=(-1!==e?b.substr(0,e):b).substr(6)):a=a[1];a&&c.html5[a]!==g?e=c.html5[a]&&!S(a):(b="audio/"+a,e=c.html5.canPlayType({type:b}),e=(c.html5[a]=e)&&c.html5[b]&&!S(b));return e};Sa=function(){function b(a){var b,d,f=b=!1;if(!e||"function"!==typeof e.canPlayType)return b;if(a instanceof
|
||||||
|
Array){b=0;for(d=a.length;b<d;b++)if(c.html5[a[b]]||e.canPlayType(a[b]).match(c.html5Test))f=!0,c.html5[a[b]]=!0,c.flash[a[b]]=!!a[b].match(Xa);b=f}else a=e&&"function"===typeof e.canPlayType?e.canPlayType(a):!1,b=!(!a||!a.match(c.html5Test));return b}if(!c.useHTML5Audio||!c.hasHTML5)return!1;var e=Audio!==g?Ba&&10>opera.version()?new Audio(null):new Audio:null,d,a,f={},h;h=c.audioFormats;for(d in h)if(h.hasOwnProperty(d)&&(a="audio/"+d,f[d]=b(h[d].type),f[a]=f[d],d.match(Xa)?(c.flash[d]=!0,c.flash[a]=
|
||||||
|
!0):(c.flash[d]=!1,c.flash[a]=!1),h[d]&&h[d].related))for(a=h[d].related.length-1;0<=a;a--)f["audio/"+h[d].related[a]]=f[d],c.html5[h[d].related[a]]=f[d],c.flash[h[d].related[a]]=f[d];f.canPlayType=e?b:null;c.html5=t(c.html5,f);return!0};na={};v=function(){};Y=function(b){8===k&&(1<b.loops&&b.stream)&&(b.stream=!1);return b};Z=function(b){if(b&&!b.usePolicyFile&&(b.onid3||b.usePeakData||b.useWaveformData||b.useEQData))b.usePolicyFile=!0;return b};H=function(){};ha=function(){return!1};La=function(b){for(var c in b)b.hasOwnProperty(c)&&
|
||||||
|
"function"===typeof b[c]&&(b[c]=ha)};sa=function(b){b===g&&(b=!1);(s||b)&&c.disable(b)};Ma=function(b){var e=null;if(b)if(b.match(/\.swf(\?.*)?$/i)){if(e=b.substr(b.toLowerCase().lastIndexOf(".swf?")+4))return b}else b.lastIndexOf("/")!==b.length-1&&(b+="/");b=(b&&-1!==b.lastIndexOf("/")?b.substr(0,b.lastIndexOf("/")+1):"./")+c.movieURL;c.noSWFCache&&(b+="?ts="+(new Date).getTime());return b};ma=function(){k=parseInt(c.flashVersion,10);8!==k&&9!==k&&(c.flashVersion=k=8);var b=c.debugMode||c.debugFlash?
|
||||||
|
"_debug.swf":".swf";c.useHTML5Audio&&(!c.html5Only&&c.audioFormats.mp4.required&&9>k)&&(c.flashVersion=k=9);c.version=c.versionNumber+(c.html5Only?" (HTML5-only mode)":9===k?" (AS3/Flash 9)":" (AS2/Flash 8)");8<k?(c.defaultOptions=t(c.defaultOptions,c.flash9Options),c.features.buffering=!0,c.defaultOptions=t(c.defaultOptions,c.movieStarOptions),c.filePatterns.flash9=RegExp("\\.(mp3|"+$a.join("|")+")(\\?.*)?$","i"),c.features.movieStar=!0):c.features.movieStar=!1;c.filePattern=c.filePatterns[8!==k?
|
||||||
|
"flash9":"flash8"];c.movieURL=(8===k?"soundmanager2.swf":"soundmanager2_flash9.swf").replace(".swf",b);c.features.peakData=c.features.waveformData=c.features.eqData=8<k};Ka=function(b,c){if(!h)return!1;h._setPolling(b,c)};ra=function(){c.debugURLParam.test(ga)&&(c.debugMode=!0)};p=this.getSoundById;G=function(){var b=[];c.debugMode&&b.push("sm2_debug");c.debugFlash&&b.push("flash_debug");c.useHighPerformance&&b.push("high_performance");return b.join(" ")};ua=function(){v("fbHandler");var b=c.getMoviePercent(),
|
||||||
|
e={type:"FLASHBLOCK"};if(c.html5Only)return!1;c.ok()?c.oMC&&(c.oMC.className=[G(),"movieContainer","swf_loaded"+(c.didFlashBlock?" swf_unblocked":"")].join(" ")):(u&&(c.oMC.className=G()+" movieContainer "+(null===b?"swf_timedout":"swf_error")),c.didFlashBlock=!0,B({type:"ontimeout",ignoreInit:!0,error:e}),F(e))};la=function(b,c,d){r[b]===g&&(r[b]=[]);r[b].push({method:c,scope:d||null,fired:!1})};B=function(b){b||(b={type:c.ok()?"onready":"ontimeout"});if(!j&&b&&!b.ignoreInit||"ontimeout"===b.type&&
|
||||||
|
(c.ok()||s&&!b.ignoreInit))return!1;var e={success:b&&b.ignoreInit?c.ok():!s},d=b&&b.type?r[b.type]||[]:[],a=[],f,e=[e],g=u&&!c.ok();b.error&&(e[0].error=b.error);b=0;for(f=d.length;b<f;b++)!0!==d[b].fired&&a.push(d[b]);if(a.length){b=0;for(f=a.length;b<f;b++)a[b].scope?a[b].method.apply(a[b].scope,e):a[b].method.apply(this,e),g||(a[b].fired=!0)}return!0};C=function(){i.setTimeout(function(){c.useFlashBlock&&ua();B();"function"===typeof c.onload&&c.onload.apply(i);c.waitForWindowLoad&&n.add(i,"load",
|
||||||
|
C)},1)};za=function(){if(A!==g)return A;var b=!1,c=navigator,d=c.plugins,a,f=i.ActiveXObject;if(d&&d.length)(c=c.mimeTypes)&&(c["application/x-shockwave-flash"]&&c["application/x-shockwave-flash"].enabledPlugin&&c["application/x-shockwave-flash"].enabledPlugin.description)&&(b=!0);else if(f!==g&&!q.match(/MSAppHost/i)){try{a=new f("ShockwaveFlash.ShockwaveFlash")}catch(h){}b=!!a}return A=b};Ra=function(){var b,e,d=c.audioFormats;if(ca&&q.match(/os (1|2|3_0|3_1)/i))c.hasHTML5=!1,c.html5Only=!0,c.oMC&&
|
||||||
|
(c.oMC.style.display="none");else if(c.useHTML5Audio&&(!c.html5||!c.html5.canPlayType))c.hasHTML5=!1;if(c.useHTML5Audio&&c.hasHTML5)for(e in d)if(d.hasOwnProperty(e)&&(d[e].required&&!c.html5.canPlayType(d[e].type)||c.preferFlash&&(c.flash[e]||c.flash[d[e].type])))b=!0;c.ignoreFlash&&(b=!1);c.html5Only=c.hasHTML5&&c.useHTML5Audio&&!b;return!c.html5Only};aa=function(b){var e,d,a=0;if(b instanceof Array){e=0;for(d=b.length;e<d;e++)if(b[e]instanceof Object){if(c.canPlayMIME(b[e].type)){a=e;break}}else if(c.canPlayURL(b[e])){a=
|
||||||
|
e;break}b[a].url&&(b[a]=b[a].url);b=b[a]}return b};Na=function(b){b._hasTimer||(b._hasTimer=!0,!Ca&&c.html5PollingInterval&&(null===P&&0===$&&(P=i.setInterval(Pa,c.html5PollingInterval)),$++))};Oa=function(b){b._hasTimer&&(b._hasTimer=!1,!Ca&&c.html5PollingInterval&&$--)};Pa=function(){var b;if(null!==P&&!$)return i.clearInterval(P),P=null,!1;for(b=c.soundIDs.length-1;0<=b;b--)c.sounds[c.soundIDs[b]].isHTML5&&c.sounds[c.soundIDs[b]]._hasTimer&&c.sounds[c.soundIDs[b]]._onTimer()};F=function(b){b=b!==
|
||||||
|
g?b:{};"function"===typeof c.onerror&&c.onerror.apply(i,[{type:b.type!==g?b.type:null}]);b.fatal!==g&&b.fatal&&c.disable()};Ta=function(){if(!Va||!za())return!1;var b=c.audioFormats,e,d;for(d in b)if(b.hasOwnProperty(d)&&("mp3"===d||"mp4"===d))if(c.html5[d]=!1,b[d]&&b[d].related)for(e=b[d].related.length-1;0<=e;e--)c.html5[b[d].related[e]]=!1};this._setSandboxType=function(){};this._externalInterfaceOK=function(){if(c.swfLoaded)return!1;c.swfLoaded=!0;da=!1;Va&&Ta();setTimeout(ia,z?100:1)};X=function(b,
|
||||||
|
e){function d(a,b){return'<param name="'+a+'" value="'+b+'" />'}if(J&&K)return!1;if(c.html5Only)return ma(),c.oMC=T(c.movieID),ia(),K=J=!0,!1;var a=e||c.url,f=c.altURL||a,h=qa(),i=G(),k=null,k=l.getElementsByTagName("html")[0],j,n,m,k=k&&k.dir&&k.dir.match(/rtl/i),b=b===g?c.id:b;ma();c.url=Ma(Ea?a:f);e=c.url;c.wmode=!c.wmode&&c.useHighPerformance?"transparent":c.wmode;if(null!==c.wmode&&(q.match(/msie 8/i)||!z&&!c.useHighPerformance)&&navigator.platform.match(/win32|win64/i))Qa.push(na.spcWmode),
|
||||||
|
c.wmode=null;h={name:b,id:b,src:e,quality:"high",allowScriptAccess:c.allowScriptAccess,bgcolor:c.bgColor,pluginspage:Ya+"www.macromedia.com/go/getflashplayer",title:"JS/Flash audio component (SoundManager 2)",type:"application/x-shockwave-flash",wmode:c.wmode,hasPriority:"true"};c.debugFlash&&(h.FlashVars="debug=1");c.wmode||delete h.wmode;if(z)a=l.createElement("div"),n=['<object id="'+b+'" data="'+e+'" type="'+h.type+'" title="'+h.title+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+
|
||||||
|
Ya+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">',d("movie",e),d("AllowScriptAccess",c.allowScriptAccess),d("quality",h.quality),c.wmode?d("wmode",c.wmode):"",d("bgcolor",c.bgColor),d("hasPriority","true"),c.debugFlash?d("FlashVars",h.FlashVars):"","</object>"].join("");else for(j in a=l.createElement("embed"),h)h.hasOwnProperty(j)&&a.setAttribute(j,h[j]);ra();i=G();if(h=qa())if(c.oMC=T(c.movieID)||l.createElement("div"),c.oMC.id)m=c.oMC.className,c.oMC.className=
|
||||||
|
(m?m+" ":"movieContainer")+(i?" "+i:""),c.oMC.appendChild(a),z&&(j=c.oMC.appendChild(l.createElement("div")),j.className="sm2-object-box",j.innerHTML=n),K=!0;else{c.oMC.id=c.movieID;c.oMC.className="movieContainer "+i;j=i=null;c.useFlashBlock||(c.useHighPerformance?i={position:"fixed",width:"8px",height:"8px",bottom:"0px",left:"0px",overflow:"hidden"}:(i={position:"absolute",width:"6px",height:"6px",top:"-9999px",left:"-9999px"},k&&(i.left=Math.abs(parseInt(i.left,10))+"px")));eb&&(c.oMC.style.zIndex=
|
||||||
|
1E4);if(!c.debugFlash)for(m in i)i.hasOwnProperty(m)&&(c.oMC.style[m]=i[m]);try{z||c.oMC.appendChild(a),h.appendChild(c.oMC),z&&(j=c.oMC.appendChild(l.createElement("div")),j.className="sm2-object-box",j.innerHTML=n),K=!0}catch(p){throw Error(v("domError")+" \n"+p.toString());}}return J=!0};W=function(){if(c.html5Only)return X(),!1;if(h||!c.url)return!1;h=c.getMovie(c.id);h||(N?(z?c.oMC.innerHTML=ta:c.oMC.appendChild(N),N=null,J=!0):X(c.id,c.url),h=c.getMovie(c.id));"function"===typeof c.oninitmovie&&
|
||||||
|
setTimeout(c.oninitmovie,1);return!0};D=function(){setTimeout(Ja,1E3)};Ja=function(){var b,e=!1;if(!c.url||O)return!1;O=!0;n.remove(i,"load",D);if(da&&!Da)return!1;j||(b=c.getMoviePercent(),0<b&&100>b&&(e=!0));setTimeout(function(){b=c.getMoviePercent();if(e)return O=!1,i.setTimeout(D,1),!1;!j&&Wa&&(null===b?c.useFlashBlock||0===c.flashLoadTimeout?c.useFlashBlock&&ua():B({type:"ontimeout",ignoreInit:!0}):0!==c.flashLoadTimeout&&sa(!0))},c.flashLoadTimeout)};V=function(){if(Da||!da)return n.remove(i,
|
||||||
|
"focus",V),!0;Da=Wa=!0;O=!1;D();n.remove(i,"focus",V);return!0};L=function(b){if(j)return!1;if(c.html5Only)return j=!0,C(),!0;var e=!0,d;if(!c.useFlashBlock||!c.flashLoadTimeout||c.getMoviePercent())j=!0,s&&(d={type:!A&&u?"NO_FLASH":"INIT_TIMEOUT"});if(s||b)c.useFlashBlock&&c.oMC&&(c.oMC.className=G()+" "+(null===c.getMoviePercent()?"swf_timedout":"swf_error")),B({type:"ontimeout",error:d,ignoreInit:!0}),F(d),e=!1;s||(c.waitForWindowLoad&&!ja?n.add(i,"load",C):C());return e};Ia=function(){var b,e=
|
||||||
|
c.setupOptions;for(b in e)e.hasOwnProperty(b)&&(c[b]===g?c[b]=e[b]:c[b]!==e[b]&&(c.setupOptions[b]=c[b]))};ia=function(){if(j)return!1;if(c.html5Only)return j||(n.remove(i,"load",c.beginDelayedInit),c.enabled=!0,L()),!0;W();try{h._externalInterfaceTest(!1),Ka(!0,c.flashPollingInterval||(c.useHighPerformance?10:50)),c.debugMode||h._disableDebug(),c.enabled=!0,c.html5Only||n.add(i,"unload",ha)}catch(b){return F({type:"JS_TO_FLASH_EXCEPTION",fatal:!0}),sa(!0),L(),!1}L();n.remove(i,"load",c.beginDelayedInit);
|
||||||
|
return!0};E=function(){if(M)return!1;M=!0;Ia();ra();!A&&c.hasHTML5&&c.setup({useHTML5Audio:!0,preferFlash:!1});Sa();c.html5.usingFlash=Ra();u=c.html5.usingFlash;!A&&u&&(Qa.push(na.needFlash),c.setup({flashLoadTimeout:1}));l.removeEventListener&&l.removeEventListener("DOMContentLoaded",E,!1);W();return!0};xa=function(){"complete"===l.readyState&&(E(),l.detachEvent("onreadystatechange",xa));return!0};pa=function(){ja=!0;n.remove(i,"load",pa)};oa=function(){if(Ca&&(c.setupOptions.useHTML5Audio=!0,c.setupOptions.preferFlash=
|
||||||
|
!1,ca||Ua&&!q.match(/android\s2\.3/i)))ca&&(c.ignoreFlash=!0),w=!0};oa();za();n.add(i,"focus",V);n.add(i,"load",D);n.add(i,"load",pa);l.addEventListener?l.addEventListener("DOMContentLoaded",E,!1):l.attachEvent?l.attachEvent("onreadystatechange",xa):F({type:"NO_DOM2_EVENTS",fatal:!0})}var fa=null;if(void 0===i.SM2_DEFER||!SM2_DEFER)fa=new R;i.SoundManager=R;i.soundManager=fa})(window);
|
Binary file not shown.
Binary file not shown.
@ -1,240 +0,0 @@
|
|||||||
if(RadiumEngine !== undefined)
|
|
||||||
{
|
|
||||||
/*Class*/ RadiumEngine.prototype.IsometricMap = function(canvas)
|
|
||||||
{
|
|
||||||
this.tile_width = 32;
|
|
||||||
this.tile_height = 64;
|
|
||||||
this.width = 6;
|
|
||||||
this.height = 6;
|
|
||||||
this.mouse_tile = undefined;
|
|
||||||
this.mouse_over = false;
|
|
||||||
this.mouse_in = false;
|
|
||||||
this.fill_screen = false;
|
|
||||||
|
|
||||||
this.canvas = canvas
|
|
||||||
this.context = canvas.getContext("2d");
|
|
||||||
|
|
||||||
$(this.canvas).bind('mouseenter', {'self': this}, function(event){
|
|
||||||
self.mouse_over = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
$(this.canvas).bind('mouseleave', {'self': this}, function(event){
|
|
||||||
self.mouse_over = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
$(this.canvas).bind('mousemove', {'self': this}, function(event){
|
|
||||||
self = event.data.self;
|
|
||||||
|
|
||||||
var rect = self.canvas.getBoundingClientRect();
|
|
||||||
var root = document.documentElement;
|
|
||||||
var mouse_x = event.clientX - rect.top - root.scrollTop;
|
|
||||||
var mouse_y = event.clientY - rect.left - root.scrollLeft;
|
|
||||||
var coords = event.data.self.TileFromPosition(mouse_x, mouse_y);
|
|
||||||
|
|
||||||
self.mouse_tile = coords;
|
|
||||||
|
|
||||||
if(coords.x >= 0 && coords.x < self.width && coords.y >= 0 && coords.y < self.height)
|
|
||||||
{
|
|
||||||
self.mouse_in = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
self.mouse_in = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.Redraw();
|
|
||||||
});
|
|
||||||
|
|
||||||
var Configure = this.Configure = function(tile_width, tile_height)
|
|
||||||
{
|
|
||||||
this.tile_width = tile_width;
|
|
||||||
this.tile_height = tile_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.SetFill = function(enabled)
|
|
||||||
{
|
|
||||||
if(enabled === true)
|
|
||||||
{
|
|
||||||
$(this.canvas).css({
|
|
||||||
'position': "absolute",
|
|
||||||
'left': "0px",
|
|
||||||
'top': "0px"
|
|
||||||
});
|
|
||||||
|
|
||||||
$('body').css({
|
|
||||||
'overflow': "hidden"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fill_screen = enabled;
|
|
||||||
this.UpdateSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.UpdateSize = function()
|
|
||||||
{
|
|
||||||
if(this.fill_screen === false)
|
|
||||||
{
|
|
||||||
this.canvas.width = $(this.canvas).width();
|
|
||||||
this.canvas.height = $(this.canvas).height();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.canvas.width = window.innerWidth;
|
|
||||||
this.canvas.height = window.innerHeight;
|
|
||||||
|
|
||||||
$(this.canvas).css({
|
|
||||||
'width': window.innerWidth + "px",
|
|
||||||
'height': window.innerHeight + "px"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var Redraw = this.Redraw = function()
|
|
||||||
{
|
|
||||||
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
||||||
|
|
||||||
for(var i = 0; i < this.height; i++)
|
|
||||||
{
|
|
||||||
for(var r = 0; r < this.width; r++)
|
|
||||||
{
|
|
||||||
this.DrawTile(r, i);
|
|
||||||
/*pos = this.GetTilePosition(r, i);
|
|
||||||
this.context.fillRect(pos.x, pos.y, 1, 1);*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.DrawTile = function(tile_x, tile_y)
|
|
||||||
{
|
|
||||||
var pos_x = tile_x * this.tile_width;
|
|
||||||
var pos_y = tile_y * this.tile_height;
|
|
||||||
|
|
||||||
var t1 = this.GetTileOrigin(tile_x, tile_y);
|
|
||||||
var t2 = t1.Add(new RadiumEngine.Point(this.tile_width / 2, this.tile_height / 2));
|
|
||||||
var t3 = t1.Add(new RadiumEngine.Point(0, this.tile_height));
|
|
||||||
var t4 = t1.Add(new RadiumEngine.Point(0 - (this.tile_width / 2), this.tile_height / 2));
|
|
||||||
|
|
||||||
this.context.beginPath();
|
|
||||||
|
|
||||||
this.context.moveTo(t1.x, t1.y);
|
|
||||||
this.context.lineTo(t2.x, t2.y);
|
|
||||||
this.context.lineTo(t3.x, t3.y);
|
|
||||||
this.context.lineTo(t4.x, t4.y);
|
|
||||||
this.context.lineTo(t1.x, t1.y);
|
|
||||||
|
|
||||||
switch(tile_y)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
this.context.lineWidth = 1;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
this.context.lineWidth = 2;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
this.context.lineWidth = 3;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
this.context.lineWidth = 4;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
this.context.lineWidth = 5;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
this.context.lineWidth = 6;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(tile_x)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
this.context.strokeStyle = "blue";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
this.context.strokeStyle = "purple";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
this.context.strokeStyle = "green";
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
this.context.strokeStyle = "red";
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
this.context.strokeStyle = "maroon";
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
this.context.strokeStyle = "black";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.mouse_tile !== undefined && tile_x == this.mouse_tile.x && tile_y == this.mouse_tile.y)
|
|
||||||
{
|
|
||||||
this.context.fillStyle = "#D9FFB4";
|
|
||||||
this.context.fill();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.context.stroke();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.GetBasePoint = function()
|
|
||||||
{
|
|
||||||
return new RadiumEngine.Point((this.width * this.tile_width) / 2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.GetTileOrigin = function(tile_x, tile_y)
|
|
||||||
{
|
|
||||||
/* Determine base point (0,0) of the isometric diamond. */
|
|
||||||
base_point = this.GetBasePoint();
|
|
||||||
|
|
||||||
/* Determine offset for determining starting point for the current row (tile_y coordinate). */
|
|
||||||
row_offset = new RadiumEngine.Point(0 - ((this.tile_width / 2) * tile_y), (this.tile_height / 2) * tile_y);
|
|
||||||
|
|
||||||
/* Determine specific offset of the specified tile_x coordinate on the tile_y row. */
|
|
||||||
tile_offset = new RadiumEngine.Point((this.tile_width / 2) * tile_x, (this.tile_height / 2) * tile_x);
|
|
||||||
|
|
||||||
/* Return the sum of the above to determine the actual tile position on the canvas. */
|
|
||||||
return base_point.Add(row_offset, tile_offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.GetTilePosition = function(tile_x, tile_y)
|
|
||||||
{
|
|
||||||
origin = this.GetTileOrigin(tile_x, tile_y);
|
|
||||||
|
|
||||||
return origin.Add(new RadiumEngine.Point(0 - (this.tile_width / 2), 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.GetRangePosition = function(start, size)
|
|
||||||
{
|
|
||||||
x = this.GetTilePosition(start.x, start.y + size.y - 1).x;
|
|
||||||
y = this.GetTilePosition(start.x, start.y).y;
|
|
||||||
|
|
||||||
return new RadiumEngine.Point(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.TileFromPosition = function(x, y)
|
|
||||||
{
|
|
||||||
p = new RadiumEngine.Point(x, y);
|
|
||||||
a = self.GetBasePoint();
|
|
||||||
b = a.Add(new RadiumEngine.Point(0 - (this.tile_width / 2), this.tile_height / 2));
|
|
||||||
c = a.Add(new RadiumEngine.Point(this.tile_width / 2, this.tile_height / 2));
|
|
||||||
|
|
||||||
/* Compute vectors. */
|
|
||||||
v0 = c.Subtract(a);
|
|
||||||
v1 = b.Subtract(a);
|
|
||||||
v2 = p.Subtract(a);
|
|
||||||
|
|
||||||
/* Compute dot products. */
|
|
||||||
dot00 = RadiumEngine.dot_product([v0.x, v0.y], [v0.x, v0.y]);
|
|
||||||
dot01 = RadiumEngine.dot_product([v0.x, v0.y], [v1.x, v1.y]);
|
|
||||||
dot02 = RadiumEngine.dot_product([v0.x, v0.y], [v2.x, v2.y]);
|
|
||||||
dot11 = RadiumEngine.dot_product([v1.x, v1.y], [v1.x, v1.y]);
|
|
||||||
dot12 = RadiumEngine.dot_product([v1.x, v1.y], [v2.x, v2.y]);
|
|
||||||
|
|
||||||
/* Compute tile. */
|
|
||||||
inv_denom = 1 / (dot00 * dot11 - dot01 * dot01);
|
|
||||||
tile_x = (dot11 * dot02 - dot01 * dot12) * inv_denom;
|
|
||||||
tile_y = (dot00 * dot12 - dot01 * dot02) * inv_denom;
|
|
||||||
|
|
||||||
return new RadiumEngine.Point(Math.floor(tile_x), Math.floor(tile_y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue