Created
September 3, 2014 00:05
-
-
Save AmandaCameron/8b5e3eb08b15533b46a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import "stdlib/stdlib.obj-lsl"; | |
@import "src/os/Common/DOSApp.obj-lsl"; | |
@import "src/os/Common/DOSRenderContext.obj-lsl"; | |
@enum MediaStatus | |
Stopped = 0 | |
Paused = 1 | |
Playing = 2 | |
@end | |
@class DOAMediaItem : OLObject { | |
OLString title; | |
OLString url; | |
} | |
@property title; | |
@property url; | |
@end | |
@class DOAMedia : DOSApp { | |
CMMessaging mediaMsgr; | |
MediaStatus status; | |
DOAMediaItem current; | |
list queue; | |
} | |
- (void) start { | |
[self broadcast]; | |
} | |
- (void) init { | |
self.mediaMsgr = [[CMMessaging alloc] initWithNamespace:"Media" andDelegate:self]; | |
} | |
- (OLString) name { return "Media"; } | |
- (OLString) desc { return ""; } | |
- (OLString) author { return "Amanda Cameron"; } | |
- (OLString) version { return "0.01a"; } | |
- (void) icon:(DOSRenderContext) ctx { | |
[ctx penColour:"black"]; | |
[ctx fillCircle:<ctx.width / 2, ctx.height / 2, 0> radius:ctx.width / 3]; | |
[ctx textColour:"white"] | |
[ctx textCenter:"M" at:<ctx.width / 2, ctx.height / 2, 0>]; | |
} | |
- (list) theme { | |
return [ "Colour::Button::Flat::Foreground", "black" ]; | |
} | |
- (list) flags { | |
return [ "Widget" ]; | |
} | |
- (void) deactivate { | |
} | |
- (void) activate { | |
[self render:self.gui]; | |
} | |
- (void) render:(DOSRenderContext) ctx { | |
[ctx begin]; | |
if ctx.tag == "Screen" { | |
if [ctx isTv] { | |
// TODO. | |
} else { | |
[ctx banner:"Media Control"]; | |
[ctx penColour:"red"]; | |
[ctx fillRectangle:<0, 56, 0> size:<ctx.width, ctx.width, 0>] | |
[self renderControls:ctx]; | |
} | |
} else if ctx.tag == "Launcher/Widget" { | |
[ctx penColour:"red"]; | |
[ctx fillRectangle:<0, 0, 0> size:<ctx.width, ctx.width, 0>]; | |
[self renderControls:ctx]; | |
} else if ctx == "Notification" { | |
[ctx penColour:"red"]; | |
[ctx fillRectangle:<0, 0, 0> size:<48, 48, 0>]; | |
[self renderControlsAt:<48, 0, 0> size:<ctx.width - 48, ctx.height - 36, 0> on:ctx]; | |
} | |
[ctx end]; | |
} | |
- (void) hotspotClicked:(OLString) hs { | |
} | |
- (void) messenger:(CMMessaging) msgr command:(OLString) command args:(list) args { | |
if msgr == self.mediaMsgr { | |
// TODO. | |
} | |
} | |
- (void) renderControls:(DOSRenderContext) ctx { | |
[self renderControlsAt:<0, ctx.height - 36, 0> size:<ctx.width, 36, 0> on:ctx]; | |
} | |
- (void) renderControlsAt:(OLVector) pos size:(OLVector) size on:(DOSRenderContext) ctx { | |
float btnWidth = size.x / 3; | |
[ctx theme:[self theme]]; | |
[ctx penColour:"Button::Background"]; | |
[ctx fillRectangle:pos size:size]; | |
[ctx buttonFlat:"<|" at:<pos.x, pos.y, 0> size:<btnWidth, size.y, 0> hotZone:"Back"]; | |
if self.status == MediaStatus.Playing { | |
[ctx buttonFlat:"||" at:<pos.x + size.x / 2 - btnWidth / 2, pos.y, 0> size:<btnWidth, size.y, 0> hotZone:"Pause"]; | |
} else { | |
[ctx buttonFlat:">" at:<pos.x + size.x / 2 - btnWidth / 2, pos.y, 0> size:<btnWidth, size.y, 0> hotZone:"Play"]; | |
} | |
[ctx buttonFlat:"|>" at:<pos.x + btnWidth * 2, pos.y, 0> size:<btnWidth, size.y, 0> hotZone:"Next"]; | |
} | |
@end | |
default { | |
state_entry() { | |
[[DOAMedia instance] start]; | |
} | |
link_message(integer sender, integer intArg, string strArg, key keyArg) { | |
[CMMessaging linkMessage:sender integerArg:intArg keyArg:keyArg stringArg: strArg]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list __ObjLSL_CallStack; | |
string LIST_SEP = "#8675#"; | |
string nil = "8F24F505-BE43-410D-8D87-349E53F788C1"; | |
list __ObjLSL_Objects = []; | |
list __CMMessaging_Recievers; | |
string DOAMedia(string __self, string __selector, list __args) { | |
ObjLSL_PushCall("DOAMedia", __self, __selector, __args); | |
if(__self == NULL_KEY) { | |
} else { | |
string self = (string)__self; | |
if(__selector == "activate") { | |
DOAMedia((string)self, "render:", [(string)DOSApp((string)self, "gui", [])]); | |
} else if(__selector == "renderControlsAt:size:on:") { | |
vector pos = llList2Vector(__args, 0); | |
vector size = llList2Vector(__args, 1); | |
string ctx = llList2String(__args, 2); | |
float btnWidth = size.x / 3; | |
DOSRenderContext((string)ctx, "theme:", [ObjLSL_Serialise_List(ObjLSL_Deserialise_List(DOAMedia((string)self, "theme", [])))]); | |
DOSRenderContext((string)ctx, "penColour:", ["Button::Background"]); | |
DOSRenderContext((string)ctx, "fillRectangle:size:", [pos, size]); | |
DOSRenderContext((string)ctx, "buttonFlat:at:size:hotZone:", ["<|", < pos.x, pos.y, 0>, < btnWidth, size.y, 0>, "Back"]); | |
if((integer)ObjLSL_Get(self, 7) == 2) { | |
DOSRenderContext((string)ctx, "buttonFlat:at:size:hotZone:", ["||", < pos.x + size.x / 2 - btnWidth / 2, pos.y, 0>, < btnWidth, size.y, 0>, "Pause"]); | |
} | |
else { | |
DOSRenderContext((string)ctx, "buttonFlat:at:size:hotZone:", [">", < pos.x + size.x / 2 - btnWidth / 2, pos.y, 0>, < btnWidth, size.y, 0>, "Play"]); | |
} | |
DOSRenderContext((string)ctx, "buttonFlat:at:size:hotZone:", ["|>", < pos.x + btnWidth * 2, pos.y, 0>, < btnWidth, size.y, 0>, "Next"]); | |
} else if(__selector == "start") { | |
DOSApp((string)self, "broadcast", []); | |
} else if(__selector == "name") { | |
return ObjLSL_Return( (string)"Media"); | |
} else if(__selector == "icon:") { | |
string ctx = llList2String(__args, 0); | |
DOSRenderContext((string)ctx, "penColour:", ["black"]); | |
DOSRenderContext((string)ctx, "fillCircle:radius:", [< (integer)ObjLSL_Get(ctx, 0) / 2, (integer)ObjLSL_Get(ctx, 1) / 2, 0>, (integer)ObjLSL_Get(ctx, 0) / 3]); | |
DOSRenderContext((string)ctx, "textColour:", ["white"]); | |
DOSRenderContext((string)ctx, "textCenter:at:", ["M", < (integer)ObjLSL_Get(ctx, 0) / 2, (integer)ObjLSL_Get(ctx, 1) / 2, 0>]); | |
} else if(__selector == "messenger:command:args:") { | |
string msgr = llList2String(__args, 0); | |
string command = llList2String(__args, 1); | |
list args = ObjLSL_Deserialise_List(llList2String(__args, 2)); | |
if(msgr == (string)ObjLSL_Get(self, 6)) { | |
} | |
} else if(__selector == "init") { | |
ObjLSL_Set(self, 6, (string)CMMessaging(ObjLSL_New("CMMessaging", 2), "initWithNamespace:andDelegate:", ["Media", self])); | |
} else if(__selector == "author") { | |
return ObjLSL_Return( (string)"Amanda Cameron"); | |
} else if(__selector == "deactivate") { | |
} else if(__selector == "desc") { | |
return ObjLSL_Return( (string)""); | |
} else if(__selector == "renderControls:") { | |
string ctx = llList2String(__args, 0); | |
DOAMedia((string)self, "renderControlsAt:size:on:", [< 0, (integer)ObjLSL_Get(ctx, 1) - 36, 0>, < (integer)ObjLSL_Get(ctx, 0), 36, 0>, ctx]); | |
} else if(__selector == "version") { | |
return ObjLSL_Return( (string)"0.01a"); | |
} else if(__selector == "theme") { | |
return ObjLSL_Return( ObjLSL_Serialise_List(["Colour::Button::Flat::Foreground", "black"])); | |
} else if(__selector == "flags") { | |
return ObjLSL_Return( ObjLSL_Serialise_List(["Widget"])); | |
} else if(__selector == "render:") { | |
string ctx = llList2String(__args, 0); | |
DOSRenderContext((string)ctx, "begin", []); | |
if((string)ObjLSL_Get(ctx, 7) == "Screen") { | |
if((integer)DOSRenderContext((string)ctx, "isTv", [])) { | |
} | |
else { | |
DOSRenderContext((string)ctx, "banner:", ["Media Control"]); | |
DOSRenderContext((string)ctx, "penColour:", ["red"]); | |
DOSRenderContext((string)ctx, "fillRectangle:size:", [< 0, 56, 0>, < (integer)ObjLSL_Get(ctx, 0), (integer)ObjLSL_Get(ctx, 0), 0>]); | |
DOAMedia((string)self, "renderControls:", [ctx]); | |
} | |
} | |
else if((string)ObjLSL_Get(ctx, 7) == "Launcher/Widget") { | |
DOSRenderContext((string)ctx, "penColour:", ["red"]); | |
DOSRenderContext((string)ctx, "fillRectangle:size:", [< 0, 0, 0>, < (integer)ObjLSL_Get(ctx, 0), (integer)ObjLSL_Get(ctx, 0), 0>]); | |
DOAMedia((string)self, "renderControls:", [ctx]); | |
} | |
else if(ctx == "Notification") { | |
DOSRenderContext((string)ctx, "penColour:", ["red"]); | |
DOSRenderContext((string)ctx, "fillRectangle:size:", [< 0, 0, 0>, < 48, 48, 0>]); | |
DOAMedia((string)self, "renderControlsAt:size:on:", [< 48, 0, 0>, < (integer)ObjLSL_Get(ctx, 0) - 48, (integer)ObjLSL_Get(ctx, 1) - 36, 0>, ctx]); | |
} | |
DOSRenderContext((string)ctx, "end", []); | |
} else if(__selector == "hotspotClicked:") { | |
string hs = llList2String(__args, 0); | |
} else { | |
/* TODO: Implement Default Selectors? */ | |
} | |
} | |
return DOSApp(__self, __selector, __args); | |
} | |
string OLObject(string __self, string __selector, list __args) { | |
ObjLSL_PushCall("OLObject", __self, __selector, __args); | |
if(__self == NULL_KEY) { | |
} else { | |
string self = (string)__self; | |
if(__selector == "describe") { | |
return ObjLSL_Return( (string)"[ OLObject of type " + llList2String(ObjLSL_GetData(self), 0) + " ]"); | |
} else if(__selector == "hash") { | |
return ObjLSL_Return( (string)self); | |
} else { | |
/* TODO: Implement Default Selectors? */ | |
} | |
} | |
return ObjLSL_Return(nil); | |
} | |
string OLSingleton(string __self, string __selector, list __args) { | |
ObjLSL_PushCall("OLSingleton", __self, __selector, __args); | |
if(__self == NULL_KEY) { | |
} else { | |
string self = (string)__self; | |
if(__selector == "describe") { | |
return ObjLSL_Return( (string)"[ OLSingleton of type " + llList2String(ObjLSL_GetData(self), 0) + " ]"); | |
} else if(__selector == "hash") { | |
return ObjLSL_Return( (string)self); | |
} else { | |
/* TODO: Implement Default Selectors? */ | |
} | |
} | |
return ObjLSL_Return(nil); | |
} | |
string DOSRenderContext(string __self, string __selector, list __args) { | |
ObjLSL_PushCall("DOSRenderContext", __self, __selector, __args); | |
if(__self == NULL_KEY) { | |
} else { | |
string self = (string)__self; | |
if(__selector == "applyTheme:") { | |
list theme = ObjLSL_Deserialise_List(llList2String(__args, 0)); | |
DOSRenderContext((string)self, "sendDraw:args:", ["GUI/Theme", ObjLSL_Serialise_List(theme)]); | |
} else if(__selector == "theme:") { | |
list theme = ObjLSL_Deserialise_List(llList2String(__args, 0)); | |
DOSRenderContext((string)self, "sendDraw:args:", ["GUI/Theme", ObjLSL_Serialise_List(theme)]); | |
} else if(__selector == "clear") { | |
DOSRenderContext((string)self, "sendDraw:", ["Clear"]); | |
} else if(__selector == "textCenter:at:") { | |
string text = llList2String(__args, 0); | |
vector pos = llList2Vector(__args, 1); | |
DOSRenderContext((string)self, "sendDraw:args:", ["Text/Center", ObjLSL_Serialise_List([pos.x, pos.y, text])]); | |
} else if(__selector == "initWithToken:andDelegate:") { | |
key token = llList2Key(__args, 0); | |
key del = llList2Key(__args, 1); | |
ObjLSL_Set(self, 3, (string)token); | |
ObjLSL_Set(self, 6, (string)CMMessaging(ObjLSL_New("CMMessaging", 2), "initWithNamespace:", ["Display/Context/" + ((string)token)])); | |
ObjLSL_Set(self, 0, (string)(-1)); | |
ObjLSL_Set(self, 1, (string)(-1)); | |
ObjLSL_Set(self, 4, (string)FALSE); | |
ObjLSL_Set(self, 2, (string)del); | |
return ObjLSL_Return( (string)self); | |
} else if(__selector == "begin") { | |
DOSRenderContext((string)self, "clear", []); | |
} else if(__selector == "penColour:") { | |
string colour = llList2String(__args, 0); | |
DOSRenderContext((string)self, "sendDraw:args:", ["Pen/Colour", ObjLSL_Serialise_List([colour])]); | |
} else if(__selector == "fillRectangle:size:") { | |
vector pos = llList2Vector(__args, 0); | |
vector size = llList2Vector(__args, 1); | |
DOSRenderContext((string)self, "sendDraw:args:", ["Rectangle/Fill", ObjLSL_Serialise_List([pos.x, pos.y, size.x, size.y])]); | |
} else if(__selector == "start") { | |
if( ! (integer)ObjLSL_Get(self, 4)) { | |
CMMessaging((string)ObjLSL_Get(self, 6), "send:link:", ["GetDetails", (key)ObjLSL_Get(self, 5)]); | |
} | |
} else if(__selector == "sendDraw:args:") { | |
string cmd = llList2String(__args, 0); | |
list args = ObjLSL_Deserialise_List(llList2String(__args, 1)); | |
CMMessaging((string)ObjLSL_Get(self, 6), "send:link:args:", ["Draw/" + cmd, (key)ObjLSL_Get(self, 5), ObjLSL_Serialise_List(args)]); | |
} else if(__selector == "describe") { | |
return ObjLSL_Return( (string)"[ DOSRenderContext with tag: " + (string)ObjLSL_Get(self, 7) + " ]"); | |
} else if(__selector == "free") { | |
CMMessaging((string)ObjLSL_Get(self, 6), "free", []); | |
ObjLSL_Free(self); | |
return ObjLSL_Return( nil); | |
} else if(__selector == "fillCircle:radius:") { | |
vector pos = llList2Vector(__args, 0); | |
integer rad = llList2Integer(__args, 1); | |
DOSRenderContext((string)self, "sendDraw:args:", ["Circle/Fill", ObjLSL_Serialise_List([pos.x, pos.y, rad])]); | |
} else if(__selector == "buttonFlat:at:size:hotZone:") { | |
string text = llList2String(__args, 0); | |
vector pos = llList2Vector(__args, 1); | |
vector size = llList2Vector(__args, 2); | |
string hz = llList2String(__args, 3); | |
DOSRenderContext((string)self, "sendDraw:args:", ["GUI/Button/Flat", ObjLSL_Serialise_List([pos.x, pos.y, size.x, size.y, hz, text])]); | |
} else if(__selector == "isTv") { | |
return ObjLSL_Return( (string)((integer)ObjLSL_Get(self, 0) == 1024 && (integer)ObjLSL_Get(self, 1) == 512)); | |
} else if(__selector == "banner:") { | |
string banner = llList2String(__args, 0); | |
DOSRenderContext((string)self, "sendDraw:args:", ["GUI/Banner", ObjLSL_Serialise_List([banner])]); | |
} else if(__selector == "done") { | |
CMMessaging((string)ObjLSL_Get(self, 6), "send:link:", ["Done", LINK_SET]); | |
} else if(__selector == "messenger:command:args:") { | |
string msgr = llList2String(__args, 0); | |
string command = llList2String(__args, 1); | |
list args = ObjLSL_Deserialise_List(llList2String(__args, 2)); | |
if(command == "Details") { | |
ObjLSL_Set(self, 4, (string)TRUE); | |
ObjLSL_Set(self, 0, (string)llList2Integer(args, 0)); | |
ObjLSL_Set(self, 1, (string)llList2Integer(args, 1)); | |
ObjLSL_Call((key)ObjLSL_Get(self, 2), "contextReady:", [self]); | |
} | |
else if(command == "Destroyed") { | |
ObjLSL_Set(self, 4, (string)FALSE); | |
ObjLSL_Call((key)ObjLSL_Get(self, 2), "contextDestroyed:", [self]); | |
} | |
} else if(__selector == "sendDraw:") { | |
string cmd = llList2String(__args, 0); | |
DOSRenderContext((string)self, "sendDraw:args:", [cmd, ObjLSL_Serialise_List([])]); | |
} else if(__selector == "end") { | |
DOSRenderContext((string)self, "done", []); | |
} else if(__selector == "textColour:") { | |
string colour = llList2String(__args, 0); | |
DOSRenderContext((string)self, "sendDraw:args:", ["Text/Colour", ObjLSL_Serialise_List([colour])]); | |
} else { | |
/* TODO: Implement Default Selectors? */ | |
} | |
} | |
return ObjLSL_Return(nil); | |
} | |
string CMMessaging(string __self, string __selector, list __args) { | |
ObjLSL_PushCall("CMMessaging", __self, __selector, __args); | |
if(__self == NULL_KEY) { | |
if(__selector == "linkMessage:integerArg:keyArg:stringArg:") { | |
integer sender = llList2Integer(__args, 0); | |
integer intArg = llList2Integer(__args, 1); | |
key keyArg = llList2Key(__args, 2); | |
string strArg = llList2String(__args, 3); | |
string cmd = ((string)keyArg); | |
list args = llParseString2List(strArg, ["%%%"], []); | |
integer __total_46 = llGetListLength(__CMMessaging_Recievers); | |
integer __i_46 = 0; | |
for(__i_46 = 0; __i_46 < __total_46; __i_46++) { | |
string recv = llList2Key(__CMMessaging_Recievers, __i_46); | |
if((llGetSubString(cmd, 0, llStringLength(((string)ObjLSL_Get(recv, 0) + "/")) - 1) == ((string)ObjLSL_Get(recv, 0) + "/"))) { | |
cmd = (llGetSubString(cmd, llStringLength((string)ObjLSL_Get(recv, 0)) + 1, llStringLength(cmd))); | |
if((key)ObjLSL_Get(recv, 1) != nil) { | |
ObjLSL_Call((key)ObjLSL_Get(recv, 1), "messenger:command:args:", [recv, cmd, ObjLSL_Serialise_List(args)]); | |
} | |
} | |
} | |
} else { | |
/* TODO: Implement Default Selectors? */ | |
} | |
} else { | |
string self = (string)__self; | |
if(__selector == "initWithNamespace:andDelegate:") { | |
string ns = llList2String(__args, 0); | |
key del = llList2Key(__args, 1); | |
ObjLSL_Set(self, 0, (string)ns); | |
ObjLSL_Set(self, 1, (string)del); | |
__CMMessaging_Recievers += [self]; | |
return ObjLSL_Return( (string)self); | |
} else if(__selector == "initWithNamespace:") { | |
string ns = llList2String(__args, 0); | |
return ObjLSL_Return( (string)CMMessaging((string)self, "initWithNamespace:andDelegate:", [ns, nil])); | |
} else if(__selector == "broadcast:args:") { | |
string command = llList2String(__args, 0); | |
list argList = ObjLSL_Deserialise_List(llList2String(__args, 1)); | |
llMessageLinked(LINK_SET, 0, llDumpList2String(argList, "%%%"), (string)ObjLSL_Get(self, 0) + "/" + command); | |
} else if(__selector == "send:link:") { | |
string command = llList2String(__args, 0); | |
integer link = llList2Integer(__args, 1); | |
CMMessaging((string)self, "send:link:args:", [command, link, ObjLSL_Serialise_List([])]); | |
} else if(__selector == "send:link:args:") { | |
string command = llList2String(__args, 0); | |
integer link = llList2Integer(__args, 1); | |
list args = ObjLSL_Deserialise_List(llList2String(__args, 2)); | |
llMessageLinked(link, 0, llDumpList2String(args, "%%%"), (string)ObjLSL_Get(self, 0) + "/" + command); | |
} else if(__selector == "free") { | |
list new = []; | |
integer __total_1b = llGetListLength(__CMMessaging_Recievers); | |
integer __i_1b = 0; | |
for(__i_1b = 0; __i_1b < __total_1b; __i_1b++) { | |
string recv = llList2Key(__CMMessaging_Recievers, __i_1b); | |
if(!recv != self) { | |
new += [recv]; | |
} | |
} | |
__CMMessaging_Recievers = new; | |
ObjLSL_Free((string)self); | |
} else if(__selector == "describe") { | |
return ObjLSL_Return( (string)"[CMMessaging with Namespace " + (string)ObjLSL_Get(self, 0) + " and delegate " + ((string)ObjLSL_Call((key)ObjLSL_Get(self, 1), "describe", [])) + "]"); | |
} else { | |
/* TODO: Implement Default Selectors? */ | |
} | |
} | |
return ObjLSL_Return(nil); | |
} | |
string DOSApp(string __self, string __selector, list __args) { | |
ObjLSL_PushCall("DOSApp", __self, __selector, __args); | |
if(__self == NULL_KEY) { | |
} else { | |
string self = (string)__self; | |
if(__selector == "messenger:command:args:") { | |
string msgr = llList2String(__args, 0); | |
string command = llList2String(__args, 1); | |
list args = ObjLSL_Deserialise_List(llList2String(__args, 2)); | |
if(msgr == (string)ObjLSL_Get(self, 2)) { | |
DOSApp((string)self, "appMessage:args:", [command, ObjLSL_Serialise_List(args)]); | |
} | |
else if(msgr == (string)ObjLSL_Get(self, 3)) { | |
DOSApp((string)self, "displayMessage:args:", [command, ObjLSL_Serialise_List(args)]); | |
} | |
else if(msgr == (string)ObjLSL_Get(self, 4)) { | |
DOSApp((string)self, "storageMessage:args:", [command, ObjLSL_Serialise_List(args)]); | |
} | |
return ObjLSL_Return( nil); | |
} else if(__selector == "contextForTag:") { | |
string tag = llList2String(__args, 0); | |
integer __total_9a = llGetListLength(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0))); | |
integer __i_9a = 0; | |
for(__i_9a = 0; __i_9a < __total_9a; __i_9a++) { | |
string ctx = llList2Key(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0)), __i_9a); | |
if((string)ObjLSL_Get(ctx, 7) == tag) { | |
return ObjLSL_Return( (string)ctx); | |
} | |
} | |
return ObjLSL_Return( (string)nil); | |
} else if(__selector == "displayMessage:args:") { | |
string command = llList2String(__args, 0); | |
list args = ObjLSL_Deserialise_List(llList2String(__args, 1)); | |
if((llGetSubString(command, 0, llStringLength("Context/") - 1) == "Context/")) { | |
command = (llGetSubString(command, 8, llStringLength(command))); | |
integer __total_81 = llGetListLength(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0))); | |
integer __i_81 = 0; | |
for(__i_81 = 0; __i_81 < __total_81; __i_81++) { | |
string ctx = llList2Key(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0)), __i_81); | |
if((llGetSubString(command, 0, llStringLength((key)ObjLSL_Get(ctx, 3) + "/") - 1) == (key)ObjLSL_Get(ctx, 3) + "/")) { | |
DOSRenderContext((string)ctx, "messenger:command:args:", [nil, (llGetSubString(command, llStringLength(((key)ObjLSL_Get(ctx, 3))) + 1, llStringLength(command))), ObjLSL_Serialise_List(args)]); | |
} | |
} | |
} | |
else if(command == "Touched" && (string)ObjLSL_Get(self, 1) != nil) { | |
ObjLSL_Call((string)((key)self), "hotspotClicked:", [llList2String(args, 0)]); | |
} | |
return ObjLSL_Return( nil); | |
} else if(__selector == "storageMessage:args:") { | |
string command = llList2String(__args, 0); | |
list args = ObjLSL_Deserialise_List(llList2String(__args, 1)); | |
if(command == "Updated" && llList2String(args, 0) == (string)ObjLSL_Call((string)((key)self), "name", [])) { | |
JsonDestroyStore((key)ObjLSL_Get(self, 5)); | |
ObjLSL_Set(self, 5, (string)JsonCreateStore("{}")); | |
CMMessaging((string)ObjLSL_Get(self, 4), "broadcast:args:", ["Load", ObjLSL_Serialise_List([(string)ObjLSL_Call((string)((key)self), "name", []), (key)ObjLSL_Get(self, 5)])]); | |
} | |
return ObjLSL_Return( nil); | |
} else if(__selector == "gui") { | |
return ObjLSL_Return( (string)DOSApp((string)self, "contextForTag:", ["Screen"])); | |
} else if(__selector == "appMessage:args:") { | |
string command = llList2String(__args, 0); | |
list args = ObjLSL_Deserialise_List(llList2String(__args, 1)); | |
if(command == "Activate" && llList2String(args, 0) == (string)ObjLSL_Call((string)((key)self), "name", [])) { | |
ObjLSL_Set(self, 1, (string)llList2String(args, 1)); | |
string ctx = (string)DOSRenderContext(ObjLSL_New("DOSGuiContext", 8), "initWithToken:andDelegate:", [llList2String(args, 1), self]); | |
ObjLSL_Set((string)ctx, 7, (string)"Screen"); | |
ObjLSL_Set((string)ctx, 5, (string)llList2Integer(args, 2)); | |
DOSRenderContext((string)ctx, "applyTheme:", [ObjLSL_Serialise_List((ObjLSL_Deserialise_List(ObjLSL_Call((string)((key)self), "theme", []))))]); | |
ObjLSL_Set(self, 0, ObjLSL_Serialise_List(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0)) + ctx)); | |
DOSRenderContext((string)ctx, "start", []); | |
} | |
else if(command == "Deactivate" && llList2String(args, 0) == (string)ObjLSL_Call((string)((key)self), "name", [])) { | |
ObjLSL_Set(self, 1, (string)nil); | |
ObjLSL_Call((string)((key)self), "deactivate", []); | |
} | |
else if(command == "Discover") { | |
DOSApp((string)self, "broadcast", []); | |
integer __total_68 = llGetListLength(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0))); | |
integer __i_68 = 0; | |
for(__i_68 = 0; __i_68 < __total_68; __i_68++) { | |
string ctx = llList2Key(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0)), __i_68); | |
DOSRenderContext((string)ctx, "free", []); | |
} | |
ObjLSL_Set(self, 0, ObjLSL_Serialise_List([])); | |
ObjLSL_Set(self, 1, (string)nil); | |
} | |
else if((llGetSubString(command, 0, llStringLength("Render/") - 1) == "Render/") && llList2String(args, 0) == (string)ObjLSL_Call((string)((key)self), "name", [])) { | |
string ctx = (string)DOSRenderContext(ObjLSL_New("DOSRenderContext", 8), "initWithToken:andDelegate:", [llList2String(args, 1), self]); | |
ObjLSL_Set(ctx, 7, (llGetSubString(command, 7, llStringLength(command)))); | |
ObjLSL_Set(ctx, 5, (string)llList2Integer(args, 2)); | |
ObjLSL_Set(self, 0, ObjLSL_Serialise_List(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0)) + [ctx])); | |
DOSRenderContext((string)ctx, "start", []); | |
} | |
return ObjLSL_Return( nil); | |
} else if(__selector == "contextDestroyed:") { | |
string ctx = llList2String(__args, 0); | |
list new = []; | |
integer __total_ba = llGetListLength(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0))); | |
integer __i_ba = 0; | |
for(__i_ba = 0; __i_ba < __total_ba; __i_ba++) { | |
string c = llList2Key(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0)), __i_ba); | |
if(!c != ctx) { | |
new += [c]; | |
} | |
} | |
ObjLSL_Set(self, 0, ObjLSL_Serialise_List(new)); | |
DOSRenderContext((string)ctx, "free", []); | |
} else if(__selector == "init") { | |
ObjLSL_Set(self, 2, (string)CMMessaging(ObjLSL_New("CMMessaging", 2), "initWithNamespace:andDelegate:", ["App", self])); | |
ObjLSL_Set(self, 3, (string)CMMessaging(ObjLSL_New("CMMessaging", 2), "initWithNamespace:andDelegate:", ["Display", self])); | |
ObjLSL_Set(self, 4, (string)CMMessaging(ObjLSL_New("CMMessaging", 2), "initWithNamespace:andDelegate:", ["Storage", self])); | |
ObjLSL_Set(self, 1, (string)nil); | |
ObjLSL_Set(self, 0, ObjLSL_Serialise_List([])); | |
ObjLSL_Set(self, 5, (string)JsonCreateStore("{}")); | |
CMMessaging((string)ObjLSL_Get(self, 4), "broadcast:args:", ["Load", ObjLSL_Serialise_List([(string)ObjLSL_Call((string)((key)self), "name", []), (key)ObjLSL_Get(self, 5)])]); | |
if((string)ObjLSL_Call((string)((key)self), "name", []) == nil) { | |
llOwnerSay("Error: This App is not correct."); | |
} | |
return ObjLSL_Return( nil); | |
} else if(__selector == "icon") { | |
return ObjLSL_Return( (string)DOSApp((string)self, "contextForTag:", ["Icon"])); | |
} else if(__selector == "broadcast") { | |
if((string)ObjLSL_Call((string)((key)self), "name", []) == nil) { | |
return ObjLSL_Return( nil); | |
} | |
CMMessaging((string)ObjLSL_Get(self, 2), "broadcast:args:", ["Register", ObjLSL_Serialise_List([(string)ObjLSL_Call((string)((key)self), "name", []), (string)ObjLSL_Call((string)((key)self), "desc", []), (string)ObjLSL_Call((string)((key)self), "author", []), (string)ObjLSL_Call((string)((key)self), "version", [])] + ObjLSL_Deserialise_List(ObjLSL_Call((string)((key)self), "flags", [])))]); | |
} else if(__selector == "contextReady:") { | |
string ctx = llList2String(__args, 0); | |
if(ctx == (string)DOSApp((string)self, "gui", [])) { | |
ObjLSL_Call((string)((key)self), "activate", []); | |
} | |
else if(ctx == (string)DOSApp((string)self, "icon", [])) { | |
DOSRenderContext((string)ctx, "clear", []); | |
ObjLSL_Call((string)((key)self), "icon:", [ctx]); | |
DOSRenderContext((string)ctx, "done", []); | |
} | |
else { | |
integer __total_ae = llGetListLength(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0))); | |
integer __i_ae = 0; | |
for(__i_ae = 0; __i_ae < __total_ae; __i_ae++) { | |
string c = llList2Key(ObjLSL_Deserialise_List(ObjLSL_Get(self, 0)), __i_ae); | |
if(c == ctx) { | |
ObjLSL_Call((string)((key)self), "render:", [ctx]); | |
} | |
} | |
} | |
} else { | |
/* TODO: Implement Default Selectors? */ | |
} | |
} | |
return ObjLSL_Return(nil); | |
} | |
string ObjLSL_Call(string __self, string selector, list __args) { | |
if(ObjLSL_IsA(__self, "DOAMedia")) | |
return DOAMedia(__self, selector, __args); | |
else if(ObjLSL_IsA(__self, "OLObject")) | |
return OLObject(__self, selector, __args); | |
else if(ObjLSL_IsA(__self, "OLSingleton")) | |
return OLSingleton(__self, selector, __args); | |
else if(ObjLSL_IsA(__self, "DOSRenderContext")) | |
return DOSRenderContext(__self, selector, __args); | |
else if(ObjLSL_IsA(__self, "DOSApp")) | |
return DOSApp(__self, selector, __args); | |
else if(ObjLSL_IsA(__self, "CMMessaging")) | |
return CMMessaging(__self, selector, __args); | |
return ObjLSL_Return(nil); | |
} | |
ObjLSL_Free(string self) ObjLSL_PushCall("OLObject", self, "free", []); | |
if(self == nil) { | |
ObjLSL_Return(nil); | |
return; | |
} | |
integer index = llListFindList(__ObjLSL_Objects, ["Instance::" + self]); | |
if(index != -1) { | |
__ObjLSL_Objects = llDeleteSubList(__ObjLSL_Objects, index, index + 3 + llList2Integer(__ObjLSL_Objects, index + 3)); | |
} | |
ObjLSL_Return(nil); | |
string ObjLSL_Set(string self, integer prop, string value) ObjLSL_PushCall("OLObject", self, "setSlot:", [prop]); | |
if(self == nil) { | |
ObjLSL_Return(nil); | |
return nil; | |
} | |
list data = ObjLSL_GetData(self); | |
if(llGetFreeMemory() < 512) { | |
llOwnerSay("Warning: Low memory trying to set property."); | |
llOwnerSay("Object: " + llList2String(data, 0)); | |
llOwnerSay("Instance: " + self); | |
} | |
data = llListReplaceList(data, [value], 3 + prop, 3 + prop); | |
ObjLSL_SetData(self, data); | |
ObjLSL_Return(self); | |
return self; | |
string ObjLSL_New(string type, integer slots) if(llGetFreeMemory() < 512) { | |
llOwnerSay("Error: Low Memory when allocating object."); | |
llOwnerSay("Object Entries: " + ((string)(llGetListLength(__ObjLSL_Objects)))); | |
return nil; | |
} | |
string obj = ((string)llGenerateKey()); | |
__ObjLSL_Objects += ["Instance::" + obj, type, 1, slots]; | |
integer slot; | |
for(slot = 0;slot < slots;slot++) { | |
__ObjLSL_Objects += [nil]; | |
} | |
return obj; | |
string ObjLSL_Singleton(string type, integer slots) if(llGetFreeMemory() < 512) { | |
llOwnerSay("Error: Low Memory when allocating singleton '" + type + "'"); | |
llOwnerSay("Object Entries: " + ((string)(llGetListLength(__ObjLSL_Objects)))); | |
return nil; | |
} | |
string obj = ((string)"OLSingleton::") + type; | |
if(llListFindList(__ObjLSL_Objects, [obj]) == -1) { | |
__ObjLSL_Objects += ["Instance::" + obj, type, -9999, slots]; | |
integer slot; | |
for(slot = 0;slot < slots;slot++) { | |
__ObjLSL_Objects += [nil]; | |
} | |
ObjLSL_Call(obj, "init", []); | |
} | |
return obj; | |
list ObjLSL_GetData(string self) ObjLSL_PushCall("OLObject", self, "getData", []); | |
if(self == nil) { | |
ObjLSL_Fatal("Access Violation: Attempt to read nil."); | |
} | |
integer index = llListFindList(__ObjLSL_Objects, ["Instance::" + self]); | |
if(index == -1) { | |
ObjLSL_Fatal("Access Violation: No such instance " + self); | |
return []; | |
} | |
ObjLSL_Return(nil); | |
return llList2List(__ObjLSL_Objects, index + 1, index + 3 + llList2Integer(__ObjLSL_Objects, index + 3)); | |
list ObjLSL_Deserialise_List(string obj) if(obj == "") { | |
return []; | |
} | |
list data = llParseString2List(obj, [LIST_SEP], []); | |
string index = llList2String(data, 0); | |
data = llList2List(data, 1, llGetListLength(data)); | |
list out = []; | |
integer __total_83 = llGetListLength(data); | |
integer __i_83 = 0; | |
for(__i_83 = 0; __i_83 < __total_83; __i_83++) { | |
string entry = llList2Key(data, __i_83); | |
if((llGetSubString(index, 0, llStringLength("v") - 1) == "v")) { | |
out += ((vector)entry); | |
} | |
else if((llGetSubString(index, 0, llStringLength("r") - 1) == "r")) { | |
out += ((rotation)entry); | |
} | |
else if((llGetSubString(index, 0, llStringLength("f") - 1) == "f")) { | |
out += ((float)entry); | |
} | |
else if((llGetSubString(index, 0, llStringLength("i") - 1) == "i")) { | |
out += ((integer)entry); | |
} | |
else if((llGetSubString(index, 0, llStringLength("k") - 1) == "k")) { | |
out += ((key)entry); | |
} | |
else { | |
out += ((string)entry); | |
} | |
index = (llGetSubString(index, 1, llStringLength(index))); | |
} | |
return out; | |
ObjLSL_SetData(string self, list data) ObjLSL_PushCall("OLObject", self, "setData", []); | |
if(self == nil) { | |
ObjLSL_Fatal("Access Violation: Attempt to set on nil."); | |
} | |
integer index = llListFindList(__ObjLSL_Objects, ["Instance::" + self]); | |
if(index == -1) { | |
ObjLSL_Fatal("Access Violation: Unkonwn instance."); | |
} | |
integer start = llGetListLength(__ObjLSL_Objects); | |
__ObjLSL_Objects = llListReplaceList(__ObjLSL_Objects, data, index + 1, index + 3 + llList2Integer(__ObjLSL_Objects, index + 3)); | |
if(llGetListLength(__ObjLSL_Objects) != start) { | |
llOwnerSay("[" + llGetScriptName() + "] Oops: Global state changed: Delta: " + ((string)(llGetListLength(__ObjLSL_Objects) - start))); | |
llOwnerSay("[" + llGetScriptName() + "] Instance: " + ((string)self) + " of type " + llList2String(data, 0)); | |
integer __total_12c = llGetListLength(data); | |
integer __i_12c = 0; | |
for(__i_12c = 0; __i_12c < __total_12c; __i_12c++) { | |
string elem = llList2Key(data, __i_12c); | |
llOwnerSay("[" + llGetScriptName() + "] Data: " + ((string)elem)); | |
} | |
} | |
ObjLSL_Return(nil); | |
ObjLSL_Fatal(string msg) llOwnerSay(llGetScriptName() + " FATAL: " + msg); | |
llOwnerSay("Stack Trace: " + ObjLSL_TraceBack()); | |
llSetScriptState(llGetScriptName(), FALSE); | |
string ObjLSL_Return(string value) __ObjLSL_CallStack = llList2List(__ObjLSL_CallStack, 0, -5); | |
return value; | |
ObjLSL_PushCall(string object, string self, string selector, list args) __ObjLSL_CallStack += [object, self, selector, ""]; | |
string ObjLSL_TraceBack() string ret = ""; | |
integer i; | |
integer total = llGetListLength(__ObjLSL_CallStack); | |
for(i = 0;i < total;i += 4) { | |
ret += "[ " + llList2String(__ObjLSL_CallStack, i) + " " + llList2String(__ObjLSL_CallStack, i + 2) + "]\n"; | |
} | |
return ret; | |
integer ObjLSL_IsA(string self, string type) list data = ObjLSL_GetData(self); | |
return llList2String(data, 0) == type; | |
string ObjLSL_List2Id(list src, integer index) return llList2String(src, index); | |
string ObjLSL_Serialise_List(list l) if(llGetListLength(l) == 0) { | |
return ""; | |
} | |
integer i = 0; | |
string index = ""; | |
for(i = 0;i < llGetListLength(l);i++) { | |
integer t = llGetListEntryType(l, i); | |
if(t == TYPE_INTEGER) { | |
index += "i"; | |
} | |
else if(t == TYPE_FLOAT) { | |
index += "f"; | |
} | |
else if(t == TYPE_VECTOR) { | |
index += "v"; | |
} | |
else if(t == TYPE_ROTATION) { | |
index += "r"; | |
} | |
else if(t == TYPE_KEY) { | |
index += "k"; | |
} | |
else { | |
index += "s"; | |
} | |
} | |
return llDumpList2String([index] + l, LIST_SEP); | |
string ObjLSL_Get(string self, integer prop) ObjLSL_PushCall("OLObject", self, "getSlot:" + ((string)prop), [prop]); | |
if(self == nil) { | |
return ObjLSL_Return(nil); | |
} | |
list data = ObjLSL_GetData(self); | |
return ObjLSL_Return(ObjLSL_List2Id(data, 3 + prop)); | |
default { | |
state_entry () { | |
ObjLSL_BeginStack("default", "state_entry"); | |
DOAMedia(ObjLSL_Singleton("DOAMedia", 10), "start", []); | |
} | |
link_message (integer sender, integer intArg, string strArg, key keyArg) { | |
ObjLSL_BeginStack("default", "link_message"); | |
CMMessaging(NULL_KEY, "linkMessage:integerArg:keyArg:stringArg:", [sender, intArg, keyArg, strArg]); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment