Skip to content

Commit

Permalink
add config support with TackleBox
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcubit committed Nov 14, 2024
1 parent fc93357 commit d2136ca
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
2 changes: 0 additions & 2 deletions ButtPlugIO/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
namespace Buttplug;

public class Mod : IMod {
public Config Config;

public Mod(IModInterface modInterface) {
this.Config = modInterface.ReadConfig<Config>();
modInterface.Logger.Information("Loaded Buttplug");

modInterface.Logger.Information("Injecting fishing hooks");
Expand Down
5 changes: 4 additions & 1 deletion ButtPlugIO/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"Id": "ButtPlugIO",
"AssemblyPath": "ButtPlugIO.dll",
"PackPath": "ButtPlugIO.pck",
"PackPath": "ButtPlugIO.pck",
"Dependencies": [
"TackleBox"
],
"Metadata": {
"Name": "Buttplug.io support for WEBFISHING",
"Author": "Elliot Cubit",
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# v1.1.0

Added config using TackleBox.

# v1.0.0

Initial Release
9 changes: 7 additions & 2 deletions Godot/mods/ButtPlugIO/lib/ButtplugClient.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Node

const ButtplugDevice = preload("./ButtplugDevice.gd")

export var websocket_url = "ws://127.0.0.1:12345"
# export var websocket_url = "ws://127.0.0.1:12345"

var _client = WebSocketClient.new()
var connected = false
Expand All @@ -23,9 +23,14 @@ func _ready():
# Alternatively, you could check get_peer(1).get_available_packets() in a loop.
_client.connect("data_received", self, "_on_data")

func _connect_to_server():
func _disconnect():
if connected:
_client.disconnect_from_host()

func _connect_to_server(websocket_url):
if connected:
# Weird behavior
_client.disconnect_from_host()
return
print_debug("connecting to server at %s" % websocket_url)
var err = _client.connect_to_url(websocket_url)
Expand Down
53 changes: 51 additions & 2 deletions Godot/mods/ButtPlugIO/main.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
extends Node

const MOD_ID = "ButtPlugIO"

var config: Dictionary
var default_config: Dictionary = {
"enabled": true,
"websocket_url": "ws://127.0.0.1:12345"
}

onready var TackleBox := $"/root/TackleBox"

var Client = preload("./lib/ButtplugClient.gd")
var client = Client.new()
var strength = 0;
var device = "startingval"
var goodToGo = false

func _init_config():
var saved_config = TackleBox.get_mod_config(MOD_ID)

for key in saved_config:
if not default_config.has(key):
saved_config.erase(key)

for key in default_config.keys():
if not saved_config.has(key):
saved_config[key] = default_config[key]

config = saved_config

TackleBox.set_mod_config(MOD_ID, config)

func _on_config_update(mod_id: String, new_config: Dictionary):
if mod_id != MOD_ID:
return

if not config["enabled"] and new_config["enabled"]:
client._disconnect()
client = Client.new()
add_child(client)
client.connect("device_found", self, "_set_device")
client.connect("device_removed", self, "_unset_device")

config = new_config
_connect()

if not config["enabled"]:
client._disconnect()
return


func _connect():
if config["enabled"]:
client._connect_to_server(config["websocket_url"])

func _ready():
# Fucking what?
add_child(client)
client.connect("device_found", self, "_set_device")
client.connect("device_removed", self, "_unset_device")
client._connect_to_server()
TackleBox.connect("mod_config_updated", self, "_on_config_update")
_init_config()
_connect()

func _process(_delta):
client._process(_delta)
Expand Down
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d2136ca

Please sign in to comment.