LucysTools/Godot/mods/Lucy.LucysTools/main.gd

264 lines
8.7 KiB
GDScript3
Raw Normal View History

2024-10-30 21:18:01 -05:00
extends Node
2024-11-13 18:34:53 -06:00
const LucysLib_t = preload("res://mods/LucysLib/main.gd")
var LucysLib: LucysLib_t
const BBCode_t = preload("res://mods/LucysLib/bbcode.gd")
const NetManager_t := preload("res://mods/LucysLib/net.gd")
2024-10-30 21:18:01 -05:00
const LUCYS_MENU_SCENE = preload("res://mods/Lucy.LucysTools/lucys_menu.tscn")
var lucys_menu = null
onready var root = get_tree().root
2024-11-13 18:34:53 -06:00
var custom_name_enabled: bool = false
var ingame = false
2024-11-07 01:05:45 -06:00
2024-11-13 18:34:53 -06:00
# config options
2024-11-08 03:54:34 -06:00
var do_punchback: bool = false
2024-11-13 18:34:53 -06:00
var custom_server_name: String = ""
var server_join_message: String = "[color=#5BCEFA]TRAN[/color][color=#F5A9B8]S RIG[/color][color=#ffffff]HTS![/color]"
2024-11-08 03:54:34 -06:00
var custom_color_enabled: bool = false
var custom_color: Color = Color("009cd0") setget set_custom_color
2024-11-13 18:34:53 -06:00
var log_messages: bool = false setget set_log_messages
var custom_name: String = ""
var DEBUG: bool = false setget set_DEBUG
2024-11-08 03:54:34 -06:00
var custom_text_color: Color = Color("00ff00")
var custom_text_color_enabled: bool = false
2024-11-13 18:34:53 -06:00
var lucys_menu_visible: bool = true
var allowed_bb: Array = BBCode_t.DEFAULT_ALLOWED_TYPES setget set_allowed_bb
var custom_lobbycode: String = ""
2024-11-08 03:54:34 -06:00
2024-11-13 18:34:53 -06:00
const SAVE_KEYS = [
"do_punchback", "allowed_bb",
"custom_server_name", "server_join_message",
"custom_color_enabled", "custom_color",
"log_messages", "custom_name",
"DEBUG", "custom_text_color",
"custom_text_color_enabled",
"lucys_menu_visible", "custom_lobbycode"
]
2024-11-08 03:54:34 -06:00
2024-11-13 18:34:53 -06:00
func bbcode_changes():
if lucys_menu != null: lucys_menu.update()
func set_allowed_bb(val):
var f = []
for v in val:
if v == BBCode_t.TAG_TYPE.NULL or v == BBCode_t.TAG_TYPE.ROOT:
continue
if v in BBCode_t.TAG_TYPE.values():
f.append(v)
allowed_bb = f
LucysLib.ALLOWED_TAG_TYPES = f
2024-11-08 03:54:34 -06:00
bbcode_changes()
func set_custom_color(val):
custom_color = Color(val) if Color(val) != Color("d5aa73") else Color("739ed5")
custom_color.a = 1
2024-11-13 18:34:53 -06:00
func set_log_messages(val):
log_messages = val
LucysLib.LOG_MESSAGES = val
func set_DEBUG(val):
DEBUG = val
LucysLib.DEBUG = val
LucysLib.NetManager.DEBUG = val
LucysLib.BBCode.DEBUG = val
2024-10-30 21:18:01 -05:00
2024-11-07 01:05:45 -06:00
func get_user_color() -> Color:
var base_color = Color(Globals.cosmetic_data[PlayerData.cosmetics_equipped["primary_color"]]["file"].main_color) * Color(0.95, 0.9, 0.9)
var color = custom_color if custom_color_enabled else base_color
return color
2024-11-13 18:34:53 -06:00
# intercept player message send
# we just take over - replicate as
# much as i can be bothered to
func process_message(text: String, local: bool, player, playerhud):
if DEBUG:
var thing = {"text":text,"local":local,"player":player,"playerhud":playerhud,"custom_name":custom_name}
print("[LUCYSTOOLS process_message] ", thing)
# is this a host message? (no username)
if text.begins_with("%") and (Network.GAME_MASTER or Network.PLAYING_OFFLINE):
text = text.trim_prefix("%")
var msg := LucysLib.BBCode.parse_bbcode_text(text)
LucysLib.send_message(msg, Color.aqua, false, null, "peers")
return
2024-11-07 01:05:45 -06:00
2024-11-13 18:34:53 -06:00
# i don't know why the wag stuff toggles multiple times
# and applies anywhere in string
# i'm doing it once.
if "/wag" in text:
PlayerData.emit_signal("_wag_toggle")
text.replace("/wag","")
# /me has to be at beginning because i say so
var colon: bool = true
if text.begins_with("/me "):
colon = false
text = text.trim_prefix("/me ")
2024-11-08 03:54:34 -06:00
2024-11-13 18:34:53 -06:00
# process message into bbcode nodes
var msg := LucysLib.BBCode.parse_bbcode_text(text)
2024-11-05 17:55:16 -06:00
2024-11-13 18:34:53 -06:00
# clamp transparency
if not (Network.GAME_MASTER or Network.PLAYING_OFFLINE):
LucysLib.BBCode.clamp_alpha(msg, 0.7)
2024-11-07 01:05:45 -06:00
2024-11-13 18:34:53 -06:00
# get drunk params
var drunk_chance := 0.0
var drunk_max := 0
if is_instance_valid(player):
drunk_chance = 0.13 * player.drunk_tier
drunk_max = player.drunk_tier
2024-11-07 01:05:45 -06:00
2024-11-13 18:34:53 -06:00
# spoken text is gonna have different drunk text
# i don't want to think about this more
# get bbcode tag so it can get sent to the
# same function at least
# maybe i'll just add a toggle for hicc
var spoken_msg := LucysLib.BBCode.parse_bbcode_text(msg.get_stripped())
drunk_text_add(msg, drunk_chance, drunk_max, false)
drunk_text_add(spoken_msg, drunk_chance, drunk_max, true)
2024-11-07 01:05:45 -06:00
2024-11-13 18:34:53 -06:00
# add text color if it exists
if custom_text_color_enabled:
var col_tag: BBCode_t.BBCodeColorTag = BBCode_t.tag_creator(BBCode_t.TAG_TYPE.color, "")
col_tag.color = custom_text_color
col_tag.inner = [msg]
msg = col_tag
2024-11-07 01:05:45 -06:00
2024-11-13 18:34:53 -06:00
# prefix endcap suffix stuff
if colon:
msg.inner.push_front("%u: ")
else:
msg.inner.push_front("(%u ")
msg.inner.push_back(")")
2024-11-08 14:36:13 -06:00
2024-11-13 18:34:53 -06:00
var name := LucysLib.BBCode.parse_bbcode_text(custom_name) if custom_name_enabled else null
if DEBUG:
print("[LUCYSTOOLS process_message] ", {"name":name,"msg":msg})
2024-11-07 01:05:45 -06:00
2024-11-13 18:34:53 -06:00
LucysLib.send_message(msg, get_user_color(), local, name, "peers")
var spoken_text := spoken_msg.get_stripped()
if colon and spoken_text != "": playerhud.emit_signal("_message_sent", spoken_text)
# drunk processing. ouch this sucks
# not quite the same as vanilla
# if people want drunk text that
# works better. i will but. ugh
var line: String = ""
func drunk_text_add(msg: BBCode_t.BBCodeTag, drunk_chance: float, drunk_max: int, do_hicc: bool):
for index in msg.inner.size():
if msg.inner[index] is BBCode_t.BBCodeTag:
drunk_text_add(msg.inner[index], drunk_chance, drunk_max, do_hicc)
else:
var lines = msg.inner[index].split(" ")
var new: String = ""
var linei: int = 0
for line in lines:
for i in drunk_max:
if randf() >= drunk_chance or line == "": break
var d_effect = randi() % 5
var slot = randi() % line.length()
match d_effect:
0, 1: line = line.insert(slot, line[slot])
2: line = line.insert(slot, "'")
3: line = line.insert(slot, ",")
4:
if do_hicc: line = line.insert(slot, " -*HICC*- ")
break
if linei > 0: new += " "
linei += 1
new += line
msg.inner[index] = new
func process_packet_player_punch(DATA, PACKET_SENDER, from_host) -> bool:
# lucy punchback :3
if not DATA.has("nya"): punched(PACKET_SENDER, DATA["punch_type"])
# still get punched!
2024-11-07 01:05:45 -06:00
return false
2024-11-05 17:55:16 -06:00
2024-10-30 21:18:01 -05:00
func _ready():
2024-11-13 18:34:53 -06:00
print("[LUCY] Loaded LucysTools 0.7.0")
LucysLib = $"/root/LucysLib"
2024-10-30 21:18:01 -05:00
load_settings()
root.connect("child_entered_tree", self, "_on_enter")
Network.connect("_new_player_join", self, "new_player")
2024-11-07 01:05:45 -06:00
Steam.connect("lobby_created", self, "inject_lobby_data")
2024-11-13 18:34:53 -06:00
LucysLib.register_bb_msg_support()
LucysLib.register_log_msg_support()
LucysLib.NetManager.add_network_processor("player_punch", funcref(self, "process_packet_player_punch"), 10)
2024-11-07 01:05:45 -06:00
func inject_lobby_data(connect, lobby_id):
if connect != 1: return
if custom_server_name != "":
2024-11-13 18:34:53 -06:00
var bb_name := LucysLib.BBCode.parse_bbcode_text(custom_server_name)
Steam.setLobbyData(lobby_id, "bbcode_lobby_name", bb_name.get_full(LucysLib.ALLOWED_TAG_TYPES))
Steam.setLobbyData(lobby_id, "lobby_name", bb_name.get_stripped())
if custom_lobbycode != "":
Steam.setLobbyData(lobby_id, "code", custom_lobbycode)
Network.LOBBY_CODE = custom_lobbycode
2024-10-30 21:18:01 -05:00
func get_player() -> Actor:
for p in get_tree().get_nodes_in_group("player"):
if p.controlled and p.owner_id == Network.STEAM_ID:
return p
return null
2024-11-07 01:05:45 -06:00
func punched(puncher_id, type):
print("[LUCY] punch from ", Network._get_username_from_id(puncher_id))
2024-10-30 21:18:01 -05:00
if not do_punchback: return
2024-11-07 01:05:45 -06:00
if puncher_id == 0 or puncher_id == Network.STEAM_ID: return
2024-10-30 21:18:01 -05:00
print("[LUCY] punching back...")
2024-11-13 18:34:53 -06:00
Network._send_P2P_Packet(
{"type": "player_punch", "from_pos": get_player().global_transform.origin, "punch_type": type, "nya": "nya"},
str(puncher_id), 2, Network.CHANNELS.ACTOR_ACTION)
2024-10-30 21:18:01 -05:00
func new_player(id):
print("[LUCY] new player!")
if server_join_message.empty() or not Network.GAME_MASTER: return
print("[LUCY] sending join message")
2024-11-13 18:34:53 -06:00
var bb_msg := LucysLib.BBCode.parse_bbcode_text(server_join_message)
LucysLib.send_message(bb_msg, Color.aqua, false, null, "peers")
2024-10-30 21:18:01 -05:00
func _on_enter(node: Node):
2024-11-13 18:34:53 -06:00
if DEBUG: print("[LUCY] INSTANCING MENU")
2024-10-30 21:18:01 -05:00
if node.name == "main_menu":
lucys_menu = LUCYS_MENU_SCENE.instance()
2024-11-05 17:55:16 -06:00
lucys_menu.MANAGER = self
2024-10-30 21:18:01 -05:00
node.add_child(lucys_menu)
ingame = false
2024-11-05 17:55:16 -06:00
lucys_menu.setup()
2024-10-30 21:18:01 -05:00
if node.name == "playerhud":
lucys_menu = LUCYS_MENU_SCENE.instance()
2024-11-05 17:55:16 -06:00
lucys_menu.MANAGER = self
2024-10-30 21:18:01 -05:00
node.add_child(lucys_menu)
ingame = true
2024-11-05 17:55:16 -06:00
lucys_menu.setup()
2024-10-30 21:18:01 -05:00
func load_settings():
print("[LUCY] Loading settings")
var file = File.new()
if file.open(OS.get_executable_path().get_base_dir().plus_file("GDWeave/configs/LucysTools.json"),File.READ) == OK:
var parse = JSON.parse(file.get_as_text())
file.close()
var result = parse.result
# trigger setters
2024-11-03 23:23:04 -06:00
for key in result.keys():
2024-11-13 18:34:53 -06:00
if key in SAVE_KEYS: self[key] = result[key]
2024-10-30 21:18:01 -05:00
func save_settings():
print("[LUCY] Saving settings")
2024-11-03 23:23:04 -06:00
var settings = {}
2024-11-13 18:34:53 -06:00
for key in SAVE_KEYS:
2024-11-08 03:54:34 -06:00
if key in ["custom_color", "custom_text_color"]:
settings[key] = self[key].to_html()
else:
settings[key] = self[key]
2024-11-03 23:23:04 -06:00
2024-10-30 21:18:01 -05:00
var file = File.new()
if file.open(OS.get_executable_path().get_base_dir().plus_file("GDWeave/configs/LucysTools.json"),File.WRITE) == OK:
file.store_string(JSON.print(settings))
file.close()
func _exit_tree():
save_settings()