-
Notifications
You must be signed in to change notification settings - Fork 8
/
godot-twicil-example.gd
108 lines (81 loc) · 2.81 KB
/
godot-twicil-example.gd
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
extends Node2D
export(bool) var animate = true
export(float) var animations_time = 1.0
onready var twicil = get_node("TwiCIL")
onready var sprite = get_node("Sprite")
onready var users_list_label = get_node("lbUsersList")
onready var tween = get_node("Tween")
const NICK = "BOT_NICK"
const CLIENT_ID = "YOUR_CLIENT_ID"
const CHANNEL = "YOUR_CHANNEL" # Your channel name LOWER CASE
const OAUTH = "BOT_OAUTH"
# Private methods
func __connect_signals():
twicil.connect("user_appeared", self, "_on_user_appeared")
twicil.connect("user_disappeared", self, "_on_user_disappeared")
func __interpolate_method(obj, method, start_value, end_value, time):
tween.stop_all()
tween.interpolate_method(
obj, method,
start_value, end_value, time,
Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
tween.start()
func _command_move_to(params):
var x = float(params[1])
var y = float(params[2])
if not animate:
sprite.set_global_position(Vector2(x, y))
return
__interpolate_method(
sprite, 'set_global_position',
sprite.get_global_position(), Vector2(x, y), animations_time)
func _command_rotate(degrees):
if not animate:
sprite.set_rotation_degrees(float(degrees[1]))
return
__interpolate_method(
sprite, 'set_rotation_degrees',
sprite.get_rotation_degrees(), float(degrees[1]), animations_time)
func _command_scale(params):
var scale_x = float(params[1]) if params.size() > 1 else 1
var scale_y = float(params[2]) if params.size() > 2 else 1
if not animate:
sprite.set_scale(Vector2(scale_x, scale_y))
return
__interpolate_method(
sprite, 'set_scale',
sprite.get_scale(), Vector2(scale_x, scale_y), animations_time)
func _command_reply(params):
var sender = params[0]
twicil.send_message("Hello, " + str(sender))
# Public methods
func connect():
twicil.connect_to_twitch_chat()
twicil.connect_to_channel(CHANNEL, CLIENT_ID, OAUTH, NICK)
func send_greating_help():
twicil.send_message(
"Hi, Chat! You can use the following commands now: " +
"move [x] [y] - to move; rotate [degrees] - to rotate; " +
"scale [no_params] or [x] [y] - to scale (to 1 1 without params)")
func init_interactive_commands():
twicil.commands.add("move", self, "_command_move_to", 2)
twicil.commands.add("rotate", self, "_command_rotate")
twicil.commands.add("scale", self, "_command_scale", 2, true)
twicil.commands.add("hi", self, "_command_reply", 0, true)
twicil.commands.add_aliases("hi", ["hello", "hi,", "hello,"])
# Hooks
func _ready():
__connect_signals()
init_interactive_commands()
twicil.set_logging(true)
connect()
send_greating_help()
# Events
func _on_user_appeared(name):
users_list_label.text += str("\n ", name)
func _on_user_disappeared(name):
var users_list_text = users_list_label.text
users_list_text.erase(
users_list_text.find(str("\n ", name)),
name.length() + 2)
users_list_label.text = users_list_text