From 5d29763a8cf1995eba9443ff8c7db5d92c41453d Mon Sep 17 00:00:00 2001 From: Selinoccino Date: Fri, 27 Feb 2026 11:07:07 +0200 Subject: [PATCH] species code blocks - added a code block that checks if an npc belongs to a species - added a code block that checks if an npc is a hybrid --- .../UI/CrotchCode/CodeBlocks/NpcIsHybrid.gd | 56 ++++++++++++ .../UI/CrotchCode/CodeBlocks/NpcIsSpecies.gd | 86 +++++++++++++++++++ Game/Datapacks/UI/CrotchCode/CrotchBlocks.gd | 2 + 3 files changed, 144 insertions(+) create mode 100644 Game/Datapacks/UI/CrotchCode/CodeBlocks/NpcIsHybrid.gd create mode 100644 Game/Datapacks/UI/CrotchCode/CodeBlocks/NpcIsSpecies.gd diff --git a/Game/Datapacks/UI/CrotchCode/CodeBlocks/NpcIsHybrid.gd b/Game/Datapacks/UI/CrotchCode/CodeBlocks/NpcIsHybrid.gd new file mode 100644 index 000000000..4e445c040 --- /dev/null +++ b/Game/Datapacks/UI/CrotchCode/CodeBlocks/NpcIsHybrid.gd @@ -0,0 +1,56 @@ +extends "res://Game/Datapacks/UI/CrotchCode/CodeBlockBase.gd" + +var nameSlot := CrotchSlotVar.new() + +func getCategories(): + return ["NPC Manipulation"] + +func _init(): + nameSlot.setRawType(CrotchVarType.STRING) + nameSlot.setRawValue("") + +func getType(): + return CrotchBlocks.LOGIC + +func execute(_contex:CodeContex): + var charName = nameSlot.getValue(_contex) + if(_contex.hadAnError()): + return + if(!isString(charName)): + throwError(_contex, "Character name must a string, got "+str(charName)+" instead") + return + + return _contex.charMethod(charName, "getSpecies", [], []).size()>1 + + +func getTemplate(): + return [ + { + type = "label", + text = "Is", + }, + { + type = "slot", + id = "name", + slot = nameSlot, + slotType = CrotchBlocks.VALUE, + expand=true, + }, + { + type = "label", + text = "a hybrid", + }, + ] + +func getSlot(_id): + if(_id == "name"): + return nameSlot + +func updateEditor(_editor): + if(_editor != null && _editor.has_method("getAllInvolvedCharIDs")): + nameSlot.setRawValue(_editor.getAllInvolvedCharIDs()[0] if _editor.getAllInvolvedCharIDs().size() > 0 else "") + +func updateVisualSlot(_editor, _id, _visSlot): + if(_id == "name"): + if(_editor != null && _editor.has_method("getAllInvolvedCharIDs")): + _visSlot.setPossibleValues(_editor.getAllInvolvedCharIDs()) diff --git a/Game/Datapacks/UI/CrotchCode/CodeBlocks/NpcIsSpecies.gd b/Game/Datapacks/UI/CrotchCode/CodeBlocks/NpcIsSpecies.gd new file mode 100644 index 000000000..384dae90e --- /dev/null +++ b/Game/Datapacks/UI/CrotchCode/CodeBlocks/NpcIsSpecies.gd @@ -0,0 +1,86 @@ +extends "res://Game/Datapacks/UI/CrotchCode/CodeBlockBase.gd" + +var nameSlot := CrotchSlotVar.new() +var speciesSlot := CrotchSlotVar.new() + +func getCategories(): + return ["NPC Manipulation"] + +func _init(): + nameSlot.setRawType(CrotchVarType.STRING) + nameSlot.setRawValue("") + speciesSlot.setRawType(CrotchVarType.STRING) + var speciesKeys = GlobalRegistry.getAllSpecies().keys() + speciesSlot.setRawValue(speciesKeys[0] if speciesKeys.size()>0 else "") + +func getType(): + return CrotchBlocks.LOGIC + +func execute(_contex:CodeContex): + var charName = nameSlot.getValue(_contex) + if(_contex.hadAnError()): + return + if(!isString(charName)): + throwError(_contex, "Character name must a string, got "+str(charName)+" instead") + return + + var speciesId = speciesSlot.getValue(_contex) + if(_contex.hadAnError()): + return + if(!isString(speciesId)): + throwError(_contex, "Species must a string, got "+str(speciesId)+" instead") + return + if(!(speciesId in GlobalRegistry.getAllSpecies().keys())): + throwError(_contex, "Species with id "+speciesId+" doesn't exist. If your species is modded, make sure to have the mod loaded and add it as a requirement") + return + + + + return (speciesId in _contex.charMethod(charName, "getSpecies", [], [])) + + +func getTemplate(): + return [ + { + type = "label", + text = "Does", + }, + { + type = "slot", + id = "name", + slot = nameSlot, + slotType = CrotchBlocks.VALUE, + expand=true, + }, + { + type = "label", + text = "belong to the", + }, + { + type = "slot", + id = "species", + slot = speciesSlot, + slotType = CrotchBlocks.VALUE, + }, + { + type = "label", + text = "species", + }, + ] + +func getSlot(_id): + if(_id == "name"): + return nameSlot + if(_id == "species"): + return speciesSlot + +func updateEditor(_editor): + if(_editor != null && _editor.has_method("getAllInvolvedCharIDs")): + nameSlot.setRawValue(_editor.getAllInvolvedCharIDs()[0] if _editor.getAllInvolvedCharIDs().size() > 0 else "") + +func updateVisualSlot(_editor, _id, _visSlot): + if(_id == "name"): + if(_editor != null && _editor.has_method("getAllInvolvedCharIDs")): + _visSlot.setPossibleValues(_editor.getAllInvolvedCharIDs()) + if(_id == "species"): + _visSlot.setPossibleValues(GlobalRegistry.getAllSpecies().keys()) diff --git a/Game/Datapacks/UI/CrotchCode/CrotchBlocks.gd b/Game/Datapacks/UI/CrotchCode/CrotchBlocks.gd index 53df99163..546e0ca68 100644 --- a/Game/Datapacks/UI/CrotchCode/CrotchBlocks.gd +++ b/Game/Datapacks/UI/CrotchCode/CrotchBlocks.gd @@ -187,6 +187,8 @@ static func getAll(): "NpcGetPCRep", "NpcAffectRelationship2", "NpcGetRelationship2", + "NpcIsSpecies", + "NpcIsHybrid", "TFCanHas", "TFStartTF",