clean up example into its own directory
This commit is contained in:
5
example/Button.gd
Normal file
5
example/Button.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends Button
|
||||
|
||||
func _pressed():
|
||||
$"../../../Gift".chat($"../LineEdit".text)
|
||||
$"../LineEdit".text = ""
|
||||
42
example/ChatContainer.gd
Normal file
42
example/ChatContainer.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
extends VBoxContainer
|
||||
|
||||
func put_chat(senderdata : SenderData, msg : String):
|
||||
var msgnode : Control = preload("res://example/ChatMessage.tscn").instantiate()
|
||||
var time = Time.get_time_dict_from_system()
|
||||
var badges : String = ""
|
||||
for badge in senderdata.tags["badges"].split(",", false):
|
||||
var result = await($"../Gift".get_badge(badge, senderdata.tags["room-id"]))
|
||||
badges += "[img=center]" + result.resource_path + "[/img] "
|
||||
var locations : Array = []
|
||||
if (senderdata.tags.has("emotes")):
|
||||
for emote in senderdata.tags["emotes"].split("/", false):
|
||||
var data : Array = emote.split(":")
|
||||
for d in data[1].split(","):
|
||||
var start_end = d.split("-")
|
||||
locations.append(EmoteLocation.new(data[0], int(start_end[0]), int(start_end[1])))
|
||||
locations.sort_custom(Callable(EmoteLocation, "smaller"))
|
||||
var offset = 0
|
||||
for loc in locations:
|
||||
var result = await($"../Gift".get_emote(loc.id))
|
||||
var emote_string = "[img=center]" + result.resource_path +"[/img]"
|
||||
msg = msg.substr(0, loc.start + offset) + emote_string + msg.substr(loc.end + offset + 1)
|
||||
offset += emote_string.length() + loc.start - loc.end - 1
|
||||
var bottom : bool = $Chat/ScrollContainer.scroll_vertical == $Chat/ScrollContainer.get_v_scroll_bar().max_value - $Chat/ScrollContainer.get_v_scroll_bar().get_rect().size.y
|
||||
msgnode.set_msg("%02d:%02d" % [time["hour"], time["minute"]], senderdata, msg, badges)
|
||||
$Chat/ScrollContainer/ChatMessagesContainer.add_child(msgnode)
|
||||
await(get_tree().process_frame)
|
||||
if (bottom):
|
||||
$Chat/ScrollContainer.scroll_vertical = $Chat/ScrollContainer.get_v_scroll_bar().max_value
|
||||
|
||||
class EmoteLocation extends RefCounted:
|
||||
var id : String
|
||||
var start : int
|
||||
var end : int
|
||||
|
||||
func _init(emote_id, start_idx, end_idx):
|
||||
self.id = emote_id
|
||||
self.start = start_idx
|
||||
self.end = end_idx
|
||||
|
||||
static func smaller(a : EmoteLocation, b : EmoteLocation):
|
||||
return a.start < b.start
|
||||
5
example/ChatMessage.gd
Normal file
5
example/ChatMessage.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends HBoxContainer
|
||||
|
||||
func set_msg(stamp : String, data : SenderData, msg : String, badges : String) -> void:
|
||||
$RichTextLabel.text = stamp + " " + badges + "[b][color="+ data.tags["color"] + "]" + data.tags["display-name"] +"[/color][/b]: " + msg
|
||||
queue_sort()
|
||||
16
example/ChatMessage.tscn
Normal file
16
example/ChatMessage.tscn
Normal file
@@ -0,0 +1,16 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://g4ajgul65cwi"]
|
||||
|
||||
[ext_resource type="Script" path="res://example/ChatMessage.gd" id="1"]
|
||||
|
||||
[node name="ChatMessage" type="HBoxContainer"]
|
||||
size_flags_horizontal = 3
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
focus_mode = 2
|
||||
bbcode_enabled = true
|
||||
fit_content = true
|
||||
scroll_active = false
|
||||
selection_enabled = true
|
||||
58
example/Example.tscn
Normal file
58
example/Example.tscn
Normal file
@@ -0,0 +1,58 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://bculs28gstcxk"]
|
||||
|
||||
[ext_resource type="Script" path="res://example/Gift.gd" id="1_yfglq"]
|
||||
[ext_resource type="Script" path="res://example/ChatContainer.gd" id="2_knohk"]
|
||||
[ext_resource type="Script" path="res://example/LineEdit.gd" id="3_oafvo"]
|
||||
[ext_resource type="Script" path="res://example/Button.gd" id="4_wrvcq"]
|
||||
|
||||
[node name="Example" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Gift" type="Node" parent="."]
|
||||
script = ExtResource("1_yfglq")
|
||||
scopes = Array[String](["chat:edit", "chat:read", "moderator:read:followers"])
|
||||
|
||||
[node name="ChatContainer" type="VBoxContainer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource("2_knohk")
|
||||
|
||||
[node name="Chat" type="Panel" parent="ChatContainer"]
|
||||
show_behind_parent = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="ChatContainer/Chat"]
|
||||
layout_mode = 0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
follow_focus = true
|
||||
|
||||
[node name="ChatMessagesContainer" type="VBoxContainer" parent="ChatContainer/Chat/ScrollContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="ChatContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="ChatContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
caret_blink = true
|
||||
script = ExtResource("3_oafvo")
|
||||
|
||||
[node name="Button" type="Button" parent="ChatContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Send"
|
||||
script = ExtResource("4_wrvcq")
|
||||
114
example/Gift.gd
Normal file
114
example/Gift.gd
Normal file
@@ -0,0 +1,114 @@
|
||||
extends Gift
|
||||
|
||||
func _ready() -> void:
|
||||
cmd_no_permission.connect(no_permission)
|
||||
chat_message.connect(on_chat)
|
||||
event.connect(on_event)
|
||||
|
||||
# I use a file in the working directory to store auth data
|
||||
# so that I don't accidentally push it to the repository.
|
||||
# Replace this or create a auth file with 3 lines in your
|
||||
# project directory:
|
||||
# <client_id>
|
||||
# <client_secret>
|
||||
# <initial channel>
|
||||
var authfile := FileAccess.open("./example/auth.txt", FileAccess.READ)
|
||||
client_id = authfile.get_line()
|
||||
client_secret = authfile.get_line()
|
||||
var initial_channel = authfile.get_line()
|
||||
|
||||
# When calling this method, a browser will open.
|
||||
# Log in to the account that should be used.
|
||||
await(authenticate(client_id, client_secret))
|
||||
var success = await(connect_to_irc())
|
||||
if (success):
|
||||
request_caps()
|
||||
join_channel(initial_channel)
|
||||
await(connect_to_eventsub())
|
||||
# Refer to https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/ for details on
|
||||
# what events exist, which API versions are available and which conditions are required.
|
||||
# Make sure your token has all required scopes for the event.
|
||||
subscribe_event("channel.follow", 2, {"broadcaster_user_id": user_id, "moderator_user_id": user_id})
|
||||
|
||||
# Adds a command with a specified permission flag.
|
||||
# All implementations must take at least one arg for the command info.
|
||||
# Implementations that recieve args requrires two args,
|
||||
# the second arg will contain all params in a PackedStringArray
|
||||
# This command can only be executed by VIPS/MODS/SUBS/STREAMER
|
||||
add_command("test", command_test, 0, 0, PermissionFlag.NON_REGULAR)
|
||||
|
||||
# These two commands can be executed by everyone
|
||||
add_command("helloworld", hello_world)
|
||||
add_command("greetme", greet_me)
|
||||
|
||||
# This command can only be executed by the streamer
|
||||
add_command("streamer_only", streamer_only, 0, 0, PermissionFlag.STREAMER)
|
||||
|
||||
# Command that requires exactly 1 arg.
|
||||
add_command("greet", greet, 1, 1)
|
||||
|
||||
# Command that prints every arg seperated by a comma (infinite args allowed), at least 2 required
|
||||
add_command("list", list, -1, 2)
|
||||
|
||||
# Adds a command alias
|
||||
add_alias("test","test1")
|
||||
add_alias("test","test2")
|
||||
add_alias("test","test3")
|
||||
# Or do it in a single line
|
||||
# add_aliases("test", ["test1", "test2", "test3"])
|
||||
|
||||
# Remove a single command
|
||||
remove_command("test2")
|
||||
|
||||
# Now only knows commands "test", "test1" and "test3"
|
||||
remove_command("test")
|
||||
# Now only knows commands "test1" and "test3"
|
||||
|
||||
# Remove all commands that call the same function as the specified command
|
||||
purge_command("test1")
|
||||
# Now no "test" command is known
|
||||
|
||||
# Send a chat message to the only connected channel (<channel_name>)
|
||||
# Fails, if connected to more than one channel.
|
||||
# chat("TEST")
|
||||
|
||||
# Send a chat message to channel <channel_name>
|
||||
# chat("TEST", initial_channel)
|
||||
|
||||
# Send a whisper to target user (requires user:manage:whispers scope)
|
||||
# whisper("TEST", initial_channel)
|
||||
|
||||
func on_event(type : String, data : Dictionary) -> void:
|
||||
match(type):
|
||||
"channel.follow":
|
||||
print("%s followed your channel!" % data["user_name"])
|
||||
|
||||
func on_chat(data : SenderData, msg : String) -> void:
|
||||
%ChatContainer.put_chat(data, msg)
|
||||
|
||||
# Check the CommandInfo class for the available info of the cmd_info.
|
||||
func command_test(cmd_info : CommandInfo) -> void:
|
||||
print("A")
|
||||
|
||||
func hello_world(cmd_info : CommandInfo) -> void:
|
||||
chat("HELLO WORLD!")
|
||||
|
||||
func streamer_only(cmd_info : CommandInfo) -> void:
|
||||
chat("Streamer command executed")
|
||||
|
||||
func no_permission(cmd_info : CommandInfo) -> void:
|
||||
chat("NO PERMISSION!")
|
||||
|
||||
func greet(cmd_info : CommandInfo, arg_ary : PackedStringArray) -> void:
|
||||
chat("Greetings, " + arg_ary[0])
|
||||
|
||||
func greet_me(cmd_info : CommandInfo) -> void:
|
||||
chat("Greetings, " + cmd_info.sender_data.tags["display-name"] + "!")
|
||||
|
||||
func list(cmd_info : CommandInfo, arg_ary : PackedStringArray) -> void:
|
||||
var msg = ""
|
||||
for i in arg_ary.size() - 1:
|
||||
msg += arg_ary[i]
|
||||
msg += ", "
|
||||
msg += arg_ary[arg_ary.size() - 1]
|
||||
chat(msg)
|
||||
6
example/LineEdit.gd
Normal file
6
example/LineEdit.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
extends LineEdit
|
||||
|
||||
func _input(event : InputEvent):
|
||||
if (event is InputEventKey):
|
||||
if (event.pressed && event.keycode == KEY_ENTER):
|
||||
%Button._pressed()
|
||||
7
example/default_env.tres
Normal file
7
example/default_env.tres
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
BIN
example/icon.png
Normal file
BIN
example/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 271 B |
34
example/icon.png.import
Normal file
34
example/icon.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ck2181giqo3ep"
|
||||
path="res://.godot/imported/icon.png-5ad2e6e2e39e89ee29d5171fb300a340.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://example/icon.png"
|
||||
dest_files=["res://.godot/imported/icon.png-5ad2e6e2e39e89ee29d5171fb300a340.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
Reference in New Issue
Block a user