Home /Modules/gui/SLGuiClickObject.sleela

SLGuiClickObject.sleela

lib/gui/version-dual/SLGuiClickObject.sleela · 218 line(s) · sleela

<< lib/gui/version-dual/SLGuiClickObject.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLGuiClickObject โ€” a 4.0 custom click object: a small
     circle with its own position, radius, architecturally-driven MOTION, and a
     staged TIMER. The timer runs through a sequence of "System Apprentice"
     stages โ€” subtle, escalating activations โ€” and when the final stage elapses
     it fires the FINAL CALL (a named SLeeLa operation). The motion is a declared
     architecture (static / drift / orbit / pulse) advanced by the app tick, so
     the circle moves predictably rather than by ad-hoc animation. SLeeLa owns
     position, motion, the apprentice ladder, and the final-call binding; the
     host paints the circle and plays any cue.
   
     The apprentice model: stage 0 is dormant; each interval advances one
     apprentice stage (subtle visual/behaviour change); reaching apprenticeMax
     triggers the final call exactly once. This gives a click object a careful,
     architecturally-driven build-up to its culminating action.
   
   Family: gui. A circle node's backing model; advanced by SLGuiApp's tick. >>
#sleela 2.5
material;
class SLGuiClickObject {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 11175;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-16";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  < Motion architectures. >
  < fixed position >
  static final int MOTION_STATIC = 0;
  < linear drift by (vx,vy) per interval >
  static final int MOTION_DRIFT  = 1;
  < orbit a center at a radius/step >
  static final int MOTION_ORBIT  = 2;
  < radius pulses between min/max >
  static final int MOTION_PULSE  = 3;

  String id;
  < exact position (px) of the circle's center >
  int x; int y;
  < circle radius, 2..512 >
  int radiusPx;
  < MOTION_* >
  int motion;
  < drift velocity (px per interval) for MOTION_DRIFT >
  int vx; int vy;
  < MOTION_ORBIT >
  int orbitCx; int orbitCy; int orbitR; int orbitDeg; int orbitStepDeg;
  < MOTION_PULSE radius bounds + direction >
  int pulseMin; int pulseMax; int pulseDir;

  < Staged apprentice timer. >
  < time between apprentice stages, 50..600000 >
  int intervalMs;
  < banked time toward the next stage >
  int accumMs;
  < current apprentice stage (0 = dormant) >
  int apprentice;
  < stages before the final call fires, 1..64 >
  int apprenticeMax;
  < SLeeLa operation fired at the culminating stage >
  String finalCall;
  < 1 once the final call has fired (fires once) >
  int fired;
  < 1 while the timer advances >
  int running;

  void configure(String objId, int cx, int cy, int radius) {
    id = objId; x = cx; y = cy; radiusPx = clampRadius(radius);
    motion = MOTION_STATIC; vx = 0; vy = 0;
    orbitCx = cx; orbitCy = cy; orbitR = 0; orbitDeg = 0; orbitStepDeg = 6;
    pulseMin = radiusPx; pulseMax = radiusPx; pulseDir = 1;
    intervalMs = 1000; accumMs = 0; apprentice = 0; apprenticeMax = 3;
    finalCall = ""; fired = 0; running = 0;
  }

  int clamp(int v, int lo, int hi) { if (v < lo) { return lo; } if (v > hi) { return hi; } return v; }
  int clampRadius(int r) { return clamp(r, 2, 512); }
  int wrapDeg(int d) { int r = d % 360; if (r < 0) { r = r + 360; } return r; }

  < ---- position ---------------------------------------------------------- >
  void setPosition(int cx, int cy) { x = cx; y = cy; }
  void setRadius(int r) { radiusPx = clampRadius(r); }
  int posX() { return x; }
  int posY() { return y; }
  int radius() { return radiusPx; }

  < ---- motion architecture ------------------------------------------------ >
  void setStatic() { motion = MOTION_STATIC; }
  void setDrift(int velX, int velY) { motion = MOTION_DRIFT; vx = velX; vy = velY; }
  void setOrbit(int centerX, int centerY, int r, int stepDeg) {
    motion = MOTION_ORBIT; orbitCx = centerX; orbitCy = centerY;
    orbitR = (r < 0) ? 0 : r; orbitStepDeg = clamp(stepDeg, -180, 180);
  }
  void setPulse(int minR, int maxR) {
    motion = MOTION_PULSE;
    pulseMin = clampRadius(minR); pulseMax = clampRadius(maxR);
    if (pulseMax < pulseMin) { pulseMax = pulseMin; }
    pulseDir = 1;
  }

  < ---- apprentice ladder -------------------------------------------------- >
  < Bind the culminating action and how many apprentice stages precede it. >
  void bindFinalCall(String operation, int stages) {
    finalCall = (operation == null) ? "" : operation;
    apprenticeMax = clamp(stages, 1, 64);
  }
  void setInterval(int ms) { intervalMs = clamp(ms, 50, 600000); }
  void start() { running = 1; }
  void stop()  { running = 0; }
  void reset() { apprentice = 0; accumMs = 0; fired = 0; }
  int apprenticeStage() { return apprentice; }
  int apprenticeStages() { return apprenticeMax; }
  boolean dormant() { return apprentice == 0; }
  boolean finalFired() { return fired == 1; }
  String getFinalCall() { return finalCall; }

  < ---- advance (called by the app tick) ----------------------------------- >
  < Advance motion and the apprentice timer by `elapsedMs`. Returns a code: >
  < 0 = nothing happened this tick >
  < 1 = moved and/or advanced an apprentice stage >
  < 2 = the FINAL CALL fired this tick (the host should invoke finalCall) >
  int advance(int elapsedMs) {
    if (running == 0 || elapsedMs <= 0) { return 0; }
    boolean changed = advanceMotion();

    accumMs = accumMs + elapsedMs;
    int code = changed ? 1 : 0;
    while (accumMs >= intervalMs && fired == 0) {
      accumMs = accumMs - intervalMs;
      if (apprentice < apprenticeMax) {
        < one more subtle System Apprentice awakens >
        apprentice = apprentice + 1;
        code = 1;
      }
      if (apprentice >= apprenticeMax) {
        < the final call lands exactly once >
        fired = 1; running = 0;
        return 2;
      }
    }
    return code;
  }

  < Apply one motion step according to the architecture. Returns true if moved. >
  boolean advanceMotion() {
    if (motion == MOTION_DRIFT) {
      if (vx == 0 && vy == 0) { return false; }
      x = x + vx; y = y + vy; return true;
    }
    if (motion == MOTION_ORBIT) {
      if (orbitR == 0) { return false; }
      orbitDeg = wrapDeg(orbitDeg + orbitStepDeg);
      < integer cosine/sine via a coarse step table would be ideal; here we keep >
      < the angle authoritative and let the host place the point from orbitDeg. >
      return true;
    }
    if (motion == MOTION_PULSE) {
      if (pulseMin == pulseMax) { return false; }
      radiusPx = radiusPx + pulseDir;
      if (radiusPx >= pulseMax) { radiusPx = pulseMax; pulseDir = -1; }
      else if (radiusPx <= pulseMin) { radiusPx = pulseMin; pulseDir = 1; }
      return true;
    }
    < MOTION_STATIC >
    return false;
  }

  int orbitAngle() { return orbitDeg; }
  int motionKind() { return motion; }
  String motionName() {
    if (motion == MOTION_DRIFT) { return "drift"; }
    if (motion == MOTION_ORBIT) { return "orbit"; }
    if (motion == MOTION_PULSE) { return "pulse"; }
    return "static";
  }
  boolean honored() {
    return radiusPx >= 2 && radiusPx <= 512 &&
           intervalMs >= 50 && intervalMs <= 600000 &&
           apprenticeMax >= 1 && apprenticeMax <= 64;
  }
}