Uses 1117K of libraries. Click here for Pure Java version (8567L/45K).
1 | !7 |
2 | |
3 | cmodule TimerModule > DynBigNumber { |
4 | bool active; |
5 | long setAt, setTill; |
6 | |
7 | start { |
8 | dm_onTopInput(vf<S> setTimer); |
9 | doEvery(1.0, r updateMe); |
10 | preloadLibrary(#1400163); |
11 | } |
12 | |
13 | void update { |
14 | long now = now(); |
15 | if (setTill == 0 || !active) ret with setValue(""); |
16 | if (setTill <= now) { |
17 | setField(active := false); |
18 | ret with makeAlarm(); |
19 | } else { |
20 | long seconds = iround(toSeconds(setTill-now)); |
21 | setValue(seconds/60 + ":" + formatInt(mod(seconds, 60), 2)); |
22 | } |
23 | } |
24 | |
25 | void makeAlarm { |
26 | setValue("ALARM!"); |
27 | infoBox_noHide("ALARM!"); |
28 | vmBus_send('timerAlarm, module()); |
29 | playWAVSnippet(#1400163); |
30 | } |
31 | |
32 | // API |
33 | |
34 | void reset enter { |
35 | setFields(active := false, setAt := 0L, setTill := 0L); |
36 | update(); |
37 | } |
38 | |
39 | void setTimer(fS s) { |
40 | final new Matches m; |
41 | if "* minutes|* minute|set timer to * minutes" { |
42 | switch to q(); |
43 | int minutes = parseEnglishNumberOrInt($1); |
44 | if (minutes <= 0) ret; |
45 | setFields(active := true, setAt := now(), setTill := now()+fromMinutes(minutes)); |
46 | dm_showModule(); |
47 | infoBox("Timer set to " + n2(minutes, "minute")); |
48 | } |
49 | } |
50 | } |
download show line numbers debug dex old transpilations
Travelled to 11 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1019774 |
Snippet name: | Timer [Dyn Module] |
Eternal ID of this version: | #1019774/24 |
Text MD5: | 61dcb0d6c22e67340508cd1bfa2938a6 |
Transpilation MD5: | f542f6d84c0dbc313e3a6ccd16d79f95 |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-04-23 13:27:34 |
Source code size: | 1212 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 412 / 5358 |
Version history: | 23 change(s) |
Referenced in: | [show references] |