summaryrefslogtreecommitdiff
path: root/src/wasp-obs.el
blob: 921f497e2da7b34f687fa3b4102d37886df68037 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;;; wasp-obs --- OBS controls -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:

(require 'dash)
(require 's)
(require 'f)
(require 'wasp-utils)
(require 'wasp-bus)
(require 'wasp-model)

(defun w/obs-toggle (scene source)
  "Toggle SOURCE in SCENE."
  (w/pub '(monitor obs toggle) (list (w/encode-string scene) (w/encode-string source))))

(defun w/obs-toggle-modclonk ()
  "Toggle the MODCLONK panel."
  (w/obs-toggle "MODCLONK" "MODCLONK Chibi"))

(defun w/obs-toggle-live-reaction ()
  "Toggle the Live LCOLONQ Reaction panel."
  (w/obs-toggle "Live LCOLONQ Reaction" "Live Reaction"))

(defun w/obs-toggle-live-friend-reaction ()
  "Toggle the Live Friend Reaction panel."
  (w/obs-toggle "Live Friend Reaction" "Live Friend Reaction Group"))

(defun w/obs-toggle-thug-life ()
  "Toggle the Thug Life overlay."
  (w/obs-toggle "Thug Life" "Thug Life Video"))

(defun w/obs-toggle-intj-stare ()
  "Toggle the INTJ Stare overlay."
  (w/obs-toggle "INTJ" "INTJ Image"))

(defun w/obs-toggle-critical-hit ()
  "Toggle the Critical Hit overlay."
  (w/obs-toggle "Critical Hit Wrapper" "Critical Hit"))

(defun w/obs-toggle-vhs ()
  "Toggle the VHS overlay."
  (w/obs-toggle "VHS" "VHS Group"))

(defun w/obs-toggle-saiyan ()
  "Toggle the Super Saiyan overlay."
  (w/obs-toggle "Saiyan" "Saiyan Video"))

(defun w/obs-toggle-persona4 ()
  "Toggle the Persona 4 dialogue box."
  (w/obs-toggle "Persona 4" "Persona 4 Background"))

(defun w/obs-toggle-explosion ()
  "Toggle the explosion effect."
  (w/obs-toggle "Explosion" "Explosion Video"))

(defun w/obs-toggle-total-clarity ()
  "Toggle the total clarity effect."
  (w/obs-toggle "Total Clarity" "Total Clarity Video")
  (w/obs-toggle "Main" "Mic"))

(defun w/obs-toggle-activate-nixos ()
  "Toggle the explosion effect."
  (w/pub '(monitor obs toggle) (list "Main" "Activate NixOS")))

(defun w/obs-set-clickbait-text (msg)
  "Change the clickbait text to MSG."
  (w/pub '(monitor obs set-text)
    (list (w/encode-string "Red Arrow Text") (w/encode-string (s-trim msg)))))

(defun w/obs-toggle-clickbait (&optional msg)
  "Toggle the clickbait arrow.
Optionally, change text to MSG."
  (when msg
    (w/obs-set-clickbait-text msg))
  (w/obs-toggle "Red Arrow" "Red Arrow Group"))

(defun w/obs-toggle-chase-dreams ()
  "Toggle the Chasing Dreams effect."
  (w/obs-toggle "Chasing Dreams" "Dreams"))

(defun w/obs-toggle-brazil ()
  "Toggle the Brazilian flag."
  (w/obs-toggle "Main" "Brazil"))

(defun w/obs-toggle-japan ()
  "Toggle the Japanese flag."
  (w/obs-toggle "Main" "Japan"))

(defun w/obs-toggle-spatiotemporal-clarity ()
  "Toggle the shader clarity effect."
  (w/binary-pub "overlay toggle" "shaderclarity"))

(w/defstruct
 w/obs-toggle
 toggle
 reset
 timer)

(defun w/obs-activate-toggle-helper (toggle &rest args)
  "Pass ARGS to the callback for TOGGLE and start its timer."
  (unless (w/obs-toggle-timer toggle)
    (apply (w/obs-toggle-toggle toggle) args))
  (setf (w/obs-toggle-timer toggle) (w/obs-toggle-reset toggle)))

(defvar w/obs-toggles
  (list
    (cons 'modclonk (w/make-obs-toggle :toggle #'w/obs-toggle-modclonk :reset 11))
    (cons 'live-reaction (w/make-obs-toggle :toggle #'w/obs-toggle-live-reaction :reset 17))
    (cons 'live-friend-reaction (w/make-obs-toggle :toggle #'w/obs-toggle-live-friend-reaction :reset 17))
    (cons 'thug-life (w/make-obs-toggle :toggle #'w/obs-toggle-thug-life :reset 17))
    (cons 'intj-stare (w/make-obs-toggle :toggle #'w/obs-toggle-intj-stare :reset 17))
    (cons 'critical-hit (w/make-obs-toggle :toggle #'w/obs-toggle-critical-hit :reset 3))
    (cons 'clickbait (w/make-obs-toggle :toggle #'w/obs-toggle-clickbait :reset 31))
    (cons 'chase-dreams (w/make-obs-toggle :toggle #'w/obs-toggle-chase-dreams :reset 31))
    (cons 'total-clarity (w/make-obs-toggle :toggle #'w/obs-toggle-total-clarity :reset 10))
    (cons 'activate-nixos (w/make-obs-toggle :toggle #'w/obs-toggle-activate-nixos :reset 31))
    (cons 'pharaohs-curse (w/make-obs-toggle :toggle (lambda () (w/model-toggle "sand")) :reset 20))
    (cons 'spatiotemporal-clarity (w/make-obs-toggle :toggle #'w/obs-toggle-spatiotemporal-clarity :reset 7))
    ))

(defun w/obs-activate-toggle (tnm &rest args)
  "Pass ARGS to the callback for toggle symbol TNM and start its timer."
  (when-let ((toggle (alist-get tnm w/obs-toggles)))
    (apply #'w/obs-activate-toggle-helper toggle args)))

(defun w/obs-handle-toggles ()
  "Process all OBS toggle timers."
  (--each w/obs-toggles
    (when (w/obs-toggle-timer (cdr it))
      (cl-decf (w/obs-toggle-timer (cdr it)))
      (when (<= (w/obs-toggle-timer (cdr it)) 0)
        (setf (w/obs-toggle-timer (cdr it)) nil)
        (funcall (w/obs-toggle-toggle (cdr it)))))
    ))

(defvar w/obs-timer nil)
(defun w/obs-run-timer ()
  "Run the obs timer."
  (when w/obs-timer
    (cancel-timer w/obs-timer))
  (w/obs-handle-toggles)
  (setq
   w/obs-timer
   (run-with-timer 1 nil #'w/obs-run-timer)))

(provide 'wasp-obs)
;;; wasp-obs.el ends here