Files
opengenesislinkserver/addons/NexSmartLight/NexSmartLightModel.cs
T
OpenGenesis (MPL 2.0) 8e57845cf2 feat(gen1): three standalone city addons NexTraffic, NexTransit and NexSmartLight (#338)
* feat(gen1): deterministic separate traffic, transit and smart light domain model

* feat(gen1): deterministic separate traffic, transit and smart light domain model

* feat(gen1): deterministic separate traffic, transit and smart light domain model

* feat(gen1): implement independent simulator-wide NexTraffic region module

* feat(gen1): implement independent simulator-wide NexTransit region module

* feat(gen1): implement independent simulator-wide NexSmartLight region module

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* build(gen1): add independent opt-in city addon configs and deployment wrappers

* feat(gen1): inworld LSL traffic lights, transit departures and city street lamps

* feat(gen1): inworld LSL traffic lights, transit departures and city street lamps

* feat(gen1): inworld LSL traffic lights, transit departures and city street lamps

* fix(gen1): use portable OpenSim LSL syntax for lighting and traffic state

* fix(gen1): use portable OpenSim LSL syntax for lighting and traffic state

* test(gen1): regression for junction safety, timetable rollovers, DST lighting and plugin boundaries

* test(gen1): regression for junction safety, timetable rollovers, DST lighting and plugin boundaries

* test(gen1): regression for junction safety, timetable rollovers, DST lighting and plugin boundaries

* ci(gen1): build NexTraffic, NexTransit and NexSmartLight independently and regression-test models

* docs(gen1): deployment and precise MVP scope for NexTraffic

* docs(gen1): deployment and precise MVP scope for NexTransit

* docs(gen1): deployment and precise MVP scope for NexSmartLight

* fix(gen1): resolve city addon helper at repository root, not parent directory

* test(gen1): guard standalone addon builder repository root discovery
2026-10-28 19:46:02 +01:00

37 lines
1.4 KiB
C#

// SPDX-License-Identifier: MPL-2.0
using System;
using System.Globalization;
namespace OpenGenesisLINK.Addons.NexSmartLight
{
public static class NexSmartLightModel
{
public static int ParseTime(string value)
{
if (!TimeSpan.TryParseExact(value, @"hh\:mm",
CultureInfo.InvariantCulture, out TimeSpan t) ||
t.TotalMinutes < 0 || t.TotalMinutes >= 1440)
throw new FormatException("Expected HH:mm between 00:00 and 23:59");
return (int)t.TotalMinutes;
}
public static bool IsOn(DateTime local, int fromMinute, int untilMinute)
{
if (fromMinute < 0 || fromMinute >= 1440 ||
untilMinute < 0 || untilMinute >= 1440)
throw new ArgumentOutOfRangeException(nameof(fromMinute));
int now = local.Hour * 60 + local.Minute;
if (fromMinute == untilMinute) return false; // safe default OFF
if (fromMinute < untilMinute)
return now >= fromMinute && now < untilMinute;
return now >= fromMinute || now < untilMinute; // midnight crossover
}
public static string Wire(DateTime local, bool on)
{
return "NEXLIGHT|1|" + (on ? "ON" : "OFF") + "|" +
local.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
}
}
}