tinyfiles.tv

Achievements

For helping the demoscene. No bananas. No weird fruit. Just demos, code, pixels, and helping people.

โญ Level 1XP: 0๐Ÿ† 0 unlocked๐ŸŽฏ Next: First Demo
0 / 500 XP to Level 2

How it works

Demoscene = people making real-time demos, intros, chiptunes, pixel art, shaders โ€” tiny files that do big things. Thatโ€™s us.
โ€ข Building Community โ€” post, comment, help.
โ€ข Demoscene โ€” ship a demo, intro, shader, tune.
โ€ข Academy โ€” finish lessons + challenges in Academy.
โ€ข Streak โ€” show up daily.
Click any badge to see how to unlock it. Use the buttons above to simulate a post / comment / lesson and watch badges unlock (saved in your browser).

Backend

Right now this page is local-only โ€” progress lives in localStorage key ach_state. This backend is the map to make it real: same achievements, same XP, but saved on the server so it follows the member across devices. Proposed, not connected.

01 / Files to create
api/achievements/list.php        GET  /api/achievements/list
api/achievements/progress.php     GET  /api/achievements/progress
api/achievements/unlock.php      POST /api/achievements/unlock
api/achievements/simulate.php    POST /api/achievements/simulate  (dev/demo only)
sql/achievements_tables.sql

Keep the tinyfiles PHP pattern: each endpoint loads /api/bootstrap.php, uses json_in() / json_out(), member session for auth, prepared PDO statements.

02 / Database tables
-- sql/achievements_tables.sql
achievements
  id VARCHAR(40) PRIMARY KEY          -- e.g. 'first-post', 'chip-tune'
  category VARCHAR(40) NOT NULL       -- Building Community / Demoscene / Streak / Academy / Creator / Exploration
  name VARCHAR(80) NOT NULL
  description VARCHAR(255) NOT NULL
  icon VARCHAR(16) NOT NULL           -- emoji
  xp INT NOT NULL DEFAULT 0
  how_to_unlock VARCHAR(255) NOT NULL

user_achievements
  member VARCHAR(80) NOT NULL
  achievement_id VARCHAR(40) NOT NULL
  unlocked_at DATETIME NOT NULL
  PRIMARY KEY (member, achievement_id)
  FOREIGN KEY (achievement_id) REFERENCES achievements(id)

user_xp
  member VARCHAR(80) PRIMARY KEY
  xp INT NOT NULL DEFAULT 0
  level INT NOT NULL DEFAULT 1
  updated_at DATETIME

user_achievement_counts
  member VARCHAR(80) NOT NULL
  kind ENUM('post','comment','lesson') NOT NULL
  count INT NOT NULL DEFAULT 0
  PRIMARY KEY (member, kind)

Seed achievements from the ACH array already in this page. Never trust XP from the browser โ€” server recomputes XP from unlocked rows.

03 / API endpoints & request flow
GET /api/achievements/list
- returns all achievements + locked/unlocked for current member

GET /api/achievements/progress
{
  "ok": true,
  "xp": 25,
  "level": 1,
  "unlocked": ["first-visit"],
  "counts": { "post": 0, "comment": 0, "lesson": 0 }
}

POST /api/achievements/unlock
{ "achievement_id": "first-post" }
- server checks rule, inserts into user_achievements (INSERT IGNORE / idempotent)
- recomputes XP, updates user_xp in same transaction
- returns { "ok": true, "unlocked": true, "xp": 75, "level": 1 }

POST /api/achievements/simulate
{ "type": "post" }  - dev only, increments count, runs same unlock rules as front-end simulateAction()

Unlock must be idempotent โ€” unlocking twice must not double XP. Use PRIMARY KEY (member, achievement_id) + transaction.

04 / Unlock rules & validation
// Server owns the rules. Browser submits intent only.
post:    count >=1 -> first-post, first-demo
         count >=2 -> 4k-intro
         count >=3 -> top25-poster
         count >=10 -> top10-poster
comment: count >=1 -> first-comment
         count >=5 -> top25-commenter, welcome-wagon
         count >=15 -> top10-commenter
lesson:  count >=1 -> first-lesson
         count >=5 -> html-hero, challenge-champ
         count >=10 -> js-ninja
any:     post+comment+lesson >=3 -> explorer

// Validate on every unlock:
1. achievement_id must exist in achievements table (allowlist)
2. member must be authenticated via member session
3. counts must come from server-side events, not browser-supplied XP
4. level = FLOOR(xp / 500) + 1, xp_in_level = xp % 500

Front-end tryUnlock() / simulateAction() stays as demo until the API exists. When it exists, replace localStorage save with fetch() to the endpoints above and keep localStorage as offline fallback only.

05 / Front-end integration contract
// When API exists, render() should fetch, not just read localStorage:
GET /api/achievements/progress
{
  "ok": true,
  "mode": "live", // or "simulation" if API unavailable
  "xp": 25,
  "level": 1,
  "unlocked": ["first-visit"],
  "counts": { "post": 0, "comment": 0, "lesson": 0 }
}

// Keep the page useful if API is down:
// - fall back to localStorage ach_state
// - show "Simulation" pill when in local-only mode
// - never show fabricated live XP as real server XP

Recommended states: loading, live, simulation, empty, validation error, unauthorized, server unavailable.