File size: 6,332 Bytes
135e328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* GSAP-led parlor transitions, with a native CSS/reduced-motion fallback. */
(function () {
  const overlay = document.getElementById('scene-transition');
  const leftDoor = overlay && overlay.querySelector('.scene-door-left');
  const rightDoor = overlay && overlay.querySelector('.scene-door-right');
  const core = overlay && overlay.querySelector('.scene-core');
  const caption = document.getElementById('scene-caption');
  const title = document.getElementById('scene-title');
  const gsap = window.gsap;
  let reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  let transitionRunning = false;

  if (gsap && gsap.matchMedia) {
    const media = gsap.matchMedia();
    media.add({ reduceMotion: '(prefers-reduced-motion: reduce)' }, function (context) {
      reducedMotion = context.conditions.reduceMotion;
    });
  }

  function showScene(sceneCaption, sceneTitle) {
    if (!overlay) return false;
    caption.textContent = sceneCaption;
    title.textContent = sceneTitle;
    overlay.hidden = false;
    overlay.setAttribute('aria-hidden', 'false');
    overlay.dataset.active = 'true';
    return true;
  }

  function hideScene() {
    if (!overlay) return;
    overlay.hidden = true;
    overlay.setAttribute('aria-hidden', 'true');
    overlay.dataset.active = 'false';
    overlay.classList.remove('is-active', 'is-closing', 'is-opening', 'is-closed');
  }

  function enterRoom(url) {
    if (transitionRunning || !url) return;
    transitionRunning = true;
    try { sessionStorage.setItem('parlor:arrival', '1'); } catch (_) { /* storage may be disabled */ }
    if (!showScene('THE MIDNIGHT PARLOR', 'A seat has been kept for you.')) {
      location.assign(url);
      return;
    }

    const navigate = function () { location.assign(url); };
    if (!gsap || reducedMotion) {
      overlay.classList.add('is-active', 'is-closing');
      window.setTimeout(navigate, reducedMotion ? 120 : 760);
      return;
    }

    gsap.set(overlay, { autoAlpha: 1 });
    gsap.set(leftDoor, { xPercent: -100 });
    gsap.set(rightDoor, { xPercent: 100 });
    gsap.set(core, { autoAlpha: 0, y: 18, scale: 0.96 });
    gsap.timeline({ defaults: { ease: 'power3.inOut' }, onComplete: navigate })
      .to(leftDoor, { xPercent: 0, duration: 0.78 }, 0)
      .to(rightDoor, { xPercent: 0, duration: 0.78 }, 0.04)
      .to(core, { autoAlpha: 1, y: 0, scale: 1, duration: 0.48, ease: 'power2.out' }, 0.38)
      .to(core, { autoAlpha: 0, y: -10, duration: 0.2 }, 1.12);
  }

  function revealRoom() {
    let arriving = false;
    try {
      arriving = sessionStorage.getItem('parlor:arrival') === '1';
      if (arriving) sessionStorage.removeItem('parlor:arrival');
    } catch (_) { /* storage may be disabled */ }
    function revealContent() {
      if (!gsap || reducedMotion) return;
      document.documentElement.classList.add('gsap-ready');
      gsap.timeline({ defaults: { ease: 'power2.out' } })
        .fromTo('.room-heading', { y: 16, autoAlpha: 0 }, { y: 0, autoAlpha: 1, duration: 0.48 }, 0)
        .fromTo('.gameplay-panel', { y: 22, autoAlpha: 0 }, { y: 0, autoAlpha: 1, duration: 0.58 }, 0.08)
        .fromTo('.room-main .chat', { y: 14, autoAlpha: 0 }, { y: 0, autoAlpha: 1, duration: 0.48 }, 0.18)
        .fromTo('.rail .panel', { x: -12, autoAlpha: 0 }, { x: 0, autoAlpha: 1, duration: 0.4, stagger: 0.08 }, 0.12);
    }

    if (!arriving) {
      revealContent();
      return;
    }
    if (!showScene('THE MIDNIGHT PARLOR', 'The room has noticed you.')) return;

    if (!gsap || reducedMotion) {
      overlay.classList.add('is-active', 'is-closed');
      requestAnimationFrame(function () { overlay.classList.add('is-opening'); });
      window.setTimeout(function () { hideScene(); revealContent(); }, reducedMotion ? 80 : 760);
      return;
    }

    gsap.set(overlay, { autoAlpha: 1 });
    gsap.set(leftDoor, { xPercent: 0 });
    gsap.set(rightDoor, { xPercent: 0 });
    gsap.set(core, { autoAlpha: 1, y: 0, scale: 1 });
    gsap.timeline({ defaults: { ease: 'power3.inOut' }, onComplete: function () {
      hideScene();
      revealContent();
    } })
      .to(leftDoor, { xPercent: -100, duration: 0.86 }, 0.2)
      .to(rightDoor, { xPercent: 100, duration: 0.86 }, 0.2)
      .to(core, { autoAlpha: 0, y: -8, duration: 0.24 }, 0)
      .to('.scene-rule', { scaleX: 0, duration: 0.36 }, 0.05);
  }

  function openOnboarding() {
    const card = document.querySelector('.onboarding-card');
    if (!card) return;
    if (gsap && !reducedMotion) {
      gsap.fromTo(card, { y: 26, scale: 0.97, autoAlpha: 0 }, {
        y: 0, scale: 1, autoAlpha: 1, duration: 0.62, ease: 'power3.out', clearProps: 'transform',
      });
    } else {
      card.classList.add('is-entered');
    }
  }

  function closeOnboarding(onComplete) {
    const modal = document.getElementById('onboarding-overlay');
    const card = document.querySelector('.onboarding-card');
    if (!modal) { if (onComplete) onComplete(); return; }
    const finish = function () {
      modal.hidden = true;
      modal.setAttribute('aria-hidden', 'true');
      document.body.classList.remove('onboarding-active');
      if (onComplete) onComplete();
    };
    if (gsap && !reducedMotion && card) {
      gsap.timeline({ onComplete: finish })
        .to(card, { y: 10, autoAlpha: 0, duration: 0.24, ease: 'power2.in' })
        .to(modal, { autoAlpha: 0, duration: 0.22 }, '<0.04');
    } else {
      modal.classList.add('is-closing');
      window.setTimeout(finish, reducedMotion ? 0 : 220);
    }
  }

  function animateLobby() {
    const hero = document.querySelector('.hero');
    if (!hero) return;
    if (gsap && !reducedMotion) {
      document.documentElement.classList.add('gsap-ready');
      gsap.timeline({ defaults: { ease: 'power3.out' } })
        .from('.hero .eyebrow', { y: 12, autoAlpha: 0, duration: 0.42 })
        .from('.hero h1', { y: 24, autoAlpha: 0, duration: 0.64 }, '<0.06')
        .from('.hero .lede', { y: 12, autoAlpha: 0, duration: 0.5 }, '<0.1')
        .from('.hero + .grid > .panel', { y: 22, autoAlpha: 0, duration: 0.55, stagger: 0.12 }, '<0.1');
    }
  }

  window.ParlorMotion = { enterRoom: enterRoom, revealRoom: revealRoom, openOnboarding: openOnboarding, closeOnboarding: closeOnboarding };
  animateLobby();
  revealRoom();
})();