Difference between revisions of "Oolite JavaScript Reference: Oolite"

From Elite Wiki
(Updating BB links)
 
(20 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 
<small>'''Prototype:''' <code>Object</code></small><br />
 
<small>'''Prototype:''' <code>Object</code></small><br />
<small>'''Subtypes:''' none
+
<small>'''Subtypes:''' none</small>
 
 
{{Oolite-class-added|1.70}}
 
  
 
The '''<code>Oolite</code>''' class represents Oolite itself. It allows scripts to access information about the application. There is a global instance of <code>Oolite</code>, named <code>oolite</code>.
 
The '''<code>Oolite</code>''' class represents Oolite itself. It allows scripts to access information about the application. There is a global instance of <code>Oolite</code>, named <code>oolite</code>.
  
 
== Properties ==
 
== Properties ==
 +
=== <code>gameSettings</code> ===
 +
'''gameSettings''' : Object(read-only)
 +
This property allows an [[OXP]] to detect various game settings. It has the following read-only properties:
 +
 +
autosave : Boolean
 +
gameWindow : Object (see below)
 +
keyConfig : Object (from v1.77.1 onwards, see below)
 +
musicMode : String ("MUSIC_OFF", "MUSIC_ON", or "MUSIC_ITUNES")
 +
procedurallyTexturedPlanets : Boolean
 +
reducedDetailGraphics : Boolean
 +
detailLevel : String ("DETAIL_LEVEL_MINIMUM", "DETAIL_LEVEL_NORMAL", "DETAIL_LEVEL_SHADERS", or "DETAIL_LEVEL_EXTRAS")
 +
speechOn : Boolean
 +
wireframeGraphics : Boolean
 +
 +
Before 1.80, there was no <code>detailLevel</code> property, but there was a <code>shaderEffectsLevel</code> property.
 +
 +
The <code>gameWindow</code> property contains the following properties:
 +
height : Number
 +
width : Number
 +
fullScreen : Boolean
 +
 +
The <code>keyConfig</code> property contains numeric (decimal) KeyCode values of all Keyconfig Entries in oolite.app/Resources/Config/keyconfig.plist. Keyconfig Entry - KeyCode pairs are documented in ''[[Oolite_Keyboard_Controls]]''.
 +
 +
You can use the standard Javascript <code>String.fromCharCode()</code> method to convert KeyCode to a string:
 +
var button = String.fromCharCode( oolite.gameSettings.keyConfig.key_ident_system );
 +
player.consoleMessage( "Press " + button + " to turn on the ident system." );
 +
 +
Keys like tab, escape, arrow keys, etc. need to be handled separately.
 +
 
=== <code>jsVersion</code> ===
 
=== <code>jsVersion</code> ===
 
  '''jsVersion''' : Number (read-only)
 
  '''jsVersion''' : Number (read-only)
The version of the JavaScript language implemented by this version of Oolite, multiplied by 100, as an integer. For instance, for [http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7 JavaScript 1.7] (expected to be used in Oolite 1.70), this will be equal to <code>170</code>.
+
The version of the JavaScript language implemented by this version of Oolite, multiplied by 100, as an integer. For instance, for [http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7 JavaScript 1.7] (used in Oolite 1.74), this will be equal to <code>170</code>.
  
=== <code>jsVersion</code> ===
+
=== <code>jsVersionString</code> ===
 
  '''jsVersionString''' : String (read-only)
 
  '''jsVersionString''' : String (read-only)
 
The version of the JavaScript language implemented by this version of Oolite, as a string. For instance, for JavaScript 1.7, this will be equal to <code>"1.7"</code>.
 
The version of the JavaScript language implemented by this version of Oolite, as a string. For instance, for JavaScript 1.7, this will be equal to <code>"1.7"</code>.
 +
 +
=== <code>resourcePaths</code> ===
 +
{{oolite-method-added|1.83}}
 +
'''resourcePaths''' : Array (read-only)
 +
Contain full path of loaded config files and expansion packs, including all .oxp folders and .oxz files.
  
 
=== <code>version</code> ===
 
=== <code>version</code> ===
 
  '''version''' : Array (read-only)
 
  '''version''' : Array (read-only)
The version of Oolite, as an array of version components. For instance, for Oolite 1.70 this will be equal to <code>[1, 70]</code>. For a hypothetical version 1.70.1, it will be equal to <code>[1, 70, 1]</code>.
+
The version of Oolite, as an array of version components. For instance, for Oolite 1.74 this is <code>[1, 74]</code>. For version 1.73.4, it is <code>[1, 73, 4]</code>.
  
 +
=== <code>versionString</code> ===
 
  '''versionString''' : String (read-only)
 
  '''versionString''' : String (read-only)
The version of Oolite, as a string. For instance, for Oolite 1.70 this will be equal to <code>"1.70"</code>. For a hypothetical version 1.70.1, it will be equal to <code>"1.70.1"</code>.
+
The version of Oolite, as a string. For instance, for Oolite 1.74 this is <code>"1.74"</code>. For version 1.73.4, it is <code>"1.73.4"</code>.
  
  
 
== Methods ==
 
== Methods ==
=== compareVersion  ===
+
=== <code>compareVersion</code> ===
  <code>'''compareVersion'''(versionSpec) : Number
+
  function '''compareVersion'''(versionSpec) : Number
Compare the version of Oolite to <code>versionSpec</code>, which may be either a string or an array (in the format given by <code>[[#version|version]]</code>). If the current version of Oolite is less than <code>versionSpec</code>, -1 is returned. If the current version of Oolite is greater than <code>versionSpec</code>, 1 is returned. If they are equal, 0 is returned. Example:
+
Compare the version of Oolite to <code>versionSpec</code>, which may be either a string or an array (in the format given by <code>[[#version|version]]</code>). If the current version of Oolite is less than <code>versionSpec</code>, 1 is returned. If the current version of Oolite is greater than <code>versionSpec</code>, -1 is returned. If they are equal, 0 is returned. Example:
  if (oolite.compareVersion("1.80") < 0)
+
  if (0 < oolite.compareVersion("1.80"))
 
  {
 
  {
 
     // Oolite version is older than 1.80.
 
     // Oolite version is older than 1.80.
     Log("An old version of Oolite (" + oolite.versionString + ") is in use. Some features of SuperDuperOXP will not be available.")
+
     log(this.name, "An old version of Oolite (" + oolite.versionString + ") is in use. Some features of SuperDuperOXP will not be available.")
 
  }
 
  }
 
  else
 
  else
Line 36: Line 69:
 
     // Enable advanced features here.
 
     // Enable advanced features here.
 
  }
 
  }
 +
 +
[[Category:Oolite JavaScript Reference]]
 +
 +
== Radical changes (new galaxies ''etc'') ==
 +
[[User:Cim|Cim]] talks [https://bb.oolite.space/viewtopic.php?f=4&t=17603 here] about doing this sort of thing.

Latest revision as of 02:19, 29 February 2024

Prototype: Object
Subtypes: none

The Oolite class represents Oolite itself. It allows scripts to access information about the application. There is a global instance of Oolite, named oolite.

Properties

gameSettings

gameSettings : Object(read-only)

This property allows an OXP to detect various game settings. It has the following read-only properties:

autosave : Boolean
gameWindow : Object (see below)
keyConfig : Object (from v1.77.1 onwards, see below)
musicMode : String ("MUSIC_OFF", "MUSIC_ON", or "MUSIC_ITUNES")
procedurallyTexturedPlanets : Boolean
reducedDetailGraphics : Boolean
detailLevel : String ("DETAIL_LEVEL_MINIMUM", "DETAIL_LEVEL_NORMAL", "DETAIL_LEVEL_SHADERS", or "DETAIL_LEVEL_EXTRAS")
speechOn : Boolean
wireframeGraphics : Boolean

Before 1.80, there was no detailLevel property, but there was a shaderEffectsLevel property.

The gameWindow property contains the following properties:

height : Number
width : Number
fullScreen : Boolean

The keyConfig property contains numeric (decimal) KeyCode values of all Keyconfig Entries in oolite.app/Resources/Config/keyconfig.plist. Keyconfig Entry - KeyCode pairs are documented in Oolite_Keyboard_Controls.

You can use the standard Javascript String.fromCharCode() method to convert KeyCode to a string:

var button = String.fromCharCode( oolite.gameSettings.keyConfig.key_ident_system );
player.consoleMessage( "Press " + button + " to turn on the ident system." );

Keys like tab, escape, arrow keys, etc. need to be handled separately.

jsVersion

jsVersion : Number (read-only)

The version of the JavaScript language implemented by this version of Oolite, multiplied by 100, as an integer. For instance, for JavaScript 1.7 (used in Oolite 1.74), this will be equal to 170.

jsVersionString

jsVersionString : String (read-only)

The version of the JavaScript language implemented by this version of Oolite, as a string. For instance, for JavaScript 1.7, this will be equal to "1.7".

resourcePaths

This method was added in Oolite test release 1.83.

resourcePaths : Array (read-only)

Contain full path of loaded config files and expansion packs, including all .oxp folders and .oxz files.

version

version : Array (read-only)

The version of Oolite, as an array of version components. For instance, for Oolite 1.74 this is [1, 74]. For version 1.73.4, it is [1, 73, 4].

versionString

versionString : String (read-only)

The version of Oolite, as a string. For instance, for Oolite 1.74 this is "1.74". For version 1.73.4, it is "1.73.4".


Methods

compareVersion

function compareVersion(versionSpec) : Number

Compare the version of Oolite to versionSpec, which may be either a string or an array (in the format given by version). If the current version of Oolite is less than versionSpec, 1 is returned. If the current version of Oolite is greater than versionSpec, -1 is returned. If they are equal, 0 is returned. Example:

if (0 < oolite.compareVersion("1.80"))
{
    // Oolite version is older than 1.80.
    log(this.name, "An old version of Oolite (" + oolite.versionString + ") is in use. Some features of SuperDuperOXP will not be available.")
}
else
{
    // Enable advanced features here.
}

Radical changes (new galaxies etc)

Cim talks here about doing this sort of thing.