Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/source/addons/OrbitalScience.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Most of the time Orbital Science experiments should work exactly like stock ones
they inherit all suffixes from :ref:`ScienceExperimentModule <scienceexperimentmodule>`::

SET P TO SHIP:PARTSTAGGED("")[0].
SET M TO P:GETMODULE("dmmodulescienceanimate").
SET M TO P:MODULES:dmmodulescienceanimate.

PRINT M:RERUNNABLE.
PRINT M:INOPERABLE.
Expand All @@ -26,15 +26,15 @@ deactivates them::


SET P TO SHIP:PARTSTAGGED("collector")[0].
SET M TO P:GETMODULE("dmsolarcollector").
SET M TO P:MODULES:dmsolarcollector.

M:TOGGLE.

`Submersible Oceanography and Bathymetry` has two extra suffixes that turn the experiment's
lights on and off::

SET P TO SHIP:PARTSTAGGED("bathymetry")[0].
SET M TO P:GETMODULE("dmbathymetry").
SET M TO P:MODULES:dmbathymetry.

M:LIGHTSON.
WAIT 3.
Expand Down
2 changes: 1 addition & 1 deletion doc/source/addons/RemoteTech.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Antennas
It is possible to activate/deactivate RT antennas, as well as set their targets using kOS::

SET P TO SHIP:PARTSNAMED("mediumDishAntenna")[0].
SET M to p:GETMODULE("ModuleRTAntenna").
SET M to p:MODULES:ModuleRTAntenna.
M:DOEVENT("activate").
M:SETFIELD("target", "Mission Control").
M:SETFIELD("target", mun).
Expand Down
6 changes: 3 additions & 3 deletions doc/source/general/parts_and_partmodules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Examples::

// Change the altitude at which all the drogue chutes will deploy:
FOR somechute IN somevessel:PARTSNAMED("parachuteDrogue") {
somechute:GETMODULE("ModuleParachute"):SETFIELD("DEPLOYALTITUDE", 1500).
somechute:MODULES:ModuleParachute:SETFIELD("DEPLOYALTITUDE", 1500).
}.

Pattern matching
Expand Down Expand Up @@ -217,14 +217,14 @@ B: **Use the :MODULES suffix of Part:** If you have a handle on any part in kOS,
LOG P:MODULES TO MODLIST.
}.

Do that, and the file MODLIST should now contain a verbose dump of all the module names of all the parts on your ship. You can get any of the modules now by using Part:GETMODULE("module name").
Do that, and the file MODLIST should now contain a verbose dump of all the module names of all the parts on your ship. You can get any of the modules now by using Part:MODULES:ModuleName.

What are the names of the stuff that a PartModule can do?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These three suffixes tell you everything a part module can do::

SET MOD TO P:GETMODULE("some name here").
SET MOD TO P:MODULE:SomeModuleName.
LOG ("These are all the things that I can currently USE GETFIELD AND SETFIELD ON IN " + MOD:NAME + ":") TO NAMELIST.
LOG MOD:ALLFIELDS TO NAMELIST.
LOG ("These are all the things that I can currently USE DOEVENT ON IN " + MOD:NAME + ":") TO NAMELIST.
Expand Down
11 changes: 11 additions & 0 deletions doc/source/structures/misc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Configuration of kOS
- :struct:`Boolean`
- False
- If true, kOS's controls do nothing.
* - :attr:`DEPRECATEDWARNINGS`
- :struct:`Boolean`
- True
- If true, warnings will be printed when using deprecated globals, suffixes or functions.
* - :attr:`TELNET`
- :struct:`Boolean`
- False
Expand Down Expand Up @@ -273,6 +277,13 @@ Configuration of kOS
While it does suppress steering, throttle, and translation, it cannot
suppress action groups or staging.

.. attribute:: Config:DEPRECATEDWARNINGS

:access: Get/Set
:type: :struct:`Boolean`

If true, warnings will be printed when using deprecated globals, suffixes or functions.

.. attribute:: Config:TELNET

:access: Get/Set
Expand Down
86 changes: 37 additions & 49 deletions doc/source/structures/vessels/part.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,9 @@ These are the generic properties every PART has. You can obtain a list of values
* - :attr:`SHIP`
- :struct:`Vessel`
- the vessel that contains this part
* - :meth:`GETMODULE(name)`
- :struct:`PartModule`
- Get one of the :struct:`PartModules <PartModule>` by name
* - :meth:`GETMODULEBYINDEX(index)`
- :struct:`PartModule`
- Get one of the :struct:`PartModules <PartModule>` by index
* - :attr:`MODULES`
- :struct:`List`
- Names (:struct:`String`) of all :struct:`PartModules <PartModule>`
* - :attr:`ALLMODULES`
- :struct:`List`
- Same as :attr:`MODULES`
* - :meth:`HASMODULE(name)`
- :struct:`Boolean`
- True if the part has the named module in it, false if not.
- :struct:`ModuleLexicon`
- Special :struct:`ModuleLexicon` structure for getting modules.
* - :attr:`PARENT`
- :struct:`Part`
- Adjacent :struct:`Part` on this :struct:`Vessel`.
Expand Down Expand Up @@ -319,54 +307,54 @@ These are the generic properties every PART has. You can obtain a list of values

the vessel that contains this part.

.. method:: Part:GETMODULE(name)
.. attribute:: Part:MODULES

:access: Get only
:type: :struct:`ModuleLexicon`

.. structure:: ModuleLexicon

.. list-table:: Members
:header-rows: 1
:widths: 1 1 4

:parameter name: (:struct:`String`) Name of the part module
:returns: :struct:`PartModule`
* - Suffix
- Type
- Description

Get one of the :struct:`PartModules <PartModule>` attached to this part, given the name of the module. (See :attr:`Part:MODULES` for a list of all the names available).

.. method:: Part:GETMODULEBYINDEX(index)
* - :attr:`PART`
- :struct:`Part`
- The part this ModuleLexicon gets modules from
* - :attr:`KEYS`
- :struct:`List` of strings
- List of module names
* - :meth:`HASKEY(key)`
- :struct:`Boolean`
- Does the part have a module with this name
* - :attr:`LENGTH`
- :struct:`Scalar`
- Number of modules on a part

:parameter index: (:struct:`Scalar`) Index number of the part module
:returns: :struct:`PartModule`
Structure for getting :struct:`PartModules <PartModule>` from a part with a name or an index. To get a module by its name use the suffix syntax with the module name(the leading "Module" string in the name is optional). Example::

Get one of the :struct:`PartModules <PartModule>` attached to this part,
given the index number of the module. You can use :attr:`Part:MODULES` for a
list of names of all modules on the part. The indexes are not guaranteed to
always be in the same order. It is recommended to iterate over the indexes
with a loop and verify the module name::
print part:modules.
ModuleLexicon, containing keys:
[0] ModuleCommand
[1] ModuleReactionWheel
set command to part:modules:command.
set reactionwheel to part:modules[1].

local moduleNames is part:modules.
The indexes are not guaranteed to always be in the same order. It is recommended to iterate over the indexes with a loop and verify the module name::

local moduleNames is part:modules:keys.
for idx in range(0, moduleNames:length) {
if moduleNames[idx] = "test module" {
local pm is part:getmodulebyindex(idx).
DoSomething(pm).
}
}


.. attribute:: Part:MODULES

:access: Get only
:type: :struct:`List` of strings

list of the names of :struct:`PartModules <PartModule>` enabled for this part.

.. attribute:: Part:ALLMODULES

Same as :attr:`Part:MODULES`

.. method:: Part:HASMODULE(name)

:parameter name: (:struct:`String`) The name of the module to check for
:returns: :struct:`Boolean`

Checks to see if this part contains the :struct:`PartModule` with the name
given. If it does, this returns true, else it returns false. (If
``HASMODULE(name)`` returns false, then this means an attempt to use
``GETMODULE(name)`` would fail with an error.)

.. attribute:: Part:PARENT

:access: Get only
Expand Down
4 changes: 2 additions & 2 deletions doc/source/structures/vessels/scienceexperiment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Some of the science-related tasks are normally not available to kOS scripts. It
example possible to deploy a science experiment::

SET P TO SHIP:PARTSNAMED("GooExperiment")[1].
SET M TO P:GETMODULE("ModuleScienceExperiment").
SET M TO P:MODULES:ModuleScienceExperiment.
M:DOEVENT("observe mystery goo").

However, this results in a dialog being shown to the user. Only from that dialog it is possible
Expand All @@ -18,7 +18,7 @@ to reset the experiment or transmit the experiment results back to Kerbin.
to perform all science-related tasks without any manual intervention::

SET P TO SHIP:PARTSNAMED("GooExperiment")[0].
SET M TO P:GETMODULE("ModuleScienceExperiment").
SET M TO P:MODULES:ModuleScienceExperiment.
M:DEPLOY.
WAIT UNTIL M:HASDATA.
M:TRANSMIT.
Expand Down
13 changes: 13 additions & 0 deletions src/kOS.Safe.Test/Execution/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ public bool SuppressAutopilot
{
}
}

public bool DeprecatedWarnings
{
get
{
return true;
}

set
{
}
}

public DateTime TimeStamp
{
get
Expand Down
1 change: 1 addition & 0 deletions src/kOS.Safe/Encapsulation/IConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface IConfig: ISuffixed
int TerminalDefaultHeight { get; set; }
bool AllowClobberBuiltIns { get; set; }
bool SuppressAutopilot { get; set; }
bool DeprecatedWarnings { get; set; }


/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions src/kOS.Safe/Encapsulation/VersionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using kOS.Safe.Encapsulation.Suffixes;

namespace kOS.Safe.Encapsulation
Expand All @@ -9,7 +10,23 @@ public class VersionInfo : Structure
private readonly int minor;
private readonly int patch;
private readonly int build;
public Version SystemVersion => new Version(major, minor, patch, build);

public VersionInfo(Version version)
{
// NOTICE: there is a clash of nomenclature here. C# calls the
// 3rd number "BUILD" and the 4th number "Revision" while the AVC mod
// (and presumably CKAN) calls the 3rd number "PATCH" and the 4th number "BUILD".
// We'll be using the AVC terminology in kerboscript, thus why this next line
// passes in "ver.Revision" where the VersionInfo's "BUILD" goes, and the
// "ver.Build" where VersionInfo's "PATCH" goes:
major = version.Major;
minor = version.Minor;
patch = version.Build;
build = version.Revision;
VersionInitializeSuffixes();
}

public VersionInfo(int major, int minor, int patch, int build)
{
this.major = major;
Expand Down
25 changes: 25 additions & 0 deletions src/kOS.Safe/Utilities/DeprecationHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using kOS.Safe.Encapsulation;
using kOS.Safe.Exceptions;

namespace kOS.Safe.Utilities
{
public static class DeprecationHandler
{
private const string DeprecationMessage =
"WARNING: Usage of {0} is being deprecated.\nUse {1} instead.\n"+
"At kOS version {2} this usage will be removed.\n"+
"To disable these warnings do \"config:deprecatedwarnings off.\"";

public static void DeprecatedUsage(SafeSharedObjects shared, string oldUsage, string newUsage, VersionInfo completeDeprecationVersion)
{
if (SafeHouse.Version.SystemVersion >= completeDeprecationVersion.SystemVersion)
{
throw new KOSObsoletionException(completeDeprecationVersion.ToString(), oldUsage, newUsage, null);
}
if (SafeHouse.Config.DeprecatedWarnings)
{
shared.Screen.Print(string.Format(DeprecationMessage, oldUsage, newUsage, completeDeprecationVersion), true);
}
}
}
}
8 changes: 1 addition & 7 deletions src/kOS/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ public class Core : kOSProcessorFields
static Core()
{
var ver = typeof(Core).Assembly.GetName().Version;
// NOTICE: there is a clash of nomenclature here. C# calls the
// 3rd number "BUILD" and the 4th number "Revision" while the AVC mod
// (and presumably CKAN) calls the 3rd number "PATCH" and the 4th number "BUILD".
// We'll be using the AVC terminology in kerboscript, thus why this next line
// passes in "ver.Revision" where the VersionInfo's "BUILD" goes, and the
// "ver.Build" where VersionInfo's "PATCH" goes:
VersionInfo = new VersionInfo(ver.Major, ver.Minor, ver.Build, ver.Revision);
VersionInfo = new VersionInfo(ver);
}

public Core(kOSProcessor processor, SharedObjects shared):base(processor, shared)
Expand Down
7 changes: 6 additions & 1 deletion src/kOS/Suffixed/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Config : Structure, IConfig
public bool UseBlizzyToolbarOnly { get { return kOSCustomParameters.Instance.useBlizzyToolbarOnly; } set { kOSCustomParameters.Instance.useBlizzyToolbarOnly = value; } }
public bool DebugEachOpcode { get { return kOSCustomParameters.Instance.debugEachOpcode; } set { kOSCustomParameters.Instance.debugEachOpcode = value; } }
public bool SuppressAutopilot { get { return GetPropValue<bool>(PropId.SuppressAutopilot); } set { SetPropValue(PropId.SuppressAutopilot, value); } }
public bool DeprecatedWarnings { get { return GetPropValue<bool>(PropId.DeprecatedWarnings); } set { SetPropValue(PropId.DeprecatedWarnings, value); } }

// NOTE TO FUTURE MAINTAINERS: If it looks like overkill to use a double instead of a float for this next field, you're right.
// But KSP seems to have a bug where single-precision floats don't get saved in the config XML file. Doubles seem to work, though.
Expand Down Expand Up @@ -69,6 +70,7 @@ private void InitializeSuffixes()
AddSuffix("DEFAULTWIDTH", new ClampSetSuffix<ScalarValue>(() => TerminalDefaultWidth, value => TerminalDefaultWidth = value, 15f, 255f, 1f));
AddSuffix("DEFAULTHEIGHT", new ClampSetSuffix<ScalarValue>(() => TerminalDefaultHeight, value => TerminalDefaultHeight = value, 3f, 160f, 1f));
AddSuffix("SUPPRESSAUTOPILOT", new SetSuffix<BooleanValue>(() => SuppressAutopilot, value => SuppressAutopilot = value));
AddSuffix("DEPRECATEDWARNINGS", new SetSuffix<BooleanValue>(() => DeprecatedWarnings, value => DeprecatedWarnings = value));
}

private void BuildValuesDictionary()
Expand All @@ -92,6 +94,8 @@ private void BuildValuesDictionary()
new ConfigKey("TerminalDefaultHeight", "DEFAULTHEIGHT", "Initial Terminal:HEIGHT when a terminal is first opened", 36, 3, 160, typeof(int)));
AddConfigKey(PropId.SuppressAutopilot,
new ConfigKey("SuppressAutopilot", "SUPPRESSAUTOPILOT", "Suppress all kOS autopiloting for emergency manual control", false, false, true, typeof(bool)));
AddConfigKey(PropId.DeprecatedWarnings,
new ConfigKey("DeprecatedWarnings", "DEPRECATEDWARNINGS", "Enables/disables deprecated warning messages", true, false, true, typeof(bool)));
}

private void AddConfigKey(PropId id, ConfigKey key)
Expand Down Expand Up @@ -256,7 +260,8 @@ private enum PropId
TerminalBrightness = 17,
TerminalDefaultWidth = 18,
TerminalDefaultHeight = 19,
SuppressAutopilot = 20
SuppressAutopilot = 20,
DeprecatedWarnings = 21
}
}
}
Loading
Loading