Lua library for arcs

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

Lua library for arcs

Post by ckfinite »

I'm working on a scenario, and wrote this little library for making and modifying arcs in a more convenient way than manually writing tables, and thought that it could be useful to other people here. The library can be found here, to add, just copy and paste into an event that runs whenever the scene is loaded, and it should be available.

Usage:

Arcs created by the library can be used immediately by Command with no modifications.

Example:
ScenEdit_UpdateUnit({guid='2c246071-b2a3-4603-a8a5-6d2033ff4a73', mode="add_sensor", dbid=3352, arc_detect=Arc():forward()})

Constructors:

This library adds a single function, Arc(), which provides several constructor methods for arcs:

Arc():from(from_angle):to(to_angle)

This will create a new arc which extends from from_angle, in degrees off of the front of the unit, to to_angle, in the same frame. Notably, the system sweeps clockwise, so, for example, Arc():from(0):to(0) will include all angles.

Examples:
Arc():from(0):to(90) -- front right quadrant
Arc():from(180):to(0) -- port side


Arc():new(arc)

The "new" method makes a library-usable arc from a default arc. This is used when adding arcs manually is desirable. Names are as in the default system, see here for them

Examples:
Arc():new({"SB1"}) -- adds the "SB1" arc.

Arc():all(), Arc():forward(), Arc():backward(), Arc():port(), Arc():starboard()

As the name implies, these return a pre-defined arc over the named area.

Examples:
Arc():all() -- an arc over all aspects
Arc():forward() -- an arc over the forward aspect

Arc Utilities:

Arcs created by the library can be added, using the + operator. For example, Arc():forward() + Arc():backward() is equivalent to Arc():all(). These arcs can then be added themselves, ad infinitum.

Arcs created by Arc() can be converted to string for printing and debug with the built-in tostring method, which prints out the names of the aspects included in the arc.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Lua library for arcs

Post by michaelm75au »

Thank you
Michael
Post Reply

Return to “Mods and Scenarios”