-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prettier Add github action Add README Fix lint errors
- Loading branch information
Showing
15 changed files
with
1,998 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"browser": true, | ||
"es6": true | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:import/recommended", | ||
"plugin:import/typescript", | ||
"plugin:promise/recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"settings": { | ||
"import/extensions": [".js", ".jsx", ".ts", ".tsx"], | ||
"import/parsers": { | ||
"@typescript-eslint/parser": [".ts", ".tsx"] | ||
} | ||
}, | ||
"rules": { | ||
"no-debugger": "warn", | ||
"no-implicit-coercion": ["error", { "allow": ["!!"] }], | ||
"no-unused-vars": "off", | ||
"promise/catch-or-return": [ | ||
"error", | ||
{ "allowFinally": true, "terminationMethod": ["catch", "finally"] } | ||
], | ||
"@typescript-eslint/no-require-imports": "error", | ||
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }] | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["./src/DataStore.ts"], | ||
"rules": { | ||
"@typescript-eslint/no-unused-vars": "off" | ||
} | ||
}, | ||
{ | ||
"files": ["./src/index.ts"], | ||
"rules": { | ||
"import/export": "off" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Publish to NPM | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 💾 Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: ⚙️ Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18.18.0' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: 🧰 Install | ||
uses: borales/actions-yarn@v4 | ||
with: | ||
cmd: install | ||
|
||
- name: 👊 Bump | ||
uses: anothrNick/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
WITH_V: true | ||
|
||
- name: 📦 Publish | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# **AGE** -- Abstract Gamification Engine. | ||
|
||
This is a rewrite of (rodw/age)[https://github.com/rodw/age] from coffeescript to TypeScript. Mostly it is the same but with some notable changes: | ||
|
||
1. Renamed all methods from snake_case to camelCase | ||
2. Achievement Rules are evaluated on event received rather than on `getPlayerAchievments` | ||
3. Achieved Achievements are also added to the `player.history` | ||
4. Transient rules are not yet implemented | ||
5. History entries are objects with a timestamp Date, and Achievements have an `achieved` Date | ||
6. Methods return values rather than replying on Node style callbacks with errors | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @chromeq/age | ||
``` | ||
|
||
## Examples | ||
|
||
For a detailed example of how to use the AGE framework, visit the base project [example docs](https://github.com/rodw/age/blob/master/docs/stack-exchange-example.litcoffee). | ||
|
||
## Usage | ||
|
||
Clients must: | ||
|
||
1. Initialise the ***GameEngine*** and register ***players***. [Further Docs](https://github.com/rodw/age/blob/master/docs/stack-exchange-example.litcoffee#implementing-the-game) | ||
```ts | ||
import { GameEngine } from '@chromeq/age'; | ||
|
||
// Create a new instance of the gamification engine | ||
const engine = new GameEngine(); | ||
|
||
// Register the "player" -- any object that contains at least an `id` | ||
const player = { id: 123 }; | ||
engine.addPlayer(player); | ||
``` | ||
|
||
2. Define ***achievement rules*** which define conditions that ***players*** must meet in order to earn the corresponding ***achievement***. [Further Docs](https://github.com/rodw/age/blob/master/docs/stack-exchange-example.litcoffee#age-achievement-rules) | ||
```ts | ||
const rule = new AchievementRule({ | ||
key: 'SessionCount', | ||
multiplicity: 1, | ||
transient: false, | ||
predicate: (player, engine) => { | ||
return sessionCount > 3; // Any logic required to evaluate to `boolean` | ||
}, | ||
}); | ||
|
||
// Add the achievemt rule to the engine -- Can also be defined first and provided to the GameEngine constructor | ||
engine.addAchievementRule(rule); | ||
``` | ||
|
||
3. Publish ***events*** that represent actions or events that add to a player's ***event history***. | ||
```ts | ||
// Add an event that happens -- Also has alias `trigger`, `triggerEvent`, `dispatch` or `dispatchEvent` | ||
engine.addEvent(player, 'SessionCount'); // TODO: Add extra data to the event | ||
``` | ||
|
||
4. Subscribe to ***events*** or ***achievements*** | ||
```ts | ||
// Subscribe to `'achievement-achieved'` or `'event-occurred'` -- Also has alias `listen`, `addListner` or `addEventListner` | ||
|
||
engine.on('event-occurred', async (player, event) => { | ||
// Useful to "chain" events and you can call `engine.addEvent` again here | ||
console.log('EVENT OCCURRED', player, event); | ||
}); | ||
|
||
engine.on('achievement-achieved', async (player, achievement) => { | ||
// Congrats 🎉 - Show the appropriate UI or save state | ||
console.log('ACHIEVEMENT ACHIEVED', player, achievement); | ||
}); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.