Skip to content

Instantly share code, notes, and snippets.

View hobione2k's full-sized avatar

hobione hobione2k

View GitHub Profile
@hobione2k
hobione2k / detectSignal.js
Last active April 29, 2024 19:26
ClusterScript-シグナル検出
const detectSignal = (n) => {
const sg = $.getStateCompat("this", n, T.double);
const ky = `last_${n}`;
const lsg = $.getStateCompat("this", ky, T.double);
if (sg > lsg) {
$.setStateCompat("this", ky, sg);
return true;
}
return false;
};
@hobione2k
hobione2k / log.js
Last active May 30, 2023 07:05
ClusterScript-時刻付きログ
const pad = (n, l = 2) => {
return n.toString().padStart(l, "0");
};
const now = () => {
const d = new Date();
const time = `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(
d.getSeconds()
)}.${pad(d.getMilliseconds(), 3)}`;
return time;
};
@hobione2k
hobione2k / intarvalTask.js
Created May 30, 2023 06:57
ClusterScript-一定間隔で実行
const intervalTask = (name, interval, deltaTime) => {
const key = `intervalTask_${name}}`;
$.state[key] = ($.state[key] ?? interval) + deltaTime;
if ($.state[key] < interval) return false;
$.state[key] = 0;
return true;
};
@hobione2k
hobione2k / timer.js
Last active May 31, 2023 04:11
ClusterScript Timer
const TIMER_KEY = (name) => `timer_${name}`;
const isTimerActive = (name) => $.state[TIMER_KEY(name)] >= 0;
const startTimer = (name, duration) => {
const key = TIMER_KEY(name);
if (isTimerActive(name)) return false; // この行を消すと再実行でタイマーを延長できる
$.state[key] = duration;
return true;
};