Add scripting support for TimeLimitManager
This commit is contained in:
committed by
abcdefg30
parent
47d88983fb
commit
26d712728a
@@ -10,6 +10,8 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using Eluant;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Scripting;
|
||||
|
||||
namespace OpenRA.Mods.Common.Scripting
|
||||
@@ -17,8 +19,13 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[ScriptGlobal("DateTime")]
|
||||
public class DateGlobal : ScriptGlobal
|
||||
{
|
||||
readonly TimeLimitManager tlm;
|
||||
|
||||
public DateGlobal(ScriptContext context)
|
||||
: base(context) { }
|
||||
: base(context)
|
||||
{
|
||||
tlm = context.World.WorldActor.TraitOrDefault<TimeLimitManager>();
|
||||
}
|
||||
|
||||
[Desc("True on the 31st of October.")]
|
||||
public bool IsHalloween
|
||||
@@ -43,5 +50,39 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
return Seconds(minutes * 60);
|
||||
}
|
||||
|
||||
[Desc("Return or set the time limit (in ticks). When setting, the time limit will count from now. Setting the time limit to 0 will disable it.")]
|
||||
public int TimeLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
return tlm != null ? tlm.TimeLimit : 0;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (tlm != null)
|
||||
tlm.TimeLimit = value == 0 ? 0 : value + GameTime;
|
||||
else
|
||||
throw new LuaException("Cannot set TimeLimit, TimeLimitManager trait is missing.");
|
||||
}
|
||||
}
|
||||
|
||||
[Desc("The notification string used for custom time limit warnings. See the TimeLimitManager trait documentation for details.")]
|
||||
public string TimeLimitNotification
|
||||
{
|
||||
get
|
||||
{
|
||||
return tlm != null ? tlm.Notification : null;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (tlm != null)
|
||||
tlm.Notification = value;
|
||||
else
|
||||
throw new LuaException("Cannot set TimeLimitNotification, TimeLimitManager trait is missing.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,6 +470,12 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnSold, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when the game timer expires. The callback function will be called as func().")]
|
||||
public void OnTimerExpired(LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(Context.World.WorldActor).RegisterCallback(Trigger.OnTimerExpired, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Removes all triggers from this actor. " +
|
||||
"Note that the removal will only take effect at the end of a tick, " +
|
||||
"so you must not add new triggers at the same time that you are calling this function.")]
|
||||
|
||||
Reference in New Issue
Block a user