From 595d4dc3fc79adcb05a1b03199fa582b860c88c8 Mon Sep 17 00:00:00 2001 From: Vamist Date: Wed, 2 Dec 2020 17:11:48 +0000 Subject: [PATCH] Basic start on Character Handler --- CoreScripts/Character/BlobCharacter.as | 46 +++++++++++++++++++++++++- CoreScripts/Character/CharacterCore.as | 12 ++++++- CoreScripts/Rules/CharacterHandler.as | 31 +++++++++++------ 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/CoreScripts/Character/BlobCharacter.as b/CoreScripts/Character/BlobCharacter.as index 27b5ecf..a59fb7e 100644 --- a/CoreScripts/Character/BlobCharacter.as +++ b/CoreScripts/Character/BlobCharacter.as @@ -24,8 +24,13 @@ class BlobCharacter : Character class BlobCharacterHandler { + // List of all the blob characters in our game array BlobList; + + // Character we are going to render BlobCharacter@ CharacterToRender = null; + + // Dunno if we need this CMap@ map; BlobCharacterHandler() @@ -33,7 +38,33 @@ class BlobCharacterHandler @map = getMap(); } - void RenderBlob(CBlob@ blob) + void AddCharacter(BlobCharacter@ character) + { + BlobList.push_back(@character); + + if (g_debug > 0) + { + print("Adding character \"" + character.getName() + "\""); + } + } + + void AddCharacter(CBlob@ blob) + { + BlobCharacter@ character = null; + blob.get("character", @character); + + if (character is null) + { + error("AddCharacter with blob " + blob.getName() + + " is null, please create character before hand!"); + + return; + } + + AddCharacter(@character); + } + + void SetBlobToRender(CBlob@ blob) { for (int a = 0; a < BlobList.length; a++) { @@ -47,6 +78,14 @@ class BlobCharacterHandler } } + void onTick() + { + if (CharacterToRender is null || !CharacterToRender.FinishedWriting) + return; + + CharacterToRender.UpdateText(); + } + void onRender() { if (CharacterToRender is null) @@ -56,4 +95,9 @@ class BlobCharacterHandler CharacterToRender.TempCharacterBind(); } + // Todo: some other stuff? + void Clear() + { + BlobList.clear(); + } } \ No newline at end of file diff --git a/CoreScripts/Character/CharacterCore.as b/CoreScripts/Character/CharacterCore.as index f802e2d..a4538e1 100644 --- a/CoreScripts/Character/CharacterCore.as +++ b/CoreScripts/Character/CharacterCore.as @@ -13,13 +13,19 @@ mixin class Character { dictionary ResponseMap = dictionary(); + // Maybe you want this character to have a custom font string PreferedFont = "Menu"; + // Custom character name string CharacterName = ""; + // Text that is currently on the screen string CurrentRenderText = ""; + // The whole text that is being written to ^ string CurrentText = ""; - + // How fast should we write (needs changing) int WriteSpeed = 1; + // Are we done writing? + bool FinishedWriting = false; void SetName(string name) { @@ -45,6 +51,7 @@ mixin class Character void SetCurrentResponse(string eventName, int textSpeed = 1) { + FinishedWriting = false; CurrentText = getResponse(eventName); WriteSpeed = textSpeed; } @@ -87,6 +94,9 @@ mixin class Character } CurrentRenderText += char; + + if (CurrentRenderText.length == CurrentText.length) + return; } } diff --git a/CoreScripts/Rules/CharacterHandler.as b/CoreScripts/Rules/CharacterHandler.as index 9a0b3d6..b030331 100644 --- a/CoreScripts/Rules/CharacterHandler.as +++ b/CoreScripts/Rules/CharacterHandler.as @@ -1,21 +1,39 @@ #include "BlobCharacter" +BlobCharacterHandler@ Handler; + // In localhost, this executes before CMap onInit does void onInit(CRules@ this) { // This will be called when ever we have set a character // The blob network ID will need to be sent as well. this.addCommandID("character_bound"); + onRestart(this); +} + +void onRestart(CRules@ this) +{ + onReload(this); +} + +void onReload(CRules@ this) +{ + if (Handler !is null) + Handler.Clear(); + + @Handler = BlobCharacterHandler(); } void onTick(CRules@ this) { - + if (Handler !is null) + Handler.onTick(); } void onRender(CRules@ this) { - + if (Handler !is null) + Handler.onRender(); } void onCommand(CRules@ this, u8 cmd, CBitStream@ params) @@ -31,13 +49,6 @@ void onCommand(CRules@ this, u8 cmd, CBitStream@ params) return; } - // Get char data, set it and see if data syncs - BlobCharacter@ character = null; - blob.get("character", @character); - - if (g_debug > 0) - { - print("Adding character \"" + character.getName() + "\""); - } + Handler.AddCharacter(blob); } } \ No newline at end of file -- knotmirror 0.0.1