Date uploaded | 7 months ago |
Version | 1.5.4 |
Download link | NotAtomicBomb-TerminalApi-1.5.4.zip |
Downloads | 554337 |
Dependency string | NotAtomicBomb-TerminalApi-1.5.4 |
This mod requires the following mods to function
BepInEx-BepInExPack
BepInEx pack for Mono Unity games. Preconfigured and ready to use.
Preferred version: 5.4.2100README
TerminalApi
Please report any issues here
Have the Glowstick mod and are unable to leave the terminal? Try This
Overview
Terminal Api provides a nice a easy way to add and modify terminal keywords. It allows you to create and add them whenever you want in your code as it will automatically add the keywords when it is safe to do so.
See Test Plugin and Time Command mod for an example case of this api.
Installation
Just drag and drop the BepInEx folder to your Lethal Company root folder(Where the Lethal Company.exe is). Or just use the thuderstore mod loader, much easier.
Table of Contents
- Adding Commands
- Callbacks
- Command Info
- Events
- Terminal Input
- Creating Terminal Keywords
- Creating Terminal Nodes
- Adding Text To Nodes
- Adding Keywords
- Updating Keywords
- Deleting Keyword
- Getting Keywords
- Compatible Nouns
[!WARNING] Make sure you are not adding duplicate keywords. I do plan on having a system to handle this in the future.
Adding Commands
This api give you an easy way to add terminal commands via the AddCommand
method.
This methods returns nothing.
There are two methods:
AddCommand(string commandWord, string displayText, string verbWord = null, bool clearPreviousText = true)
AddCommand(string commandWord, CommandInfo commandInfo, string verbWord = null, bool clearPreviousText = true)
Example:
AddCommand("frank", "Frank is not here\n", "get", true)
Will display Frank is not here
when get frank
or frank
is sent in the terminal
Callbacks
In 1.5.0 a way of adding callback functions was added. The current way only works on commands/terminalkeywords that are being added. The callback function must return a string, that string is what will be displayed on the terminal when the command is run.
There are two ways this can be achieved.
AddTerminalKeyword(nounKeyword, new CommandInfo() {
TriggerNode = triggerNode,
DisplayTextSupplier = () =>
{
Logger.LogWarning("Put code here, and it will run when trigger node is loaded");
return "This text will display";
},
Category = "Other",
Description = "This is just a test command."
});
Or
AddCommand("pop", new CommandInfo()
{
DisplayTextSupplier = () =>
{
Logger.LogWarning("Wowow, this ran.");
return "popped\n\n";
},
Category = "Other"
});
Command Info
Also in 1.5.0 a Command Class was added ot help with adding callbacks and info about the command to any of the existing categories.
Note: I do plan on handling categories that don't exist being automatically created, but that will have to be another time.
Any commands added with a category will append a line looking like this >[Title]\n[Description]
The CommandInfo class has 5 properties
Title
: The title of the command, can be null. If null, will try to use the terminalkeyword's word.Category
: The category that you want to add the info. Only works for existing categories likeother
.Description
: The description of your command.DisplayTextSupplier
: The callback function, needs to return a string.TriggerNode
: The node that will trigger theDisplayTextSupplier
. Can be null. If null, will try to use the terminalkeyword.specialKeywordResult.
Events
There are multiple subscribable events that this api provides.
They can be found in the TerminalApi.Events
namespace.
Here is a list of them:
TerminalAwake
- Runs when the terminal is fully awake.TerminalWaking
- Runs when the terminal is waking up.TerminalStarted
- Runs when the terminal is fully started.TerminalStarting
- Runs when the terminal starts.TerminalBeginUsing
- Runs when the player begins using.TerminalBeganUsing
- Runs after begins using.TerminalExited
- Runs when the player exits the terminal.TerminalParsedSentence
- Runs when the player sends a command.TerminalTextChanged
- Runs when the player types in the terminal.
For more information please check Test Plugin.
Terminal Input
With TerminalApi, you can get and set the users current input.
To do that we have two methods. GetTerminalInput
will of course get the terminal input.
SetTerminalInput
will set the input.
Examples:
string input = TerminalApi.GetTerminalInput();
if(input == "hello")
{
TerminalApi.SetTerminalInput("world");
}
Creating Terminal Keywords
To create a terminal keyword, you can use the CreateTerminalKeyword
method.
There are two overloaded methods available:
CreateTerminalKeyword(string word, bool isVerb = false, TerminalNode triggeringNode = null)
CreateTerminalKeyword(string word, string displayText, bool clearPreviousText = false, string terminalEvent = "")
Example:
TerminalKeyword keyword = TerminalApi.CreateTerminalKeyword("die", "No don't");
Creating Terminal Nodes
If you don't know what terminal nodes are, they essential hold information that the terminal uses when the keyword associated with the node is sent. For most cases, when a word is sent, it will display the nodes displayText
. You can create a node by using the CreateTerminalNode
method.
[!NOTE] You can pretty much ignore the terminalEvent parameter. Unless you know what you're doing.
There is one method available:
CreateTerminalNode(string displayText, bool clearPreviousText = false, string terminalEvent = "")
Example:
TerminalNode node = TerminalApi.CreateTerminalNode("Hello world");
Adding Text To Nodes
To add a line of text to an existing node, you can use NodeAppendLine
.
It uses a keyword's word to get the node and then adds the given text as a new line. If the word you are trying to append to gets its text via a verb's compatible noun, then this will not work.
In its current state, it must be run while in a game like in the terminal awake function.
There is one method available:
NodeAppendLine(string word, string text)
Example:
// Adds 'Hello' as a new line to the help node
NodeAppendLine("help", "\nHello");
Adding Keywords
Once you have your keyword ready to add you can use the AddTerminalKeyword
to add the keyword.
There are two methods available:
AddTerminalKeyword(TerminalKeyword terminalKeyword)
AddTerminalKeyword(TerminalKeyword terminalKeyword, CommandInfo commandInfo = null)
Example:
TerminalApi.AddTerminalKeyword(keyword);
Updating Keywords
Use UpdateKeyword
to update any keyword that already exists.
There is one method available:
UpdateKeyword(TerminalKeyword terminalKeyword)
Example:
TerminalApi.UpdateKeyword(keyword);
Deleting Keywords
Use DeleteKeyword
to delete an existing keyword.
There is one method available:
DeleteKeyword(string word)
Example:
TerminalApi.DeleteKeyword("buy")
^ Will delete the buy keyword, if it exists
Getting Keywords
Use GetKeyword
to get an already existing keyword.
This uses the keyword's word to find it.
There is one method available:
GetKeyword(string keyword)
Example:
TerminalKeyword gottenKeyword = TerminalApi.GetKeyword("die");
Compatible Nouns
[!IMPORTANT] If you use compatible nouns, make sure that verb keyword and noun keywords are added to the terminal!
Every keyword has a field for an array of CompatibleNoun
, not all keywords use it though. Only keywords marked as verbs use it.
It allows for verb-noun combos like check fish
. The verb being check
and the noun being fish
.
Adding Compatible Noun To Newly Created Keyword
In TerminalApi there is an exstension method that allows you to quickly add a CompatibleNoun
to your verb keyword.
There are three of these overloaded methods:
AddCompatibleNoun(this TerminalKeyword terminalKeyword, TerminalKeyword noun, TerminalNode result)
AddCompatibleNoun(this TerminalKeyword terminalKeyword, string noun, TerminalNode result)
AddCompatibleNoun(this TerminalKeyword terminalKeyword, string noun, string displayText)
AddCompatibleNoun(this TerminalKeyword terminalKeyword, TerminalKeyword noun, string displayText, bool clearPreviousText = false)
Here is an example:
TerminalKeyword verbKeyword = TerminalApi.CreateTerminalKeyword("check", true);
TerminalKeyword nounKeyword = TerminalApi.CreateTerminalKeyword("fish");
TerminalNode triggerNode = TerminalApi.CreateTerminalNode("There are no fish\n", true);
verbKeyword = verbKeyword.AddcompatibleNoun(nounKeyword, triggerNode);
TerminalApi.AddTerminalKeyword(verbKeyword);
TerminalApi.AddTerminalKeyword(nounKeyword);
In the example above, if you were to type check fish
into the terminal you would get There are no fish\n
.
Adding Compatible Noun to Existing Keyword
Use AddCompatibleNoun
method to add a CompatibleNoun
to an existing keyword.
The Noun should also already exist.
There are four overloaded methods:
AddCompatibleNoun(TerminalKeyword verbKeyword, string noun, string displayText, bool clearPreviousText = false)
AddCompatibleNoun(TerminalKeyword verbKeyword, string noun, TerminalNode triggerNode)
AddCompatibleNoun(string verbWord, string noun, TerminalNode triggerNode)
AddCompatibleNoun(string verbWord, string noun, string displayText, bool clearPreviousText = false)
Example:
TerminalApi.AddCompatibleNoun("check", "die", "You are not dead.");
The above code would add the existing die
noun to check and when check die
is typed into the terminal You are not dead.
would display.
Updating Existing Compatible Noun
Use UpdateKeywordCompatibleNoun
method to update an existing compatible noun on a verb keyword.
There is four method:
UpdateKeywordCompatibleNoun(TerminalKeyword verbKeyword, string noun, TerminalNode newTriggerNode)
UpdateKeywordCompatibleNoun(string verbWord, string noun, TerminalNode newTriggerNode)
UpdateKeywordCompatibleNoun(TerminalKeyword verbKeyword, string noun, string newDisplayText)
UpdateKeywordCompatibleNoun(string verbWord, string noun, string newDisplayText)
Example:
TerminalApi.UpdateKeywordCompatibleNoun("check", "fish", "There are 100 fish.")
With the above code check fish
you should get There are 100 fish.
in the terminal.
CHANGELOG
Releases
Version 1.0.0
- Initial Release
Version 1.0.1
- Updated Github link
Version 1.0.2
- Added Installation Instructions to README
Version 1.0.3
- Added proper tags to mod
Version 1.1.0
- Added a subscribable event for Terminal Awake
TerminalApi.Patches.TerminalAwakePatch.TerminalAwake
- Some file organizing
- Added CHANGELOG
Version 1.2.0
- Added more events
- Events are now located at
TerminalApi.Events
- Added the
AddCommand
method to easily add terminal commands - Update README
Version 1.3.0
- Added
TerminalTextChanged
event
Version 1.3.1
- Fixed bug with TextChanged event
Version 1.3.2
Version 1.4.0
- Added DeleteKeyword
- Added GetTerminalInput
- Added SetTerminalInput
Version 1.5.0
- Added CommandInfo class
- CommandInfo allows for adding callbacks functions
- Added AddCommand overload that accepts CommandInfo
- Added AddTerminalKeyword overload that also accepts CommandInfo
- Added a config option that allows users to disable TerminalApi logs
- Added NodeAppendLine, appends a line of text to a node via its keyword
Version 1.5.1
- Updated README
Version 1.5.2
- Added Null Check for CommandInfo.Category in AddTerminalKeyword
Version 1.5.4
- Fixed a bug with NodeAppendLine
Version 1.5.5
- Added License to abide by new guidelines