template.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. if (!interface_exists('MapTemplateInterface')) {
  3. interface MapTemplateInterface
  4. {
  5. public static function id(): string;
  6. public static function applyTemplate($map): void;
  7. public static function tileDefinitions(): array;
  8. }
  9. }
  10. class RuralTemplate implements MapTemplateInterface
  11. {
  12. public static function id(): string
  13. {
  14. return 'rural';
  15. }
  16. public static function applyTemplate($map): void
  17. {
  18. if (!method_exists($map, 'getHexes')) return;
  19. $hexes = $map->getHexes();
  20. $i = 0;
  21. foreach ($hexes as $k => $h) {
  22. // marquer approximativement 10% comme forêt
  23. if ($i++ % 10 === 0) {
  24. if (method_exists($h, 'setTile')) $h->setTile('forest');
  25. }
  26. }
  27. }
  28. public static function tileDefinitions(): array
  29. {
  30. return [
  31. ['id' => 'forest', 'name' => 'Forêt', 'color' => '#228B22', 'asset' => '/assets/tiles/forest.svg'],
  32. ['id' => 'field', 'name' => 'Champ', 'color' => '#F4A460', 'asset' => '/assets/tiles/field.svg'],
  33. ['id' => 'road_straight', 'name' => 'Route droite', 'color' => '#D2B48C', 'asset' => '/assets/tiles/road-straight.svg'],
  34. ['id' => 'road_right', 'name' => 'Route tourne à droite', 'color' => '#D2B48C', 'asset' => '/assets/tiles/road-right.svg'],
  35. ['id' => 'road_left', 'name' => 'Route tourne à gauche', 'color' => '#D2B48C', 'asset' => '/assets/tiles/road-left.svg'],
  36. ['id' => 'villa', 'name' => 'Villa', 'color' => '#F5DEB3', 'asset' => '/assets/tiles/villa.svg']
  37. ];
  38. }
  39. }