Skip to content

Commit

Permalink
add real time to obituaries, fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaulwurff committed Jan 28, 2021
1 parent 7feb950 commit 425c980
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Gravestones are carried over play sessions, so:
- Thanks to Captain J for gravestone sprites.
- Thanks to Dr_Cosmobyte for feature suggestions.
- Thanks to mamaluigisbagel for bug reports.
- Thanks to 3saster for implementing real time access in GZDoom.

## Other Info

Expand Down
2 changes: 1 addition & 1 deletion zscript.zs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version 4.3
version 4.5

#include "zscript/gy_EventHandler.zs"
#include "zscript/gy_Death.zs"
Expand Down
52 changes: 39 additions & 13 deletions zscript/gy_EventHandler.zs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class gy_EventHandler : EventHandler
{

override
void WorldTick()
void worldTick()
{
if (_isFired)
{
Expand All @@ -32,29 +32,30 @@ class gy_EventHandler : EventHandler
let storage = gy_Storage.of();

gy_Death death;
while (death = storage.Next())
while (death = storage.next())
{
SendNetworkEvent("gy_spawn" .. death.toString());
sendNetworkEvent("gy_spawn" .. death.toString());
}
}

override
void WorldThingDied(WorldEvent event)
void worldThingDied(WorldEvent event)
{
if (event.thing == NULL || event.thing.player == NULL) { return; }

String name = event.thing.player.GetUserName();
String name = event.thing.player.getUserName();
String obituaryPart;
if (event.thing.target != NULL)
{
String killerName = (event.thing.target.player != NULL)
? event.thing.target.player.GetUserName()
: event.thing.target.GetTag();
? event.thing.target.player.getUserName()
: event.thing.target.getTag();
obituaryPart = ", killed by " .. killerName;
}
String obituary = String.Format( "Here lies %s%s.\n%s"
String obituary = String.format( "Here lies %s%s.\n%s\n%s"
, name
, obituaryPart
, SystemTime.format("%F %T", _now)
, level.TimeFormatted()
);

Expand All @@ -63,15 +64,15 @@ class gy_EventHandler : EventHandler
}

override
void NetworkProcess(ConsoleEvent event)
void networkProcess(ConsoleEvent event)
{
if (event.name.left(8) == "gy_spawn")
{
let death = gy_Death.fromString(event.name.mid(8));
let pos = death.getLocation();
int i = abs(int(pos.x + pos.y + pos.z)) % 4;
let c = String.Format("gy_Stone%d", i);
let stone = gy_Stone(Actor.Spawn(c, death.getLocation(), ALLOW_REPLACE));
let c = String.format("gy_Stone%d", i);
let stone = gy_Stone(Actor.spawn(c, death.getLocation(), ALLOW_REPLACE));
stone.setObituary(death.getObituary());
}
else if (event.name == "gy_remove_all")
Expand All @@ -88,23 +89,48 @@ class gy_EventHandler : EventHandler
}
}

override
void renderOverlay(RenderEvent event)
{
// Workaround to get the current time, which is UI-scoped.
// Part 1/2.
int second = level.time / 35 + 1;
if (second > _lastSecond)
{
setNow(second, SystemTime.Now());
}
}

// private: ////////////////////////////////////////////////////////////////////////////////////////

private
void print(String message)
{
Console.Printf("%s", StringTable.Localize(message, false));
Console.printf("%s", StringTable.localize(message, false));
}

private
void removeStonesOnMap()
{
let i = ThinkerIterator.Create("gy_Stone");
let i = ThinkerIterator.create("gy_Stone");
Actor a;
while (a = Actor(i.Next()))
{
a.Destroy();
}
}

// Workaround to get the current time, which is UI-scoped.
// Part 2/2.
private
void setNow(int lastSecond, int now) const
{
_lastSecond = lastSecond;
_now = now;
}

private transient bool _isFired;
private int _lastSecond;
private int _now;

} // class gy_EventHandler

0 comments on commit 425c980

Please sign in to comment.