| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation — Inkfall registration. |
| 4 |
* |
| 5 |
* Inkfall is the built-in typing game: words fall like ink down a |
| 6 |
* notebook page; typing a word launches a musical note that tears |
| 7 |
* the word apart into scattering letters. The game code lives in |
| 8 |
* its own lazily-loaded bundle (`assets/js/game-inkfall[.min].js`, |
| 9 |
* source `src/games/inkfall/`); this file only declares the |
| 10 |
* discovery metadata + score columns. The shared dictionary asset |
| 11 |
* arrives via the framework-injected `wordsUrl` config key. |
| 12 |
* |
| 13 |
* @package OpenStation |
| 14 |
*/ |
| 15 |
|
| 16 |
defined( 'ABSPATH' ) || exit; |
| 17 |
|
| 18 |
/** |
| 19 |
* The Inkfall icon: a musical note falling onto a notebook page. |
| 20 |
* |
| 21 |
* @return string Raw `<svg>` markup. |
| 22 |
*/ |
| 23 |
function openstation_inkfall_icon_svg() { |
| 24 |
return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">' |
| 25 |
. '<rect x="8" y="6" width="48" height="52" rx="6" fill="#f7f3e8"/>' |
| 26 |
. '<line x1="8" y1="20" x2="56" y2="20" stroke="#bcd4e6" stroke-width="2"/>' |
| 27 |
. '<line x1="8" y1="32" x2="56" y2="32" stroke="#bcd4e6" stroke-width="2"/>' |
| 28 |
. '<line x1="8" y1="44" x2="56" y2="44" stroke="#bcd4e6" stroke-width="2"/>' |
| 29 |
. '<line x1="18" y1="6" x2="18" y2="58" stroke="#e8a1a1" stroke-width="2"/>' |
| 30 |
. '<path fill="#2b3a55" d="M40 14v18.6a7 7 0 1 0 3 5.7V22l8 2v-6l-11-4z"/>' |
| 31 |
. '</svg>'; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Register Inkfall with the games registry on `init`. |
| 36 |
* |
| 37 |
* Priority 20 — alongside the Games window registration. |
| 38 |
*/ |
| 39 |
function openstation_inkfall_register() { |
| 40 |
if ( ! function_exists( 'openstation_games_user_can_use' ) || ! openstation_games_user_can_use() ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
openstation_register_game( |
| 45 |
'inkfall', |
| 46 |
array( |
| 47 |
'title' => __( 'Inkfall', 'desktop-mode' ), |
| 48 |
'description' => __( 'Words fall down a notebook page — type them before they reach the bottom. Finishing a word sends up a musical note that tears it into scattering letters.', 'desktop-mode' ), |
| 49 |
'icon_svg' => openstation_inkfall_icon_svg(), |
| 50 |
'script' => 'os-game-inkfall', |
| 51 |
// Mirrors the `window` block in `src/games/inkfall/index.ts`. |
| 52 |
// Declared here as well so the window opens at the right |
| 53 |
// size on the very first play, before the bundle that |
| 54 |
// carries the def has been fetched. Keep the two in step. |
| 55 |
'window' => array( |
| 56 |
'width' => 820, |
| 57 |
'height' => 620, |
| 58 |
'minWidth' => 520, |
| 59 |
'minHeight' => 420, |
| 60 |
), |
| 61 |
'score_columns' => array( |
| 62 |
array( |
| 63 |
'key' => 'score', |
| 64 |
'label' => __( 'Score', 'desktop-mode' ), |
| 65 |
'type' => 'number', |
| 66 |
), |
| 67 |
array( |
| 68 |
'key' => 'mode', |
| 69 |
'label' => __( 'Difficulty', 'desktop-mode' ), |
| 70 |
'type' => 'text', |
| 71 |
), |
| 72 |
array( |
| 73 |
'key' => 'words', |
| 74 |
'label' => __( 'Words', 'desktop-mode' ), |
| 75 |
'type' => 'number', |
| 76 |
), |
| 77 |
array( |
| 78 |
'key' => 'wpm', |
| 79 |
'label' => __( 'WPM', 'desktop-mode' ), |
| 80 |
'type' => 'number', |
| 81 |
), |
| 82 |
array( |
| 83 |
'key' => 'accuracy', |
| 84 |
'label' => __( 'Accuracy', 'desktop-mode' ), |
| 85 |
'type' => 'number', |
| 86 |
), |
| 87 |
array( |
| 88 |
'key' => 'time', |
| 89 |
'label' => __( 'Time', 'desktop-mode' ), |
| 90 |
'type' => 'time', |
| 91 |
), |
| 92 |
array( |
| 93 |
'key' => 'level', |
| 94 |
'label' => __( 'Level', 'desktop-mode' ), |
| 95 |
'type' => 'number', |
| 96 |
), |
| 97 |
), |
| 98 |
// The dictionary URL arrives via the framework-injected |
| 99 |
// `wordsUrl` config key (see includes/games/config.php). |
| 100 |
) |
| 101 |
); |
| 102 |
} |
| 103 |
add_action( 'init', 'openstation_inkfall_register', 20 ); |
| 104 |
|
| 105 |
/** |
| 106 |
* Ride the Inkfall window styles on the Games window as a companion. |
| 107 |
* |
| 108 |
* The game's script is lazily loaded by the framework on first |
| 109 |
* launch, and every launch goes through the games bundle — so a |
| 110 |
* sheet travelling with that bundle is in the tab before the game |
| 111 |
* window paints, without costing every admin page that never plays. |
| 112 |
* |
| 113 |
* @param array $window_args Args passed to `openstation_register_window()`. |
| 114 |
* @return array |
| 115 |
*/ |
| 116 |
function openstation_inkfall_window_styles( $window_args ) { |
| 117 |
if ( ! is_array( $window_args ) ) { |
| 118 |
return $window_args; |
| 119 |
} |
| 120 |
$window_args['styles'] = isset( $window_args['styles'] ) ? (array) $window_args['styles'] : array(); |
| 121 |
$window_args['styles'][] = 'os-game-inkfall'; |
| 122 |
return $window_args; |
| 123 |
} |
| 124 |
add_filter( 'openstation_games_window_args', 'openstation_inkfall_window_styles' ); |
| 125 |
|