From 6301f63bd348109b8693a922f02e16d49205a8fd Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 9 Jan 2024 16:16:56 +0100 Subject: enable indentation for gemini templates --- src/View.php | 14 +- views/gemini/send-resources/01-resource-types.twig | 3 +- views/gemini/send-resources/02-villages.twig | 2 +- views/gemini/send-units/01-units.twig | 2 +- views/gemini/send-units/02-villages.twig | 2 +- views/gemini/village.twig | 181 ++++++++++----------- views/gemini/villages.twig | 6 +- 7 files changed, 110 insertions(+), 100 deletions(-) diff --git a/src/View.php b/src/View.php index 1c29a67..10ce9db 100644 --- a/src/View.php +++ b/src/View.php @@ -40,6 +40,18 @@ class View */ public static function render(string $name, array $context = []): string { - return self::$twig->render($name, $context); + if (isset($_ENV['GEMINI'])) { + $string = self::$twig->render($name, $context); + $lines = explode(PHP_EOL, $string); + $output = ''; + + foreach ($lines as $line) { + $output .= ltrim($line, ' \t') . "\r\n"; + } + + return $output; + } else { + return self::$twig->render($name, $context); + } } } diff --git a/views/gemini/send-resources/01-resource-types.twig b/views/gemini/send-resources/01-resource-types.twig index 586aa1e..a71afd4 100644 --- a/views/gemini/send-resources/01-resource-types.twig +++ b/views/gemini/send-resources/01-resource-types.twig @@ -1,4 +1,5 @@ Sendable Resource Capability: {{ marketplace.getResourceCapabilities(village) }} + {% for resourceType in ['wood', 'clay', 'iron', 'food'] %} -=> /village/{{ village.x }}/{{ village.y }}/send-resources/type/{{ resourceType }} {{ resourceType }} + => /village/{{ village.x }}/{{ village.y }}/send-resources/type/{{ resourceType }} {{ resourceType }} {% endfor %} diff --git a/views/gemini/send-resources/02-villages.twig b/views/gemini/send-resources/02-villages.twig index 54ccc5c..5cc0e75 100644 --- a/views/gemini/send-resources/02-villages.twig +++ b/views/gemini/send-resources/02-villages.twig @@ -2,5 +2,5 @@ Sendable Resource Capability: {{ marketplace.getResourceCapabilities(village) }} {% for listVillage in villages %} -=> /village/{{ village.x }}/{{ village.y }}/send-resources/type/{{ selectedResourceType }}/village/{{ listVillage.x }}/{{ listVillage.y }} {{ listVillage.name }} - {{ listVillage.x }} x {{ listVillage.y }} + => /village/{{ village.x }}/{{ village.y }}/send-resources/type/{{ selectedResourceType }}/village/{{ listVillage.x }}/{{ listVillage.y }} {{ listVillage.name }} - {{ listVillage.x }} x {{ listVillage.y }} {% endfor %} diff --git a/views/gemini/send-units/01-units.twig b/views/gemini/send-units/01-units.twig index 6996c3b..60883bf 100644 --- a/views/gemini/send-units/01-units.twig +++ b/views/gemini/send-units/01-units.twig @@ -1,3 +1,3 @@ {% for unit in village.getUnits(village.id, 1) %} -=> /village/{{ village.x }}/{{ village.y }}/send-units/type/{{ unit.type }} {{ unit.type }} + => /village/{{ village.x }}/{{ village.y }}/send-units/type/{{ unit.type }} {{ unit.type }} {% endfor %} diff --git a/views/gemini/send-units/02-villages.twig b/views/gemini/send-units/02-villages.twig index ea2741c..69170c8 100644 --- a/views/gemini/send-units/02-villages.twig +++ b/views/gemini/send-units/02-villages.twig @@ -1,5 +1,5 @@ {{ selectedUnit }} {% for listVillage in villages %} -=> /village/{{ village.x }}/{{ village.y }}/send-units/type/{{ selectedUnit }}/village/{{ listVillage.x }}/{{ listVillage.y }} {{ listVillage.name }} - {{ listVillage.x }} x {{ listVillage.y }} + => /village/{{ village.x }}/{{ village.y }}/send-units/type/{{ selectedUnit }}/village/{{ listVillage.x }}/{{ listVillage.y }} {{ listVillage.name }} - {{ listVillage.x }} x {{ listVillage.y }} {% endfor %} diff --git a/views/gemini/village.twig b/views/gemini/village.twig index d448020..21c480b 100644 --- a/views/gemini/village.twig +++ b/views/gemini/village.twig @@ -19,120 +19,117 @@ Storage Capacity: {{ village.getStorage(village.id).getCapacity() }} # Events {% if events['UpgradeBuilding'] %} -## Upgrade Building -{% for typeEvents in events['UpgradeBuilding'] %} -{% for event in typeEvents %} -### {{ event.type }} -Finished: {{ event.event.time | date('c') }} -=> /village/{{ village.x }}/{{ village.y }}/building/UpgradeBuilding/build/cancel Cancel -{% endfor %} -{% endfor %} + ## Upgrade Building + {% for typeEvents in events['UpgradeBuilding'] %} + {% for event in typeEvents %} + ### {{ event.type }} + Finished: {{ event.event.time | date('c') }} + => /village/{{ village.x }}/{{ village.y }}/building/UpgradeBuilding/build/cancel Cancel + {% endfor %} + {% endfor %} {% endif %} - {% if events['TrainUnits'] %} -## Train Units -{% for event in events['TrainUnits'] %} -### {{ event.type }} -Amount: {{ event.amount }} -Finished: {{ event.event.time | date('c') }} -=> /village/{{ village.x }}/{{ village.y }}/unit/train/cancel Cancel -{% endfor %} + ## Train Units + {% for event in events['TrainUnits'] %} + ### {{ event.type }} + Amount: {{ event.amount }} + Finished: {{ event.event.time | date('c') }} + => /village/{{ village.x }}/{{ village.y }}/unit/train/cancel Cancel + {% endfor %} {% endif %} - {% if events['SendUnits'] %} -## Send Units -{% for event in events['SendUnits'] %} -### {{ event.unit }} - {{ event.type }} -Amount: {{ event.amount }} -Source: {{ village.get(event.source).name }} -Destination: {{ village.get(event.destination).name }} -Finished: {{ event.event.time | date('c') }} -{% if event.isCanceled %} -Canceled -{% else %} -{% if event.event.villageId == village.id %} -=> /event/{{ event.event.id }}/cancel Cancel + ## Send Units + {% for event in events['SendUnits'] %} + ### {{ event.unit }} - {{ event.type }} + Amount: {{ event.amount }} + Source: {{ village.get(event.source).name }} + Destination: {{ village.get(event.destination).name }} + Finished: {{ event.event.time | date('c') }} + {% if event.isCanceled %} + Canceled + {% else %} + {% if event.event.villageId == village.id %} + => /event/{{ event.event.id }}/cancel Cancel + {% endif %} + {% endif %} + {% endfor %} {% endif %} -{% endif %} -{% endfor %} -{% endif %} - {% if events['SendResources'] %} -## Send Resources -{% for event in events['SendResources'] %} -### {{ village.get(event.source).name }} -> {{ village.get(event.destination).name }} -Wood: {{ event.wood }} -Clay: {{ event.clay }} -Iron: {{ event.iron }} -Food: {{ event.food }} -Source: {{ village.get(event.source).name }} -Destination: {{ village.get(event.destination).name }} -Finished: {{ event.event.time | date('c') }} -{% if event.isCanceled %} -Canceled -{% else %} -{% if event.event.villageId == village.id %} -=> /event/{{ event.event.id }}/cancel Cancel -{% endif %} -{% endif %} -{% endfor %} + ## Send Resources + {% for event in events['SendResources'] %} + ### {{ village.get(event.source).name }} -> {{ village.get(event.destination).name }} + Wood: {{ event.wood }} + Clay: {{ event.clay }} + Iron: {{ event.iron }} + Food: {{ event.food }} + Source: {{ village.get(event.source).name }} + Destination: {{ village.get(event.destination).name }} + Finished: {{ event.event.time | date('c') }} + {% if event.isCanceled %} + Canceled + {% else %} + {% if event.event.villageId == village.id %} + => /event/{{ event.event.id }}/cancel Cancel + {% endif %} + {% endif %} + {% endfor %} {% endif %} # Buildings {% for building in buildings %} -## {{ building.type }} -Level: {{ building.level | default(0) }} -Build Time: {{ building.getBuildTimeForLevel(building.getEffectiveLevel() + 1) | buildTime }} -Resources: -* Wood: {{ building.getResourceRequirementsForLevel(building.getEffectiveLevel() + 1)['wood'] }} -* Clay: {{ building.getResourceRequirementsForLevel(building.getEffectiveLevel() + 1)['clay'] }} -* Iron: {{ building.getResourceRequirementsForLevel(building.getEffectiveLevel() + 1)['iron'] }} -=> /village/{{ village.x }}/{{ village.y }}/building/{{ building.type }}/manage Manage -{% if village.canBuild(village, building) %} -=> /village/{{ village.x }}/{{ village.y }}/building/{{ building.type }}/level-up Level up -{% endif %} + ## {{ building.type }} + Level: {{ building.level | default(0) }} + Build Time: {{ building.getBuildTimeForLevel(building.getEffectiveLevel() + 1) | buildTime }} + Resources: + * Wood: {{ building.getResourceRequirementsForLevel(building.getEffectiveLevel() + 1)['wood'] }} + * Clay: {{ building.getResourceRequirementsForLevel(building.getEffectiveLevel() + 1)['clay'] }} + * Iron: {{ building.getResourceRequirementsForLevel(building.getEffectiveLevel() + 1)['iron'] }} + => /village/{{ village.x }}/{{ village.y }}/building/{{ building.type }}/manage Manage + {% if village.canBuild(village, building) %} + => /village/{{ village.x }}/{{ village.y }}/building/{{ building.type }}/level-up Level up + {% endif %} {% endfor %} # Units At Home {% for unit in village.getUnits(village.id, 1, 3) %} -## {{ unit.type }} -Amount: {{ unit.amount }} -{% if not unit.isTraveling %} -Build Time: {{ unit.getBuildTime(1) | buildTime }} -Resources: -* Wood: {{ unit.getResourceRequirements(unit, 1)['wood'] }} -* Clay: {{ unit.getResourceRequirements(unit, 1)['clay'] }} -* Iron: {{ unit.getResourceRequirements(unit, 1)['iron'] }} -* Food: {{ unit.getResourceRequirements(unit, 1)['food'] ?? 0 }} -{% if village.canTrain(village, unit, 1) %} -=> /village/{{ village.x }}/{{ village.y }}/unit/{{ unit.type }}/create Train -{% endif %} -=> /village/{{ village.x }}/{{ village.y }}/send-units/type/{{ unit.type }} Send -{% else %} -~traveling~ -{% endif %} + ## {{ unit.type }} + Amount: {{ unit.amount }} + {% if not unit.isTraveling %} + Build Time: {{ unit.getBuildTime(1) | buildTime }} + Resources: + * Wood: {{ unit.getResourceRequirements(unit, 1)['wood'] }} + * Clay: {{ unit.getResourceRequirements(unit, 1)['clay'] }} + * Iron: {{ unit.getResourceRequirements(unit, 1)['iron'] }} + * Food: {{ unit.getResourceRequirements(unit, 1)['food'] ?? 0 }} + {% if village.canTrain(village, unit, 1) %} + => /village/{{ village.x }}/{{ village.y }}/unit/{{ unit.type }}/create Train + {% endif %} + => /village/{{ village.x }}/{{ village.y }}/send-units/type/{{ unit.type }} Send + {% else %} + ~traveling~ + {% endif %} {% endfor %} # Units Supporting {% for unit in village.getUnits(village.id, 2) | merge(village.getUnits(village.id, 3)) %} -## {{ unit.type }} -Amount: {{ unit.amount }} -Origin: {{ village.get(unit.homeVillageId).name }} -Location: {{ not unit.isTraveling ? village.get(unit.residenceVillageId).name : '~traveling~' }} -Travel Time: {{ unit.getTravelTime(unit, village.getDistance(unit.getHomeVillage().x, unit.getHomeVillage().x, unit.getResidenceVillage().x, unit.getResidenceVillage().y)) | buildTime }} -{% if not unit.isTraveling %} -{% if unit.homeVillageId == village.id %} -=> /village/{{ village.x }}/{{ village.y }}/unit/{{ unit.type }}/location/{{ unit.getResidenceVillage().x }}/{{ unit.getResidenceVillage().y }}/recall Recall Home -{% else %} -=> /village/{{ village.x }}/{{ village.y }}/unit/{{ unit.type }}/location/{{ unit.getHomeVillage().x }}/{{ unit.getHomeVillage().y }}/send-back Send Back -{% endif %} -{% endif %} + ## {{ unit.type }} + Amount: {{ unit.amount }} + Origin: {{ village.get(unit.homeVillageId).name }} + Location: {{ not unit.isTraveling ? village.get(unit.residenceVillageId).name : '~traveling~' }} + Travel Time: {{ unit.getTravelTime(unit, village.getDistance(unit.getHomeVillage().x, unit.getHomeVillage().x, unit.getResidenceVillage().x, unit.getResidenceVillage().y)) | buildTime }} + {% if not unit.isTraveling %} + {% if unit.homeVillageId == village.id %} + => /village/{{ village.x }}/{{ village.y }}/unit/{{ unit.type }}/location/{{ unit.getResidenceVillage().x }}/{{ unit.getResidenceVillage().y }}/recall Recall Home + {% else %} + => /village/{{ village.x }}/{{ village.y }}/unit/{{ unit.type }}/location/{{ unit.getHomeVillage().x }}/{{ unit.getHomeVillage().y }}/send-back Send Back + {% endif %} + {% endif %} {% endfor %} @@ -142,9 +139,9 @@ Travel Time: {{ unit.getTravelTime(unit, village.getDistance(unit.getHomeVillage {% if village.canSendResources(village) %} -# Send Resources + # Send Resources -{% include 'send-resources/01-resource-types.twig' %} + {% include 'send-resources/01-resource-types.twig' %} {% endif %} diff --git a/views/gemini/villages.twig b/views/gemini/villages.twig index fb0f606..f49435d 100644 --- a/views/gemini/villages.twig +++ b/views/gemini/villages.twig @@ -1,9 +1,9 @@ # Your villages {% for village in villages %} -=> /village/{{ village.x }}/{{ village.y }} {{ village.name }} - {{ village.x }} x {{ village.y }} -Resources: {{ village.wood + village.clay + village.iron + village.food }} / {{ village.getStorage(village.id).getCapacity() }} -Satisfaction: {{ village.satisfaction }} + => /village/{{ village.x }}/{{ village.y }} {{ village.name }} - {{ village.x }} x {{ village.y }} + Resources: {{ village.wood + village.clay + village.iron + village.food }} / {{ village.getStorage(village.id).getCapacity() }} + Satisfaction: {{ village.satisfaction }} {% endfor %} -- cgit v1.2.3