-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Preamble
Hi. After 4.5 years with a lot of breaks, I'm finally wanting a solid API for patches. Today I've been trying to implement ISRU patching and I've got plans to expand Ultimate Part Converter with more features. But I've hit several issues, like https://forum.kerbalspaceprogram.com/topic/50533-18x-112x-module-manager-423-july-03th-2023-fireworks-season/page/309/#comment-4440498, which makes both of my attempts at finding nodes with non-standard ID keys difficult, if not impossible. The need for arbitrarily programmable patching system is dictated by lack of constructs that allow cross-products of several lists of nodes, which is needed to implement B9 Fuel Switch compatibility for LPG converter.
The Overview
I'm suggesting addition of Lua API, like #5 that was given to me, but I've not wanted it yet, because the Ultimate Part Converter, which was a part of SSTO Project in the past was simpler and had just half of the code that I want to have now. But it was still remarkable, that it converted any LF jet, LF+Ox rocket, LF tank and LF+Ox tank to its LPG version, while supporting 2 fuel switching mods and SMURFF at the same time. And it still does that today perfectly.
Overview of the API and scripting environment
This solution combines approaches of both #5 and sarbian#157. In particular, it combines Lua API from #5 and functions from the advanced constructs issue. Here are all functions:
regexp(pattern,string)
- run regexp expression on a stringsin
,cos
,tan
,log10
,ln
,log2
,expE
,exp10
,mod
,exp
,sec
,csc
,sqrt
,curt
,root
,log
- math functionsgetKeys(node)
: finds all keys of a given nodegetKeysName(node, name)
: finds all keys with given name of a given nodegetKey(node, name)
: finds the first key with given name of a given node, or nil if not foundsetKey(key, value)
: sets a key to a valueaddKey(node, name, value)
: adds a key to a value and returns the new keyresetKey(node, name, value)
: creates or sets a key and returns the new/existing keysetNameKey(node, name, value)
: sets a key to a value only if present and returns the key or nil if not foundrenameKey(key, name)
- renames a keydelKey(key)
: deletes the key
getAllNodes(node)
: gets all sub-nodes of a nodegetTypeNodes(node, type)
: gets all sub-nodes of a node with given typegetNode(node, type)
: gets the first sub-node of a node with given type, or nil if not foundaddNode(node, name, value)
: adds a node to a value and returns the new noderesetNode(node, name, value)
: creates or sets a node and returns the new/existing nodesetNameNode(node, name, value)
: sets a node to a value only if present and returns the node or nil if not founddelNode(node)
- deletes a given noderetypeNode(node, newtype)
- changes type of the nodecloneNode(existingNode, targetParent)
- copies a node and returns the new nodecopyNode(existingNode, targetNode)
- copies all node data to a different nodeclearNode(node)
- removes all data from a node
rootNode(type)
: find a primary root-node with given typerootNodeName(type, name)
: find a root-node with given type and name
FIRST(callback), BEFORE(mod, callback), FOR(mod, callback), AFTER(mod, callback), LAST(mod, callback), FINAL(callback)
: runs the callback without arguments on given stage of loading. BEFORE, FOR, AFTER and LAST also take a modname.
Final Considerations
It's a long Feature Request, but it has to because the API will be finally extensive and very powerful. If it's implemented, I'll be grateful and Ultimate Part Converter will be bigger and better than ever.