Back to Index Page generated: May 8, 2024, 6:16:03 AM

Expansion System Data Config

Content

Warnings

  1. License not specified
  2. Information URL mismatch between OXP Manifest and Expansion Manager string length at character position 0

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Allows OXP configuration of the layout of the System Data (F7) screen Allows OXP configuration of the layout of the System Data (F7) screen
Identifier oolite.oxp.phkb.SystemDataConfig oolite.oxp.phkb.SystemDataConfig
Title System Data Config System Data Config
Category Miscellaneous Miscellaneous
Author phkb phkb
Version 1.0 1.0
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL n/a
Download URL https://wiki.alioth.net/img_auth.php/5/58/SystemDataConfig.oxz n/a
License
File Size n/a
Upload date 1691383706

Documentation

Also read http://wiki.alioth.net/index.php/System%20Data%20Config

readme.txt

System Data Config
By Nick Rogers

Overview
========
This OXP is designed to help OXP authors make use of the upper part of the F7 screen, where the statistics about the currently selected system are displayed.

A new feature added in Oolite v1.85/6 allows the layout of the F7 screen to be completely customised. However, given the number of OXP's that will want to make use of this extra space, there was a need to make the process of adding information to the screen a little more democratic. This OXP aims to provide an centralised interface OXP's can use to make the most of this new feature.

Methodology
===========
This OXP offers the following interfaces to OXP's:

systemDataLineOwner(linenumber)
-------------------------------
Returns the current owner of a particular data line.

systemDataLineText(lineNumber)
------------------------------
Returns the current text of a particular data line.

setSystemDataLine(linenumber, text [, owner]) 
--------------------------------------------
Sets the text, and optionally the owner, of a particular data line

resetSystemDataLine(linenumber)
-------------------------------
Resets the text and owner of a particular data line to be blank.

addChangeCallback(worldScriptName, callbackFunctionName)
--------------------------------------------------------
In order for an OXP to make changes to the F7 screen before it's displayed, two events must be used: guiScreenWillChange (monitoring for when the guiScreen is about to be GUI_SCREEN_SYSTEM_DATA), and infoSystemWillChange. However, because the order in which these events are fired for each OXP is hard to determine, it's quite possible for an OXP's events to be fired after the events within this OXP, which means that updated data might not be displayed.

To work around this issue, OXP's can register a callback function using this call. Then, when those events are triggered for this OXP's, all the callbacks will be executed before the data is displayed, ensuring that the correct data is shown on the screen.

removeChangeCallback(worldScriptName, callbackFunctionName)
-----------------------------------------------------------
This function removes a worldscript/callback function name from the list of callbacks.

License
=======
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 4.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/

Version History
===============
1.0
- Made compatible with "SW Economy".

0.9
- Fixed issue with formatting distance text when there is no route from the source to target destinations.

0.8
- Corrections to manifest.plist file.

0.7
- Fixed issue with distance to unreachable systems sometimes having too many decimal places.

0.6
- Fixed issue with incorrect TL being shown for systems.

0.5
- Added some documentation and a readme.txt file.

0.4
- Initial public release

Equipment

This expansion declares no equipment. This may be related to warnings.

Ships

This expansion declares no ships. This may be related to warnings.

Models

This expansion declares no models. This may be related to warnings.

Scripts

Path
Scripts/oolite-system-data-config.js
"use strict";
this.name        = "oolite-system-data-config";
this.author      = "phkb";
this.copyright   = "2017 phkb";
this.description = "Provides an interface for configuring the layout of the System Data (F7) screen.";
this.licence     = "CC BY-NC-SA 3.0";

// set up our configuration dictionary with the default settings
this._config = {
    1: {owner:"system", text:"[sysdata-eco]\t[economy_desc]"},
    2: {owner:"", text:""},
    3: {owner:"system", text:"[sysdata-govt]\t[government_desc]"},
    4: {owner:"", text:""},
    5: {owner:"system", text:"[sysdata-tl]\t[sysdata-tl-value]"},
    6: {owner:"", text:""},
    7: {owner:"system", text:"[sysdata-pop]\t[sysdata-pop-value]"},
    8: {owner:"system", text:"\t([inhabitants])"},
    9: {owner:"", text:""},
    10: {owner:"system", text:"[sysdata-prod]\t\t[sysdata-prod-value]"},
    11: {owner:"", text:""},
    12: {owner:"system", text:"[sysdata-radius]\t\t[sysdata-radius-value]"},
    13: {owner:"", text:""},
    14: {owner:"system", text:"[sysdata-distance]\t[distanceInfo]"},
    15: {owner:"", text:""},
    16: {owner:"", text:""},
};

this._governmentList = ["Anarchy","Feudal","Multi-Government","Dictatorship","Communist","Confederacy",
    "Democracy","Corporate State"];
this._economyList = ["Rich Industrial","Average Industrial","Poor Industrial","Mainly Industrial",
    "Mainly Agricultural","Rich Agricultural","Average Agricultural","Poor Agricultural"];

this._callbacks = [];

//-------------------------------------------------------------------------------------------------------------
this.startUp = function() {
    if (worldScripts["market_tweak.js"]) {
        this._economyList = ["Extreme Industrial","Strong Industrial","Common Industrial","Mainly Industrial","Mainly Agricultural","Common Agricultural","Strong Agricultural","Extreme Agricultural"];
    }
    this.$updateData();
}

//-------------------------------------------------------------------------------------------------------------
this.guiScreenWillChange = function(to, from) {
    if (to === "GUI_SCREEN_SYSTEM_DATA") {
        this.$performCallbacks("guiScreenWillChange", to, from);
        this.$updateData();
    }
}

//-------------------------------------------------------------------------------------------------------------
this.infoSystemWillChange = function(to, from) {
    this.$performCallbacks("infoSystemWillChange", to, from);
    this.$updateData();
}

//-------------------------------------------------------------------------------------------------------------
// returns the current owner of a particular data line
this.systemDataLineOwner = function(ln) {
    if (isNaN(ln) || ln < 1 || ln > 16) {
        throw "Invalid line number specified: " + ln + " - must be number between 1 and 16";
    }
    return this._config[ln].owner;
}

//-------------------------------------------------------------------------------------------------------------
// returns the current text of a particular data line
this.systemDataLineText = function(ln) {
    if (isNaN(ln) || ln < 1 || ln > 16) {
        throw "Invalid line number specified: " + ln + " - must be number between 1 and 16";
    }
    return this._config[ln].text;
}

//-------------------------------------------------------------------------------------------------------------
// sets the text and optionally the owner of a particular data line
this.setSystemDataLine = function(ln, text, owner) {
    if (isNaN(ln) || ln < 1 || ln > 16) {
        throw "Invalid line number specified: " + ln + " - must be number between 1 and 16";
    }
    if (owner) {
        // if we've been passed an owner, update the whole entry
        this._config[ln] = {owner:owner, text:text};
    } else {
        // otherwise just update the text element
        this._config[ln].text = text;
    }
    this.$updateData(ln);
}

//-------------------------------------------------------------------------------------------------------------
// resets a particular data line to being blank with no owner
this.resetSystemDataLine = function(ln) {
    if (isNaN(ln) || ln < 1 || ln > 16) {
        throw "Invalid line number specified: " + ln + " - must be number between 1 and 16";
    }
    this._config[ln] = {owner:"", text:""};
    this.$updateData(ln);
}

//-------------------------------------------------------------------------------------------------------------
// adds a worldscript/callback function name to the list of callbacks to execute whenever the information
// on the F7 screen is about to change
this.addChangeCallback = function(ws, cb) {
    var found = false;
    if (this._callbacks.length > 0) {
        for (var i = 0; i < this._callbacks.length; i++) {
            if (this._callbacks[i].worldScript === ws && this._callbacks[i].callback === cb) {
                found = true;
                break;
            }
        }
    }
    if (found === false) {
        this._callbacks.push({worldScript:ws, callback:cb});
    }
}

//-------------------------------------------------------------------------------------------------------------
// removes a worldscript/callback function name from the list of callbacks
this.removeChangeCallback = function(ws, cb) {
    for (var i = this._callbacks.length - 1; i >= 0; i--) {
        if (this._callbacks[i].worldScript === ws && this._callbacks[i].callback === cb) {
            this._callbacks.splice(i, 1);
            break;
        }
    }
}

//-------------------------------------------------------------------------------------------------------------
// executes all the callbacks
this.$performCallbacks = function(c_type, to, from) {
    if (this._callbacks.length > 0) {
        for (var i = 0; i < this._callbacks.length; i++) {
            worldScripts[this._callbacks[i].worldScript][this._callbacks[i].callback](c_type, to, from);
        }
    }
}

//-------------------------------------------------------------------------------------------------------------
// updats the data for all lines (if no line number is passed) or for a specific line
this.$updateData = function(ln) {
    // if we've been passed a line number, just update that line
    var data = this.$getSystemData(player.ship.infoSystem);
    if (ln) {
        missionVariables["oolite_sysdata_line_" + ln] = expandDescription(this._config[ln].text, data);
        return;
    }
    // otherwise update all the lines with the latest config
    for (var i = 1; i <= 16; i++) {
        missionVariables["oolite_sysdata_line_" + i] = expandDescription(this._config[i].text, data);
    }
}

//-------------------------------------------------------------------------------------------------------------
// returns a dictionary object containing the details of a particular system
this.$getSystemData = function(sysID) {
    var sys = System.infoForSystem(galaxyNumber, sysID);
    var rt = system.info.routeToSystem(sys, player.ship.routeMode);
    var data = {};
    if (sys.sun_gone_nova) {
        data["economy_desc"] = expandDescription("[nova-system-economy]");
        data["government_desc"] = expandDescription("[nova-system-government]");
        data["sysdata-tl-value"] = 0;
        data["population"] = 0;
        data["inhabitants"] = expandDescription("[nova-system-inhabitants]");
        data["productivity"] = 0;
        data["radius"] = 0;
    } else {
        data["economy_desc"] = this._economyList[sys.economy];
        data["government_desc"] = this._governmentList[sys.government];
        data["sysdata-tl-value"] = sys.techlevel + 1;
        data["population"] = sys.population;
        data["inhabitants"] = sys.inhabitants;
        data["productivity"] = sys.productivity;
        data["radius"] = sys.radius;
    } 
    if (rt) {
        data["distanceInfo"] = rt.distance.toFixed(1) + " ly / " + 
            rt.time.toFixed(1) + " " + (rt.time > 0.95 && rt.time < 1.05 ? expandDescription("[sysdata-route-hours%0]") : expandDescription("[sysdata-route-hours%1]"))  + " / " + 
            (rt.route.length - 1) + " " + (rt.route.length === 2 ? expandDescription("[sysdata-route-jumps%0]") : expandDescription("[sysdata-route-jumps%1]"));
    } else {
        data["distanceInfo"] = system.info.distanceToSystem(sys).toFixed(1) + " ly";
    }
    return data;
}