getConstants();
}
public static function get_effect_type_icon( string $effect_type ): string {
return match ( $effect_type ) {
self::DRUNK => '',
self::HEAL => '',
self::POISON => '',
self::POISON_IMMUNITY => '',
default => '',
};
}
}
// define global restriction types (array of strings)
$adventurebook_restriction_types = array( 'none', 'item', 'game_var', 'stat', 'skill', 'no_enemies' );
// directions for decisions - used for auto-generating a map
$adventurebook_decision_dirs = array( 'none', 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'northwest', 'enter', 'exit', 'up', 'down', 'ship' );
function adventurebook_get_reverse_dir(string $dir): string {
switch ( $dir ) {
case 'north':
return 'south';
case 'northeast':
return 'southwest';
case 'east':
return 'west';
case 'southeast':
return 'northwest';
case 'south':
return 'north';
case 'southwest':
return 'northeast';
case 'west':
return 'east';
case 'northwest':
return 'southeast';
case 'enter':
return 'exit';
case 'exit':
return 'enter';
case 'up':
return 'down';
case 'down':
return 'up';
default:
return 'none';
}
}
/**
* Returns the prefix for a decision dir (direction), e.g. ↑ for "north", → for "east", etc.
*
* @param string $dir Directory path
*
* @return string Prefix for the directory
*/
function adventurebook_get_prefix_for_dir( string $dir ): string {
$dir = strtolower( $dir );
// Mappe Richtungen auf CSS-Klassen
$valid_dirs = [
'north', 'south', 'east', 'west',
'northeast', 'northwest', 'southeast', 'southwest',
'enter', 'exit', 'up', 'down', 'ship'
];
if ( ! in_array( $dir, $valid_dirs, true ) ) {
return '';
}
// Für enter/exit/up/down/ship spezielle Symbole
switch ( $dir ) {
case 'enter': $output = '⎆︎ '; break;
case 'exit': $output = '⇠︎ '; break;
case 'up': $output = '⇡︎ '; break;
case 'down': $output = '⇣︎ '; break;
case 'ship': $output = '⚓︎ '; break;
default: $output = '⬆︎ '; break;
}
return wp_kses($output, array(
'span' => array(
'class' => array(),
),
));
}
/**
* returns the icon (font awesome) for a given equipment slot
* Slots handled: Weapon, Shield, Helmet, Armor, Boots, Gloves, Amulet, Ring, Cape
*
* @param string $slot
* @return string
*/
function adventurebook_get_icon_for_slot( string $slot) : string {
$slot = strtolower( $slot );
$emoji = match ( $slot ) {
'weapon' => '⚔️', // swords
'shield' => '🛡️', // shield
'helmet' => '⛑️', // helmet
'armor' => '🦺', // safety vest as armor proxy
'boots' => '🥾', // hiking boot
'gloves' => '🧤', // gloves
'amulet' => '📿', // prayer beads as amulet
'ring' => '💍', // ring
'cape' => '🧣', // scarf as cape proxy
default => '📦', // box
};
$html = '' . $emoji . '';
return apply_filters('adventurebook_slot_icon', $html, $slot);
}
if ( ! function_exists( 'ab_get' ) ) {
/**
* Safely get a value from the $_REQUEST superglobal.
*
* @param string $key The key to retrieve from the $_REQUEST array.
* @return string The sanitized value from the $_REQUEST array, or an empty string if the key does not exist.
*/
function ab_get( string $key ): string {
return sanitize_text_field( wp_unslash( $_REQUEST[ $key ] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
}
/**
* Check if the given page has directional decisions
* Iterate through all decisions and check if any has a direction set
* This is used for displaying directional arrows on the map and setting the "fixed" layout for this node (page))
*
* @param int $page_id The ID of the adventurebook page
* @return bool True if the page has directional decisions, false otherwise
*/
function adventurebook_page_has_directional_decisions(int $page_id) : bool {
$decisions = get_post_meta($page_id, '_adventurebook_decision_options', true);
if (!is_array($decisions)) {
return false;
}
foreach ($decisions as $decision) {
$dir = strtolower(trim($decision['decision_dir'] ?? ''));
if ($dir != '' && $dir != 'none') {
return true;
}
}
return false;
}