mirror of
https://github.com/osmarks/website
synced 2025-08-30 09:17:56 +00:00
Patch achievement system
This commit is contained in:
@@ -619,6 +619,9 @@ description: A game about... apioforms... by Heavpoot.
|
||||
}
|
||||
console.log(kills)
|
||||
if (localStorage.tutorial=="true"&&kills>30){
|
||||
if ("points" in window) {
|
||||
points.then(points => points.unlockAchievement("apioformGame"))
|
||||
}
|
||||
localStorage.tutorial=false
|
||||
kills=0
|
||||
}
|
||||
|
@@ -377,9 +377,9 @@ const mainLoop = () => {
|
||||
|
||||
if (hp <= 0) {
|
||||
if ("points" in window) {
|
||||
if (score >= 10) { points.unlockAchievement("emuwar10") }
|
||||
points.updateMetric("foesVanquished", function(x) { return x + score }, 0)
|
||||
points.updateMetric("deaths", function(x) { return x + 1 }, 0)
|
||||
if (score >= 10) { points.then(points => points.unlockAchievement("emuwar10")) }
|
||||
points.then(points => points.updateMetric("foesVanquished", function(x) { return x + score }, 0))
|
||||
points.then(points => points.updateMetric("deaths", function(x) { return x + 1 }, 0))
|
||||
}
|
||||
clear(saybox)
|
||||
say(saybox, gameOverMessage + " Press R to restart.")
|
||||
|
@@ -29,12 +29,12 @@ description: It is pitch black (if you ignore all of the lighting). You are like
|
||||
<script>
|
||||
function unlockAchievement(name) {
|
||||
if ("points" in window) {
|
||||
points.unlockAchievement(name)
|
||||
points.then(points => points.unlockAchievement(name))
|
||||
}
|
||||
}
|
||||
function updateMetric(name, fn, def) {
|
||||
if ("points" in window) {
|
||||
points.updateMetric(name, fn, def)
|
||||
points.then(points => points.updateMetric(name, fn, def))
|
||||
}
|
||||
}
|
||||
var state="start"; // SPOILERS SPOILERS OH GOD SPOILERS OH GOD SPOILERS
|
||||
|
@@ -125,11 +125,11 @@ url: /infipage/p
|
||||
window.addEventListener("load", function() {
|
||||
if ("points" in window) {
|
||||
console.log("running update")
|
||||
points.updateMetric("greatestInfipage", function(current) {
|
||||
points.then(points => points.updateMetric("greatestInfipage", function(current) {
|
||||
console.log("updated", current, pageString)
|
||||
if (!current || page.abs().gt(Big(current))) { return pageString }
|
||||
else { return current }
|
||||
})
|
||||
}))
|
||||
}
|
||||
})
|
||||
</script>
|
@@ -63,8 +63,8 @@ description: Lorem Ipsum (latin-like placeholder text), eternally. Somehow peopl
|
||||
var count = 0
|
||||
var unaddedCount = 0
|
||||
var handlePoints = throttle(function() {
|
||||
if (count >= 400) { points.unlockAchievement("lorem400") }
|
||||
points.updateMetric("loremParagraphs", function(x) { return x + unaddedCount }, 0).then(function() { unaddedCount = 0 })
|
||||
if (count >= 400) { points.then(p => p.unlockAchievement("lorem400")) }
|
||||
points.then(p => p.updateMetric("loremParagraphs", function(x) { return x + unaddedCount }, 0).then(function() { unaddedCount = 0 }))
|
||||
}, 300)
|
||||
|
||||
window.addEventListener("load", function() {
|
||||
|
@@ -24,6 +24,12 @@ const metricDisplayInfo = {
|
||||
heavpootDeaths: { name: "Heavpoot's Game deaths", units: "death" }
|
||||
}
|
||||
|
||||
for (const opponent of ["ai1", "ai2"]) {
|
||||
for (const result of ["Wins", "Losses", "Draws"]) {
|
||||
metricDisplayInfo[`ttt${result}${opponent}`] = { name: `${result} against ${opponent.toUpperCase()}`, units: "game" }
|
||||
}
|
||||
}
|
||||
|
||||
const displayMetric = metric => {
|
||||
let name = metric[0]
|
||||
let value = metric[1]
|
||||
@@ -40,7 +46,7 @@ const displayMetric = metric => {
|
||||
const Metrics = {
|
||||
metrics: null,
|
||||
load: async () => {
|
||||
Metrics.metrics = await points.readAllMetrics()
|
||||
Metrics.metrics = await (await points).readAllMetrics()
|
||||
m.redraw()
|
||||
},
|
||||
view: () => m("p", Metrics.metrics === null ? "Loading..." : m("table.metrics", Array.from(Metrics.metrics.entries()).map(displayMetric)))
|
||||
@@ -61,9 +67,10 @@ const renderAchievement = a =>
|
||||
const Achievements = {
|
||||
achievements: [],
|
||||
load: async () => {
|
||||
const raw = await points.getAchievements()
|
||||
let rpoints = await points
|
||||
const raw = await rpoints.getAchievements()
|
||||
Achievements.achievements = raw.map(ach => {
|
||||
const info = points.achievementInfo[ach.id]
|
||||
const info = rpoints.achievementInfo[ach.id]
|
||||
const out = {
|
||||
title: ach.id || "???",
|
||||
description: `Unrecognized achievement ${ach.id}.`,
|
||||
@@ -82,15 +89,15 @@ const Achievements = {
|
||||
const reset = async () => {
|
||||
if (prompt(`This will reset your points, achievements and metrics. If you are sure, please type "yes I am definitely sure".`) === "yes I am definitely sure") {
|
||||
if (confirm("Are you really very sure?")) {
|
||||
await points.reset()
|
||||
window.location.reload()
|
||||
await (await points).reset()
|
||||
//window.location.reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let pointsCount = "[loading...]"
|
||||
|
||||
const reloadPoints = async () => { pointsCount = await points.getPoints() }
|
||||
const reloadPoints = async () => { pointsCount = await (await points).getPoints() }
|
||||
|
||||
const App = {
|
||||
view: () => m("div", [
|
||||
@@ -107,6 +114,6 @@ Metrics.load()
|
||||
reloadPoints()
|
||||
Achievements.load()
|
||||
|
||||
points.unlockAchievement("visitArbitraryPoints")
|
||||
points.then(points => points.unlockAchievement("visitArbitraryPoints"))
|
||||
|
||||
document.addEventListener("points-update", () => { reloadPoints(); Achievements.load() })
|
@@ -121,7 +121,16 @@ const doIns = (ins, state, handler) => {
|
||||
}
|
||||
}
|
||||
|
||||
let hasDoneAchievement = false
|
||||
|
||||
export const step = (state, handler, showIns, maxdepth) => {
|
||||
if (!hasDoneAchievement && state.stacks.length > 100) {
|
||||
if ("points" in window) {
|
||||
points.then(points => points.unlockAchievement("rpnv4recursion"))
|
||||
}
|
||||
hasDoneAchievement = true
|
||||
}
|
||||
|
||||
if (state.stacks.length > maxdepth) {
|
||||
throw 'max recursion depth exceeded'
|
||||
}
|
||||
|
@@ -321,6 +321,10 @@ slug: tictactoe
|
||||
</script>
|
||||
<script>
|
||||
// copyright (2022 CE) © © © osmarks.net hypercomputational tetrational metahexagonal industrial - unsigned integer division
|
||||
|
||||
let achievementEligiblity = true
|
||||
let lastOpponent = null
|
||||
|
||||
var workerGlue = `
|
||||
onmessage = event => {
|
||||
var [policy, ...args] = event.data
|
||||
@@ -407,6 +411,23 @@ slug: tictactoe
|
||||
info.removeEventListener("click", el)
|
||||
}
|
||||
info.addEventListener("click", el)
|
||||
if (achievementEligiblity && opponentIsAI()) {
|
||||
if ("points" in window) {
|
||||
let opp = lastOpponent
|
||||
points.then(points => {
|
||||
if (winner === 1) {
|
||||
points.unlockAchievement(`tttWin${opp}`)
|
||||
points.updateMetric(`tttWins${opp}`, x => x + 1, 0)
|
||||
} else if (winner === 2) {
|
||||
points.updateMetric(`tttLosses${opp}`, x => x + 1, 0)
|
||||
} else if (isDraw) {
|
||||
points.updateMetric(`tttDraws${opp}`, x => x + 1, 0)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
achievementEligiblity = true
|
||||
lastOpponent = null
|
||||
gameOver = true
|
||||
})
|
||||
return true
|
||||
@@ -462,6 +483,10 @@ slug: tictactoe
|
||||
if (isNaN(coord) || typeof coord != "number" || start != "cell") { return }
|
||||
if (grid[coord]) { return }
|
||||
if (!onTurn(coord) && opponentIsAI()) {
|
||||
if (lastOpponent && lastOpponent !== opponent.value) {
|
||||
achievementEligiblity = false
|
||||
}
|
||||
lastOpponent = opponent.value
|
||||
worker.postMessage([opponent.value, grid, currentPlayer])
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user