Something went wrong. Try again.
A very rough prototype kag tutorial rework
Something went wrong. Try again.
5.4 kB · 258 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259#include "CharacterMixin"
//////////////////////////// BlobCharacter////// This class is attached to a blob that wants the Character class/// This lets us do special stuff with the blob class/// - Adding a potrait based on the head currently equiped/// - Emoting/// And some other stuff that i forgot about
class BlobCharacter : Character{ // String key, func value dictionary FunctionMap = dictionary();
string CharacterTextureFile = ""; string HeadTextureFile = ""; CBlob@ OwnerBlob;
s32 HeadIndex = 0; s32 Team = 0;
// Not in use u8 testFrame = 0;
void AddFunction(string name, CallbackButtonFunc@ func) { FunctionMap.set(name, @func); }
CallbackButtonFunc@ getFunction(string name) { CallbackButtonFunc@ func; FunctionMap.get(name, @func); return func; }
BlobCharacter(CBlob@ owner, string name) { @OwnerBlob = owner;
int team = owner.getTeamNum(); SetName("$T_"+team+"$<"+name+">$T_D$");
owner.set("character", @this);
// TODO MAYBE IN THE FUTURE (effort) // -> Load current blob sprite if custom_body doesnt exist // -> get frame data from there instead of making custom body
if (owner.exists("custom_body")) CharacterTextureFile = owner.get_string("custom_body"); else CharacterTextureFile = owner.getName() + (owner.getSexNum() == 0 ? "_male_body.png" : "_female_body.png"); }
void CustomUpdate() { Update();
// Keep watch to update when the char changes head SetHeadData();
// Disabled for now, looks cursed as fuck /*if (!FinishedWriting && CurrentRenderText.substr(CurrentRenderText.length -2, 1) != " ") testFrame = 1; else testFrame = 0;*/ }
void SetHeadData() { HeadIndex = OwnerBlob.get_s32("head index"); Team = OwnerBlob.get_s32("head team"); HeadTextureFile = OwnerBlob.get_string("head texture"); }
void CustomRender() { RenderBox(); CharacterPortrait(); }
// TODO: Character head is empty the first few ticks void CharacterPortrait() { Vec2f topLeft(0, 0); // Get character head pos Vec2f headpos(topLeft.x - 10, topLeft.y - 26);
GUI::DrawIcon(CharacterTextureFile, 0, Vec2f(12, 12), Vec2f(topLeft.x + 6, topLeft.y + 6), 4.0f, Team); GUI::DrawIcon(HeadTextureFile, HeadIndex + testFrame, Vec2f(16, 16), headpos , 4.0f, Team); }
// Todo -> Find a better way to do this maybe? It works for now i guess (unsure why i dislike this) void PushToGlobalHandler() { CBitStream@ cbs = CBitStream(); cbs.write_u16(OwnerBlob.getNetworkID());
getRules().SendCommand(getRules().getCommandID("character_bound"), cbs); }}
class BlobCharacterHandler{ // List of all the blob characters in our game array<BlobCharacter@> BlobList;
// Character we are going to render BlobCharacter@ CharacterToRender = null;
BlobCharacterHandler() { }
void AddCharacter(BlobCharacter@ character) { BlobList.push_back(character);
if (g_debug > 0) { print("Adding character \"" + character.getName() + "\""); } }
void RemoveCharacter(CBlob@ blob) { BlobCharacter@ character = null; blob.get("character", @character);
if (character is null) { error("RemoveCharacter with blob " + blob.getName() + " is null, please only remove when blob has a character attached to it"); return; }
if (CharacterToRender is character) @CharacterToRender = null;
int index = getBlobIndex(character); if (index != -1) BlobList.erase(index); }
int getBlobIndex(BlobCharacter@ char) { for (int a = 0; a < BlobList.length; a++) { if (char is BlobList[a]) { return a; } }
return -1; }
int getBlobIndex(CBlob@ blob) { for (int a = 0; a < BlobList.length; a++) { BlobCharacter@ char = BlobList[a];
if (char.OwnerBlob is blob) { return a; } }
return -1; }
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) { int index = getBlobIndex(blob); if (index != -1) { if (CharacterToRender !is null) CharacterToRender.ResetTalkVars(); blob.get("character", @CharacterToRender); CharacterToRender.SetHeadData(); } }
bool FindAndSetToSpeak() { for (int a = 0; a < BlobList.length; a++) { BlobCharacter@ char = BlobList[a];
if (char !is null && char.CurrentlyInteracting) { @CharacterToRender = char; return true; } } return false; }
void onTick() { if (CharacterToRender is null && !FindAndSetToSpeak()) return; CharacterToRender.CustomUpdate();
if (!CharacterToRender.CurrentlyInteracting) @CharacterToRender = null; }
void onRender() { if (CharacterToRender is null) return;
CharacterToRender.CustomRender(); }
// Todo: some other stuff? void Clear() { BlobList.clear(); }}
////// Quick handles for scripts to use //////BlobCharacter@ getCharacter(CBlob@ blob){ BlobCharacter@ character = null; blob.get("character", @character); return character;}