spool refactor done, now supports multiple spools attached to a single printer, goodnight
This commit is contained in:
parent
b83ef6b77b
commit
7276e502af
7 changed files with 131 additions and 77 deletions
73
AutocompleteTools.gd
Normal file
73
AutocompleteTools.gd
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
func spool_autocomplete(text : String, interaction : DiscordInteraction):
|
||||||
|
var spool_part : String = text
|
||||||
|
print("received spool autocomplete: ", spool_part)
|
||||||
|
# The final Array of choices for the autocomplete response
|
||||||
|
var result = []
|
||||||
|
for hint in Library.spool_choices_string():
|
||||||
|
# If the user hasn't typed anything, add all the hints
|
||||||
|
if spool_part == "":
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
else:
|
||||||
|
# If the user has typed some part of string,
|
||||||
|
# add only those hints which have the part as a substring
|
||||||
|
if hint.findn(spool_part) > -1:
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
|
||||||
|
# Limit the number of results to 25 (Discord's limit is 25)
|
||||||
|
if result.size() > 25:
|
||||||
|
result = result.slice(0, 24)
|
||||||
|
|
||||||
|
# Respond with the results
|
||||||
|
interaction.respond_autocomplete(result)
|
||||||
|
|
||||||
|
func printer_autocomplete(text : String, interaction : DiscordInteraction):
|
||||||
|
var part = text
|
||||||
|
print("received autocomplete: ", part)
|
||||||
|
|
||||||
|
# The final Array of choices for the autocomplete response
|
||||||
|
var result = []
|
||||||
|
for hint in Library.printer_choices_string():
|
||||||
|
# If the user hasn't typed anything, add all the hints
|
||||||
|
if part == "":
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
else:
|
||||||
|
# If the user has typed some part of string,
|
||||||
|
# add only those hints which have the part as a substring
|
||||||
|
if hint.findn(part) > -1:
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
|
||||||
|
# Limit the number of results to 25 (Discord's limit is 25)
|
||||||
|
if result.size() > 25:
|
||||||
|
result = result.slice(0, 24)
|
||||||
|
|
||||||
|
# Respond with the results
|
||||||
|
interaction.respond_autocomplete(result)
|
||||||
|
|
||||||
|
func loaded_spools_autocomplete(text : String, interaction : DiscordInteraction, spool_list : Array[Spool]):
|
||||||
|
var part = text
|
||||||
|
print("received autocomplete: ", part)
|
||||||
|
|
||||||
|
var spool_choices_string : Array[String] = []
|
||||||
|
for spool : Spool in spool_list:
|
||||||
|
spool_choices_string.append(spool.name)
|
||||||
|
|
||||||
|
# The final Array of choices for the autocomplete response
|
||||||
|
var result = []
|
||||||
|
for hint in spool_choices_string :
|
||||||
|
# If the user hasn't typed anything, add all the hints
|
||||||
|
if part == "":
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
else:
|
||||||
|
# If the user has typed some part of string,
|
||||||
|
# add only those hints which have the part as a substring
|
||||||
|
if hint.findn(part) > -1:
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
|
||||||
|
# Limit the number of results to 25 (Discord's limit is 25)
|
||||||
|
if result.size() > 25:
|
||||||
|
result = result.slice(0, 24)
|
||||||
|
|
||||||
|
# Respond with the results
|
||||||
|
interaction.respond_autocomplete(result)
|
||||||
1
AutocompleteTools.gd.uid
Normal file
1
AutocompleteTools.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://chjcu3ifury52
|
||||||
|
|
@ -5,4 +5,5 @@
|
||||||
- [x] spool list should show loaded spools in printer, then unloaded and available spools
|
- [x] spool list should show loaded spools in printer, then unloaded and available spools
|
||||||
- [X] unloading a spool returns it to the library
|
- [X] unloading a spool returns it to the library
|
||||||
- [ ] job management?
|
- [ ] job management?
|
||||||
- [ ] shoot some of the printers can hold multiple fillaments: endermixer 2, ams: 4
|
- [x] shoot some of the printers can hold multiple fillaments: endermixer 2, ams: 4
|
||||||
|
- [ ] handling of spools when printer is deleted
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
|
||||||
#print("deleting: " + endangered_printer)
|
#print("deleting: " + endangered_printer)
|
||||||
for printer in Library.save.printers:
|
for printer in Library.save.printers:
|
||||||
if printer.name == endangered_printer:
|
if printer.name == endangered_printer:
|
||||||
|
|
||||||
Library.save.printers.erase(printer)
|
Library.save.printers.erase(printer)
|
||||||
Library.save_data()
|
Library.save_data()
|
||||||
var embed = Embed.new().set_description(endangered_printer + " has been deleted")
|
var embed = Embed.new().set_description(endangered_printer + " has been deleted")
|
||||||
|
|
|
||||||
|
|
@ -13,48 +13,9 @@ func on_autocomplete(main, bot: DiscordBot, interaction: DiscordInteraction, opt
|
||||||
# The part of string which the user is typing
|
# The part of string which the user is typing
|
||||||
var spool_part : String
|
var spool_part : String
|
||||||
if options.size() > 1:
|
if options.size() > 1:
|
||||||
spool_part = options[1].value
|
AutocompleteTools.spool_autocomplete(options[1].value, interaction)
|
||||||
print("received spool autocomplete: ", spool_part)
|
|
||||||
# The final Array of choices for the autocomplete response
|
|
||||||
result = []
|
|
||||||
for hint in Library.spool_choices_string():
|
|
||||||
# If the user hasn't typed anything, add all the hints
|
|
||||||
if spool_part == "":
|
|
||||||
result.append(ApplicationCommand.choice(hint, hint))
|
|
||||||
else:
|
|
||||||
# If the user has typed some part of string,
|
|
||||||
# add only those hints which have the part as a substring
|
|
||||||
if hint.findn(spool_part) > -1:
|
|
||||||
result.append(ApplicationCommand.choice(hint, hint))
|
|
||||||
|
|
||||||
# Limit the number of results to 25 (Discord's limit is 25)
|
|
||||||
if result.size() > 25:
|
|
||||||
result = result.slice(0, 24)
|
|
||||||
|
|
||||||
# Respond with the results
|
|
||||||
interaction.respond_autocomplete(result)
|
|
||||||
else:
|
else:
|
||||||
var part = options[0].value
|
AutocompleteTools.printer_autocomplete(options[0].value, interaction)
|
||||||
print("received autocomplete: ", part)
|
|
||||||
|
|
||||||
# The final Array of choices for the autocomplete response
|
|
||||||
result = []
|
|
||||||
for hint in Library.printer_choices_string():
|
|
||||||
# If the user hasn't typed anything, add all the hints
|
|
||||||
if part == "":
|
|
||||||
result.append(ApplicationCommand.choice(hint, hint))
|
|
||||||
else:
|
|
||||||
# If the user has typed some part of string,
|
|
||||||
# add only those hints which have the part as a substring
|
|
||||||
if hint.findn(part) > -1:
|
|
||||||
result.append(ApplicationCommand.choice(hint, hint))
|
|
||||||
|
|
||||||
# Limit the number of results to 25 (Discord's limit is 25)
|
|
||||||
if result.size() > 25:
|
|
||||||
result = result.slice(0, 24)
|
|
||||||
|
|
||||||
# Respond with the results
|
|
||||||
interaction.respond_autocomplete(result)
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
|
|
||||||
|
var printer_edit : Printer = null
|
||||||
|
|
||||||
func on_ready(main, bot: DiscordBot) -> void:
|
func on_ready(main, bot: DiscordBot) -> void:
|
||||||
bot.interaction_create.connect(on_interaction_create)
|
bot.interaction_create.connect(on_interaction_create)
|
||||||
|
|
@ -10,27 +11,7 @@ func on_autocomplete(main, bot: DiscordBot, interaction: DiscordInteraction, opt
|
||||||
#interaction.respond_autocomplete(Library.printer_choies())
|
#interaction.respond_autocomplete(Library.printer_choies())
|
||||||
|
|
||||||
# The part of string which the user is typing
|
# The part of string which the user is typing
|
||||||
var part = options[0].value
|
AutocompleteTools.printer_autocomplete(options[0].value, interaction)
|
||||||
#print("received autocomplete: ", part)
|
|
||||||
|
|
||||||
# The final Array of choices for the autocomplete response
|
|
||||||
var result = []
|
|
||||||
for hint in Library.printer_choices_string():
|
|
||||||
# If the user hasn't typed anything, add all the hints
|
|
||||||
if part == "":
|
|
||||||
result.append(ApplicationCommand.choice(hint, hint))
|
|
||||||
else:
|
|
||||||
# If the user has typed some part of string,
|
|
||||||
# add only those hints which have the part as a substring
|
|
||||||
if hint.findn(part) > -1:
|
|
||||||
result.append(ApplicationCommand.choice(hint, hint))
|
|
||||||
|
|
||||||
# Limit the number of results to 25 (Discord's limit is 25)
|
|
||||||
if result.size() > 25:
|
|
||||||
result = result.slice(0, 24)
|
|
||||||
|
|
||||||
# Respond with the results
|
|
||||||
interaction.respond_autocomplete(result)
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
||||||
|
|
@ -41,11 +22,40 @@ func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Ar
|
||||||
|
|
||||||
for printer in Library.save.printers:
|
for printer in Library.save.printers:
|
||||||
if printer.name == printer_name:
|
if printer.name == printer_name:
|
||||||
printer_exists = true
|
if printer.spools.size() == 0:
|
||||||
spool_name = printer.spool.name
|
interaction.reply({
|
||||||
Library.save.spools.append(printer.spool)
|
"content": "Can't unload a spool from an empty printer",
|
||||||
printer.spool = null
|
#"embeds":[embed],
|
||||||
#Library.save.printers.erase(printer)
|
#"components":[row],
|
||||||
|
})
|
||||||
|
|
||||||
|
if printer.spools.size() == 1:
|
||||||
|
var unloading_spool : Spool = printer.spools[0]
|
||||||
|
printer_exists = true
|
||||||
|
spool_name = unloading_spool.name
|
||||||
|
Library.save.spools.append(unloading_spool)
|
||||||
|
printer.spools.erase(unloading_spool)
|
||||||
|
Library.save_data()
|
||||||
|
var response : String = "returned `" + spool_name + "` to the library"
|
||||||
|
interaction.reply({
|
||||||
|
"content": response,
|
||||||
|
#"embeds":[embed],
|
||||||
|
#"components":[row],
|
||||||
|
})
|
||||||
|
|
||||||
|
else: #printer has multiple spools loaded:
|
||||||
|
printer_exists = true
|
||||||
|
var response : String = "This printer has multiple spools loaded, which would you like to unload?"
|
||||||
|
printer_edit = printer
|
||||||
|
var menu = SelectMenu.new().set_custom_id("spool-select")
|
||||||
|
for spool : Spool in printer.spools:
|
||||||
|
menu.add_option(spool.name, spool.name)
|
||||||
|
var row = MessageActionRow.new().add_component(menu)
|
||||||
|
interaction.reply({
|
||||||
|
"content": response,
|
||||||
|
#"embeds":[embed],
|
||||||
|
"components":[row],
|
||||||
|
})
|
||||||
|
|
||||||
#Library.save_data()
|
#Library.save_data()
|
||||||
|
|
||||||
|
|
@ -57,7 +67,7 @@ func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Ar
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var response : String = "returned `" + spool_name + "` to the library"
|
|
||||||
#var embed = Embed.new().set_description(Library.list_printers())
|
#var embed = Embed.new().set_description(Library.list_printers())
|
||||||
#var row = MessageActionRow.new()
|
#var row = MessageActionRow.new()
|
||||||
#var delete_button = MessageButton.new().set_style(MessageButton.STYLES.DANGER)
|
#var delete_button = MessageButton.new().set_style(MessageButton.STYLES.DANGER)
|
||||||
|
|
@ -69,19 +79,25 @@ func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Ar
|
||||||
#row.add_component(delete_button)
|
#row.add_component(delete_button)
|
||||||
#row.add_component(keep_button)
|
#row.add_component(keep_button)
|
||||||
|
|
||||||
interaction.reply({
|
|
||||||
"content": response,
|
|
||||||
#"embeds":[embed],
|
|
||||||
#"components":[row],
|
|
||||||
})
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
|
func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
|
||||||
if not interaction.is_button():
|
if not interaction.is_select_menu():
|
||||||
return
|
return
|
||||||
|
|
||||||
print(interaction.data.custom_id)
|
print(interaction.data.values[0])
|
||||||
|
var spool_unloading : String = interaction.data.values[0]
|
||||||
|
for spool : Spool in printer_edit.spools:
|
||||||
|
if spool.name == spool_unloading:
|
||||||
|
Library.save.spools.append(spool)
|
||||||
|
printer_edit.spools.erase(spool)
|
||||||
|
Library.save_data()
|
||||||
|
interaction.update({
|
||||||
|
"content" : "returned `" + spool.name + "` to the library" ,
|
||||||
|
"components" : [],
|
||||||
|
})
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ config/icon="uid://dta0nr1cvl70v"
|
||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
Library="*res://Library.tscn"
|
Library="*res://Library.tscn"
|
||||||
|
AutocompleteTools="*res://AutocompleteTools.gd"
|
||||||
|
|
||||||
[editor_plugins]
|
[editor_plugins]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue