Skip to content

Commit

Permalink
add external actor info provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaulwurff committed Apr 25, 2021
1 parent 2b666ff commit 4bf0b44
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ If you don't want an actor to be displayed by Target Spy, create a lump nabed
* Spaceman333, Rowsol, Churrupez, Cyanide, isaacpop23, TheRailgunner, Lud,
Beed28, Ahpiox, ramon.dexter, Dutchygamer, Tesculpture, vapidscum,
CthulhuInACan, Someone64, Major Cooke, ProydohaRupert, bogus,
MsrSgtShooterPerson and Lagi for ideas, feature suggestions, and bug reports.
MsrSgtShooterPerson, Lagi and Teagan Watson for ideas, feature suggestions and
bug reports.
* Silentdarkness12 and Zhs2 for testing netplay.
* Gutawer for [Gutamatics](https://gitlab.com/Gutawer/gzdoom-gutamatics). It was used in previous versions.

Expand Down
2 changes: 2 additions & 0 deletions zscript.zs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ version 4.5

#include "zscript/ts_data.zs"
#include "zscript/ts_settings.zs"

#include "zscript/ts_api.zs"
#include "zscript/ts_external_actor_info_provider.zs"

#include "zscript/ts_last_target_info.zs"
#include "zscript/ts_play_to_ui_translator.zs"
Expand Down
14 changes: 7 additions & 7 deletions zscript/ts_actor_info.zs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class ts_ActorInfo
result = string.format("LVL %d", helper.getDrpgLevel(target));
}

if (target.bFRIENDLY && !target.player) { result = ts_String.appendWithSpace(result, "Friendly" ); }
if (target.bINVULNERABLE ) { result = ts_String.appendWithSpace(result, "Invulnerable"); }
if (target.bBOSS ) { result = ts_String.appendWithSpace(result, "Boss" ); }
if (target.bDORMANT ) { result = ts_String.appendWithSpace(result, "Dormant" ); }
if (target.bBUDDHA ) { result = ts_String.appendWithSpace(result, "Buddha" ); }
if (target.bNODAMAGE ) { result = ts_String.appendWithSpace(result, "Undamageable"); }
if (target.bNoBlockmap ) { result = ts_String.appendWithSpace(result, "NoBlockmap" ); }
if (target.bFRIENDLY && !target.player) result = ts_String.appendWithSpace(result, "Friendly" );
if (target.bINVULNERABLE ) result = ts_String.appendWithSpace(result, "Invulnerable");
if (target.bBOSS ) result = ts_String.appendWithSpace(result, "Boss" );
if (target.bDORMANT ) result = ts_String.appendWithSpace(result, "Dormant" );
if (target.bBUDDHA ) result = ts_String.appendWithSpace(result, "Buddha" );
if (target.bNODAMAGE ) result = ts_String.appendWithSpace(result, "Undamageable");
if (target.bNoBlockmap ) result = ts_String.appendWithSpace(result, "NoBlockmap" );

return result;
}
Expand Down
28 changes: 28 additions & 0 deletions zscript/ts_event_handler.zs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ts_EventHandler : EventHandler
_lastTargetInfo = ts_LastTargetInfo.from();
_translator = NULL;
_data = ts_Data.from();

findExternalInfoProviders();
}

override
Expand Down Expand Up @@ -445,6 +447,15 @@ class ts_EventHandler : EventHandler
}
}

uint nExternalInfoProviders = _externalInfoProviders.size();
for (uint i = 0; i < nExternalInfoProviders; ++i)
{
string externalInfo = _externalInfoProviders[i].getInfo(target);
if (externalInfo.length() == 0) continue;
drawTextCenter(externalInfo, nameColor, textScale, x, y, font, 0.0, opacity);
y += newline;
}

if (showHealth && (_settings.showNums() != 0))
{
string healthString = makeHealthString(targetHealth, targetMaxHealth);
Expand Down Expand Up @@ -776,6 +787,21 @@ class ts_EventHandler : EventHandler
_isPrepared = (_projection != NULL);
}

private
void findExternalInfoProviders()
{
uint nClasses = AllClasses.size();
for (uint i = 0; i < nClasses; ++i)
{
class aClass = AllClasses[i];
if (aClass is "ts_ExternalActorInfoProvider" && aClass != "ts_ExternalActorInfoProvider")
{
let provider = ts_ExternalActorInfoProvider(new(aClass));
_externalInfoProviders.push(provider);
}
}
}

private ts_Settings _settings;
private ts_Api _api;

Expand All @@ -795,4 +821,6 @@ class ts_EventHandler : EventHandler
private ts_Le_GlScreen _glProjection;
private ts_Le_SwScreen _swProjection;

private Array<ts_ExternalActorInfoProvider> _externalInfoProviders;

} // class ts_EventHandler
42 changes: 42 additions & 0 deletions zscript/ts_external_actor_info_provider.zs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Copyright Alexander Kromm (mmaulwurff@gmail.com) 2021
*
* This file is part of Target Spy.
*
* Target Spy is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* Target Spy is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Target Spy. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* Inherit this class and implement getInfo() method to make Target Spy display
* additional information about the target.
*
* No further setup required. Target Spy will instantiate and call this class
* when needed.
*/
class ts_ExternalActorInfoProvider abstract
{
/**
* If empty string is returned, the output is ignored.
*/
abstract string getInfo(Actor anActor);
}

// Example: this provider returns class tag repeated twice.
//
//class ts_ExternalActorInfoProviderDoubleName : ts_ExternalActorInfoProvider
//{
// override
// string getInfo(Actor anActor)
// {
// return anActor.getTag() .. "-" .. anActor.getTag();
// }
//}

0 comments on commit 4bf0b44

Please sign in to comment.