lightsync

master
livie 2026-01-25 15:14:35 +02:00
parent e328ffe8b9
commit db18f68907
1 changed files with 148 additions and 0 deletions

148
light_sync.lsl Normal file
View File

@ -0,0 +1,148 @@
// because f--- you, that's why
//--------------------------------------------------------------------------
// BEGIN config
#define USE_BOLTS
#define LIGHT_GLOW 0.2
#define OFF_DAMP_FACTOR 0.6
// END config
//--------------------------------------------------------------------------
// BEGIN macros
#define color_parse(_argv) <(float)gets(_argv, 1), (float)gets(argv, 2), (float)gets(argv, 3)>
#define listen_on(_h, _ch) llListenRemove(_h); _h = llListen(_ch, "", NULL_KEY, "")
// END macros
//--------------------------------------------------------------------------
// BEGIN includes
#include <utils.lsl>
#include <objects.lsl>
// END includes
//--------------------------------------------------------------------------
// BEGIN globals
integer L_CAPS = 0;
integer L_LIGHTS = 0;
#define C_CAPS 411
integer C_LIGHTS = 0;
integer power_on = 1;
vector color = <1, 1, 1>;
key avatar = NULL_KEY;
// END globals
//--------------------------------------------------------------------------
// BEGIN functions
init() {
avatar = llGetOwner();
C_LIGHTS = 105 - (integer)("0x" + substr(avatar, 29, 35));
listen_on(L_LIGHTS, C_LIGHTS);
listen_on(L_CAPS, C_CAPS);
power_on = 1;
tell(avatar, C_LIGHTS, "color-q");
} // init()
update_color() {
if (power_on) {
llSetLinkGLTFOverrides(LINK_THIS, ALL_SIDES, [
OVERRIDE_GLTF_BASE_COLOR_FACTOR, llsRGB2Linear(color),
OVERRIDE_GLTF_EMISSIVE_FACTOR, llsRGB2Linear(color)
]);
setp(LINK_THIS, [
PRIM_COLOR, ALL_SIDES, color, 1.0,
PRIM_GLOW, ALL_SIDES, LIGHT_GLOW
]);
} // if (power_on)
else {
llSetLinkGLTFOverrides(LINK_THIS, ALL_SIDES, [
OVERRIDE_GLTF_BASE_COLOR_FACTOR, llsRGB2Linear(color * OFF_DAMP_FACTOR),
OVERRIDE_GLTF_EMISSIVE_FACTOR, llsRGB2Linear(color * OFF_DAMP_FACTOR)
]);
setp(LINK_THIS, [
PRIM_COLOR, ALL_SIDES, color * OFF_DAMP_FACTOR, 1.0,
PRIM_GLOW, ALL_SIDES, 0
]);
} // else (power_on)
} // update_color()
// END functions
//--------------------------------------------------------------------------
// BEGIN main
default {
state_entry() {
init();
} // state_entry()
on_rez(integer n) {
init();
} // on_rez(...)
listen(integer cc, string src, key id, string msg) {
if (cc == C_CAPS) {
if (substr(msg, 0, 4) == "info ") {
integer rc = (integer)delstring(msg, 0, 4);
tell(id, rc, "hwc " + jsobject([
"vendor", "Cat Conspiracy",
"version", "1.0",
"purpose", "light",
"channel", jsobject(["caps", C_CAPS, "lights", C_LIGHTS]),
"private", 1,
"busy", 0,
"usable", power_on,
"health", 1.0,
"info", "http://localhost:8080/"
]));
} // if (cmd == "info")
} // if (cc == C_CAPS)
else if (cc == C_LIGHTS) {
list argv = split(msg, " ");
string cmd = gets(argv, 0);
switch (cmd) {
case "on":
power_on = 1;
update_color();
break;
case "off":
power_on = 0;
update_color();
break;
#ifdef USE_BOLTS
case "bolts":
if (gets(argv, 1) == "on") {
echo("@detach=n");
} else if (gets(argv, 1) == "off") {
echo("@detach=y");
}
break;
#endif
case "color":
color = color_parse(argv);
update_color();
break;
case "probe":
tell(id, C_LIGHTS, "color-q");
break;
default:
// Unsupported command, do nothing.
break;
} // switch (cmd)
} // if (cc == C_LIGHTS)
} // listen(...)
} // state default
// END main
//--------------------------------------------------------------------------