Skip to content

feat: alarm.add / alarm.delete and surface id in alarm rows#2

Closed
jonpepler wants to merge 3 commits into
mainfrom
telemachus/alarm-add-delete
Closed

feat: alarm.add / alarm.delete and surface id in alarm rows#2
jonpepler wants to merge 3 commits into
mainfrom
telemachus/alarm-add-delete

Conversation

@jonpepler
Copy link
Copy Markdown
Owner

Summary

Adds two action keys for stock-clock alarm management plus an id field in the alarm row.

alarm.add[title, ut, warpAction?, message?] → uint id    (or error string)
alarm.delete[id] → bool                                  (false if no such alarm)

alarm.list / alarm.nextAlarm rows now include "id": <uint> so external clients can address an alarm.

Why not IsAction?

alarm.add needs to return the new alarm's uint Id synchronously in the HTTP response, but the existing IsAction = true path wraps the handler in queueDelayed, which short-circuits the return to false while the real work runs on the next Unity tick. So this PR manually queues the AlarmClockScenario.AddAlarm / DeleteAlarm call onto the main thread via the same TelemachusBehaviour.queueDelayedAPI hook the auto-defer uses, while the caller returns its own value sync.

The AlarmTypeRaw ctor calls GetUniqueAlarmID() synchronously, so alarm.Id is already set by the time we read it on the dispatch thread.

Other small changes

  • alarm.count / alarm.list / alarm.nextAlarm / alarm.timeToNext gain AlwaysEvaluable = true so they're queryable from Space Center / Tracking Station, not just Flight.

Test plan

  • GET /telemachus/datalink?a=alarm.add[Test,1234567,KillWarp,Yes] returns the new alarm's uint id; the alarm appears in stock KAC UI.
  • GET /telemachus/datalink?a=alarm.list rows now include id field.
  • GET /telemachus/datalink?a=alarm.delete[<id>] returns true if the alarm exists, false otherwise, and the alarm vanishes from the UI on the next tick.
  • Invalid warpAction / message enums return a descriptive error string instead of throwing.
  • All four read keys work from Space Center scene (previously gated to Flight).

jonpepler added 3 commits May 11, 2026 13:37
Adds two action keys for stock-clock alarm management:
  alarm.add[title, ut, warpAction?, message?] → uint id
  alarm.delete[id] → bool

Both manually queue the scenario mutation onto the main thread
rather than using IsAction (which the auto-defer wrapper makes
fire-and-forget) so alarm.add can return the new id sync in the
same HTTP response.

Also surfaces alarm.Id in the AlarmJSONFormatter row so existing
alarm.list / alarm.nextAlarm callers can address alarms by id.

The alarm.count / alarm.list / alarm.nextAlarm / alarm.timeToNext
reads gain AlwaysEvaluable = true so they're queryable from the
Space Center / Tracking Station, not just Flight.
Two pieces:

  - tools/generate-openapi.ts now strips the `sourceFile` field
    when writing docs/api-schema.json. The field leaks absolute
    paths from the build machine into the committed artifact;
    every rebuild from a different machine produced ~500 lines
    of pure path churn in the diff.
  - Rebuilt and regenerated docs to pick up alarm.add /
    alarm.delete plus the AlwaysEvaluable flips on the existing
    alarm.count / list / nextAlarm / timeToNext.
@jonpepler
Copy link
Copy Markdown
Owner Author

Superseded by upstream PR TeaGuild#83

@jonpepler jonpepler closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant