1
0
forked from 0ad/0ad
0ad/binaries/data/mods/official/gui/test/functions_utility.js
Acumen 4ab25c7274 * Fixed the "can't interact with the world" glitch. Turns out it was my fault. :)
* Restored the resource pool (and cleaned up the JS interface to it ...
array and counters are updated in one spot (wrapper functions to
add/deduct/define), without need for constant refresh).
* Added crude boxes in game setup to enter initial resource value.
* The command buttons still don't work when clicked (and clicking
continues to be erratic, only triggering if hammering the mouse button
... I think it's related to the return function() hack Philip set up),
but that's next on the list. :)
* Oh, and the command buttons don't currently realign to the different
corners with Alt+G, but all the rest should.

This was SVN commit r2715.
2005-09-14 00:50:25 +00:00

78 lines
2.5 KiB
JavaScript
Executable File

/*
DESCRIPTION : Generic utility functions.
NOTES :
*/
// ====================================================================
function getRandom(randomMin, randomMax)
{
// Returns a random whole number in a min..max range.
// NOTE: There should probably be an engine function for this,
// since we'd need to keep track of random seeds for replays.
randomNum = randomMin + (randomMax-randomMin)*Math.random(); // num is random, from A to B
return Math.round(randomNum);
}
// ====================================================================
function parseDelimiterString (parseString, Delimiter)
{
// Seeks through the delimiters in a string and populates the elements of an array with fields found between them.
// Declare local variables.
parseLoop = 0;
parseElement = 0;
seekDelimiter = 0;
parseArray = new Array();
// While we're still within the bounds of the string,
while (parseLoop <= parseString.length)
{
// Seek until we find a delimiter.
seekDelimiter = parseLoop;
while (parseString[seekDelimiter] != Delimiter && seekDelimiter <= parseString.length)
seekDelimiter++;
// If we found a delimiter within the string,
if (seekDelimiter != parseString.length)
{
// Store sub-string between start point and delimiter in array element.
parseArray[parseElement] = parseString.substring(parseLoop, seekDelimiter);
parseElement++;
}
// Move to after delimiter position for next seek.
parseLoop = seekDelimiter+1;
}
// Store length of array.
parseArray.length = parseElement;
return parseArray;
}
// ====================================================================
function addArrayElement(Array)
{
// Adds an element to an array, updates its given index, and returns the index of the element.
Array[Array.last] = new Object();
Array.last++;
return (Array.last - 1);
}
// ====================================================================
function toTitleCase (string)
{
// Returns the title-case version of a given string.
string = string.substring(0,1).toUpperCase() + string.substring(1, string.length).toLowerCase();
return (string);
}
// ====================================================================