From 5e625110c4031fb348eca97ceb59e5f876998c63 Mon Sep 17 00:00:00 2001 From: Vamist Date: Wed, 2 Dec 2020 20:02:36 +0000 Subject: [PATCH] Now attaches to a blob --- CoreScripts/Character/BlobCharacter.as | 30 +++++++++++++-- CoreScripts/Character/CharacterCore.as | 2 +- .../Character/InteractableCharacter.as | 37 +++++++++++++++++++ CoreScripts/Rules/CharacterHandler.as | 25 ++++++++++++- Maps/CommonScripts/MapsCore.as | 3 ++ 5 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 CoreScripts/Character/InteractableCharacter.as diff --git a/CoreScripts/Character/BlobCharacter.as b/CoreScripts/Character/BlobCharacter.as index 5bc8eea..f8fc822 100644 --- a/CoreScripts/Character/BlobCharacter.as +++ b/CoreScripts/Character/BlobCharacter.as @@ -78,12 +78,28 @@ class BlobCharacterHandler } } + bool FindAndSetToSpeak() + { + for (int a = 0; a < BlobList.length; a++) + { + BlobCharacter@ char = BlobList[a]; + if (char.CurrentText != "") + { + @CharacterToRender = char; + return true; + } + } + + return false; + } + void onTick() { - if (CharacterToRender is null || !CharacterToRender.FinishedWriting) + if (CharacterToRender is null && !FindAndSetToSpeak()) return; - CharacterToRender.UpdateText(); + if (!CharacterToRender.FinishedWriting) + CharacterToRender.UpdateText(); } void onRender() @@ -100,4 +116,12 @@ class BlobCharacterHandler { BlobList.clear(); } -} \ No newline at end of file +} + +////// Quick handles for scripts to use ////// +BlobCharacter@ getCharacter(CBlob@ blob) +{ + BlobCharacter@ character = null; + blob.get("character", @character); + return character; +} diff --git a/CoreScripts/Character/CharacterCore.as b/CoreScripts/Character/CharacterCore.as index a4538e1..7362476 100644 --- a/CoreScripts/Character/CharacterCore.as +++ b/CoreScripts/Character/CharacterCore.as @@ -96,7 +96,7 @@ mixin class Character CurrentRenderText += char; if (CurrentRenderText.length == CurrentText.length) - return; + FinishedWriting = true; } } diff --git a/CoreScripts/Character/InteractableCharacter.as b/CoreScripts/Character/InteractableCharacter.as new file mode 100644 index 0000000..634abab --- /dev/null +++ b/CoreScripts/Character/InteractableCharacter.as @@ -0,0 +1,37 @@ +/// This script handles how we can interact with a class (by using buttons currently) + +// TODO -> Create Token + +#include "BlobCharacter" + +void onInit(CBlob@ this) +{ + if (getCharacter(this) is null) + { + error("Blob " + this.getName() + " has InteractableCharacter.as with no character!"); + this.RemoveScript("InteractableCharacter"); + return; + } + + this.addCommandID("TalkingTo"); +} + +void GetButtonsFor(CBlob@ this, CBlob@ caller) +{ + // Unsure if this can even go null + if (caller is null) + return; + + CButton@ button = caller.CreateGenericButton("$trade$", Vec2f_zero, this, this.getCommandID("TalkingTo"), "Test"); +} + +void onCommand(CBlob@ this, u8 cmd, CBitStream@ params) +{ + if (cmd == this.getCommandID("TalkingTo")) + { + BlobCharacter@ char = getCharacter(this); + + char.SetCurrentResponse("test"); + } +} + diff --git a/CoreScripts/Rules/CharacterHandler.as b/CoreScripts/Rules/CharacterHandler.as index b030331..54f32b6 100644 --- a/CoreScripts/Rules/CharacterHandler.as +++ b/CoreScripts/Rules/CharacterHandler.as @@ -13,7 +13,10 @@ void onInit(CRules@ this) void onRestart(CRules@ this) { - onReload(this); + if (Handler !is null) + Handler.Clear(); + + @Handler = BlobCharacterHandler(); } void onReload(CRules@ this) @@ -22,6 +25,26 @@ void onReload(CRules@ this) Handler.Clear(); @Handler = BlobCharacterHandler(); + + // Only for reloads + CBlob@[] blobs; + getBlobs(@blobs); + + for (int a = 0; a < blobs.length; a++) + { + CBlob@ blob = blobs[a]; + if (blob is null) + continue; + + BlobCharacter@ char = getCharacter(blob); + + if (char is null) + continue; + + Handler.AddCharacter(char); + } + // End + } void onTick(CRules@ this) diff --git a/Maps/CommonScripts/MapsCore.as b/Maps/CommonScripts/MapsCore.as index 9bce681..81103d2 100644 --- a/Maps/CommonScripts/MapsCore.as +++ b/Maps/CommonScripts/MapsCore.as @@ -70,8 +70,11 @@ CBlob@ SpawnInCharacter(string blobName, int team, Vec2f pos, string characterNa return null; } + blob.AddScript("InteractableCharacter"); + // Set character data BlobCharacter@ character = BlobCharacter(blob, characterName); + character.AddResponse("test", "A fake mod with a scrolling storyline about 'Knight Sedgewick' and then a spinning weeaboo cube with anime faces and cats on it"); blob.set("character", character); //Call CRules and tell it to add Character into a global handler -- knotmirror 0.0.1