| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation — Games framework config. |
| 4 |
* |
| 5 |
* Framework-level values every game receives on its launch-context |
| 6 |
* `config` (merged in by the `serverGames` payload builder; a game's |
| 7 |
* own `config` keys win on collision): |
| 8 |
* |
| 9 |
* - `wordsUrl` — URL of the shared dictionary asset |
| 10 |
* (`assets/games/words.txt`). The word list is a |
| 11 |
* framework asset, not a per-game one: it is |
| 12 |
* identical for every player, which is what lets |
| 13 |
* seeded games generate the same puzzle worldwide. |
| 14 |
* |
| 15 |
* @package OpenStation |
| 16 |
*/ |
| 17 |
|
| 18 |
defined( 'ABSPATH' ) || exit; |
| 19 |
|
| 20 |
/** |
| 21 |
* URL of the shared games dictionary asset, cache-busted on content |
| 22 |
* change (the browser caches the ~150 KB list across sessions |
| 23 |
* otherwise). |
| 24 |
* |
| 25 |
* @return string The dictionary URL. |
| 26 |
*/ |
| 27 |
function openstation_games_words_url() { |
| 28 |
$words_file = OPENSTATION_DIR . 'assets/games/words.txt'; |
| 29 |
$words_url = OPENSTATION_URL . 'assets/games/words.txt'; |
| 30 |
if ( file_exists( $words_file ) ) { |
| 31 |
$words_url = add_query_arg( 'ver', (string) filemtime( $words_file ), $words_url ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Filters the URL of the shared games dictionary asset. |
| 36 |
* |
| 37 |
* Seeded games generate identical puzzles worldwide only while |
| 38 |
* every player resolves the same word list — swap the URL for |
| 39 |
* all users (a translated list, a themed list), not per user. |
| 40 |
* |
| 41 |
* @param string $words_url The dictionary URL (with `ver` cache-bust). |
| 42 |
*/ |
| 43 |
return (string) apply_filters( 'openstation_games_words_url', $words_url ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* The framework-level `config` keys merged into every game's launch |
| 48 |
* context. A game's own `config` wins on collision. |
| 49 |
* |
| 50 |
* @internal |
| 51 |
* |
| 52 |
* @return array Framework config keys. |
| 53 |
*/ |
| 54 |
function openstation_games_framework_config() { |
| 55 |
return array( |
| 56 |
'wordsUrl' => esc_url_raw( openstation_games_words_url() ), |
| 57 |
); |
| 58 |
} |
| 59 |
|