From 3d2f1fe23076be7206c18ce52cd7f65af4723d6a Mon Sep 17 00:00:00 2001 From: arookas Date: Sat, 12 Dec 2015 12:51:32 -0500 Subject: [PATCH] Added some stdlib scripts. --- stdlib/common.sun | 15 ++++++ stdlib/sound.sun | 12 +++++ stdlib/system.sun | 14 ++++++ stdlib/talk.sun | 115 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 stdlib/common.sun create mode 100644 stdlib/sound.sun create mode 100644 stdlib/system.sun create mode 100644 stdlib/talk.sun diff --git a/stdlib/common.sun b/stdlib/common.sun new file mode 100644 index 0000000..4f0bc09 --- /dev/null +++ b/stdlib/common.sun @@ -0,0 +1,15 @@ +/* ================================================= *\ + * common.sun + * + * ssc standard include utility + * 2015 arookas +\* ================================================= */ + +// return values for typeof(x) +const TYPE_INT = 0; +const TYPE_FLOAT = 1; +const TYPE_STRING = 2; + +import "system.sun"; +import "talk.sun"; +import "sound.sun"; diff --git a/stdlib/sound.sun b/stdlib/sound.sun new file mode 100644 index 0000000..a94900e --- /dev/null +++ b/stdlib/sound.sun @@ -0,0 +1,12 @@ +/* ================================================= *\ + * sound.sun + * + * ssc standard include utility + * 2015 arookas +\* ================================================= */ + +// builtins +builtin startBGM(num); +builtin stopBGM(num); + +builtin startSE(num); diff --git a/stdlib/system.sun b/stdlib/system.sun new file mode 100644 index 0000000..e78325d --- /dev/null +++ b/stdlib/system.sun @@ -0,0 +1,14 @@ +/* ================================================= *\ + * system.sun + * + * ssc standard include utility + * 2015 arookas +\* ================================================= */ + +// builtins +builtin getSystemFlag(flag); +builtin setSystemFlag(flag, value); + +// functions +function setOnSystemFlag(flag) { setSystemFlag(flag, true); } +function setOffSystemFlag(flag) { setSystemFlag(flag, false); } diff --git a/stdlib/talk.sun b/stdlib/talk.sun new file mode 100644 index 0000000..a171c51 --- /dev/null +++ b/stdlib/talk.sun @@ -0,0 +1,115 @@ +/* ================================================= *\ + * talk.sun + * + * ssc standard include utility + * 2015 arookas +\* ================================================= */ + +// ================================================= \\ +// TALK +// ================================================= \\ + +// flags +const TALKF_WAIT = 0; +const TALKF_CLOSE = (1 << 0); + +// builtins +builtin getTalkMode(); +builtin isTalkModeNow(); +builtin getTalkNPC(); +builtin getTalkNPCName(); +builtin setTalkMsgID(msgID, flags); + +// functions +function waitTalkStart(name) { + while (true) { + if (isTalkModeNow()) { + if (getTalkNPCName() == name) { + break; + } + } + yield; + } +} +function waitTalkStartHandle(handle) { + while (true) { + if (isTalkModeNow()) { + if (getTalkNPC() == handle) { + break; + } + } + yield; + } +} + +// sets message (blocking) +function talk(msgID, flags) { + setTalkMsgID(msgID, flags); + if (flags & TALKF_CLOSE) { + while (isTalkModeNow()) { + yield; + } + } + yield; + while (getTalkMode() != true) { + yield; + } +} + +function talkAndWait(msgID) { talk(msgID, TALKF_WAIT); } +function talkAndClose(msgID) { talk(msgID, TALKF_CLOSE); } + +// ================================================= \\ +// SELECT +// ================================================= \\ + +// builtins +builtin getTalkSelectedValue(); + +// functions +function select(msgID, flags) { + setTalkMsgID(msgID, flags); + if (flags & TALKF_CLOSE) { + while (isTalkModeNow()) { + yield; + } + } + else { + yield; + while (getTalkMode() != true) { + yield; + } + } + return getTalkSelectedValue(); +} + +function talkAndSelect(msgID) { select(msgID, TALKF_WAIT); } +function talkAndSelectClose(msgID) { select(msgID, TALKF_CLOSE); } + +// ================================================= \\ +// FORCE +// ================================================= \\ + +// builtins +builtin __forceStartTalk(handle); +builtin __forceStartTalkExceptNpc(handle); + +// functions +function forceTalk(handle) { + var res = __forceStartTalk(handle); + if (res == true) { + while (!isTalkModeNow()) { + yield; + } + } + return res; +} +function forceTalkExceptNpc(handle) { + var res = __forceStartTalkExceptNpc(handle); + if (res == true) { + while (!isTalkModeNow()) { + yield; + } + } + return res; +}