template.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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' => '#2b7a2b'],
  32. ['id' => 'field', 'name' => 'Champ', 'color' => '#f4ecb0']
  33. ];
  34. }
  35. }