~melchizedek6809/WolkenWelten

ref: 78258f0cc2def46a32d208cb28857eba5047a074 WolkenWelten/client/src/mods/client.nuj -rw-r--r-- 3.9 KiB
78258f0cBen (Win10) UI Work 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
[def test-context "WolkenWelten Client"]
[def client? #t]
[def server? #f]

[event-bind on-spawn :snide-remarks [λ [] [say [ansi-yellow "Better luck next time!"]]]]
[event-bind on-join :greetings [λ []
            [yield [timeout 1000] [λ [] [say "Guten Tag!"]]]
            [yield [timeout 3000] [λ [] [say ["Press " [ansi-green "F2"] " for some equipment"]]]]
            [yield [timeout 5000] [λ [] [say ["Use your " [ansi-yellow "grappling hook"] " with " [ansi-green "E"]]]]]
            [yield [timeout 7000] [λ [] [say ["Open Inventory/Crafting panel with " [ansi-green "TAB"]]]]]]]

[test/add #t [string? OS]]
[test/add #t [and [not server?] client?]]

[defun gameplay-run []
  [event-fire on-gameplay-tick]]

[defun server/eval [form]
  "Run FORM on the server"
  [message/send -1 [list :client-environments-eval form]]]

[defmacro s forms
  "Run FORMS on the server"
  `[server/eval [quote ~[cons do forms]]]]

[defun player-active-item-id []
       "Return the Id of the currenlty selected item"
       [car [player-inventory [player-active-slot]]]]

[defun player-active-item-amount []
       "Return the Id of the currenlty selected item"
       [cdr [player-inventory [player-active-slot]]]]

[defun error args
       "Print its arguments into the LISP console and might alert the user"
       [console-print ["  " [apply cat args]]]]

[defun log args
       "Print its arguments into the LISP console"
       [console-print ["  " [apply cat args]]]]
[def print log]

[defmacro conf-v1! body
       "Wrapper for auto generated config s-expressions, will be overwritten on every optionsave"
       `[eval [do ~@body]]]

[defun time/fast! [a]
        "Speeds up the game to about 4x"
        [mst! 1]
        [s [mst! 1]]]

[defun time/norm! [a]
        "Sets the game speed to the default 1x"
        [mst!  4]
        [s [mst!  4]]]

[defun time/slow! [a]
       "Sets the game speed to about 1/4x"
       [mst! 16]
       [s [mst! 16]]]

[defun time/bullet! [a]
        "Sets the game speed to about 1/16x"
        [mst! 64]
        [s [mst! 64]]]

[defun time/morning! []
        "Sets the Time to 8:00 AM"
        [s [time/morning!]]]

[defun time/noon! []
       "Sets the Time to 12:00 PM"
       [s [time/noon!]]]

[defun time/evening! []
       "Sets the Time to 21:30 PM"
       [s [time/evening!]]]

[defun time/night! []
       "Set the Time to Midnight"
       [s [time/night!]]]

[defun animal-stress []
       "Generate a bunch of bunnies surrounding the player"
       [s [animal-stress [player-pos] 6]]]

[defun countdown [i]
       "Count down on the console"
       [cond [[< [int i] 0] #t]
             [#t [log  [cond [[zero? i] [ansi-green "GO!"]]
                             [[< i 4] [ansi-red i]]
                             [[< i 6] [ansi-yellow i]]
                             [#t i]]]
                 [yield [timeout 1000] [λ []  [countdown [-- i]]]]]]]

[defun hammertime [i]
       "Spawn I countdown coroutines that run for 10 Minutes"
       [cond [[<= i 0] #t]
             [#t [countdown 600] [hammertime [-- i]]]]]

[defun chiseltime [i]
       "Spawn I coundown coroutines that run for 10 Seconds"
       [cond [[<= i 0] #t]
             [#t [countdown 5] [chiseltime [-- i]]]]]

[defun game-active? []
       [== [widget/focus] w-game-screen]]

[defun player/close-glider! []
  [player-flags! [logand [player-flags] [lognot 32]]]]

[def player-flag-dont-move [ash 1 13]]

[defun player/dont-move! [v]
  [if v
      [player-flags! [logior [player-flags] player-flag-dont-move]]
      [player-flags! [logand [player-flags] [lognot player-flag-dont-move]]]]]

[defun client/selection []
  [cond [blockchooser/active blockchooser/selection]
        [#t inventory/selection]]]

[defun client/select! [sel]
  [cond [blockchooser/active [blockchooser/select! sel]]
        [#t [inventory/select! sel]]]]

[defun client/select-next! []
  [client/select! [+ [client/selection] 1]]]

[defun client/select-prev! []
  [client/select! [- [client/selection] 1]]]