mirror of
https://git.srhtnin.garden/sarah/srhtnin.github.io.git
synced 2026-10-14 02:38:12 +02:00
Changed naming scheme of plant stages (1, 2, 3 instead of Seed, Sprout,
Mature).
This commit is contained in:
1 parent
c558a4988f
commit
bf15c48c10
7 files changed
+392
-104
No files matched your search
@@ -103,6 +103,220 @@ function RenderPage(
|
||||
);
|
||||
}
|
||||
|
||||
function GeneratePlantImageManifest(
|
||||
string $RootDirectory,
|
||||
string $OutputDirectory
|
||||
): void {
|
||||
$PlantsDirectory =
|
||||
$RootDirectory .
|
||||
"/Assets/Img/Garden/Plants";
|
||||
|
||||
$Manifest = [];
|
||||
|
||||
if (!is_dir($PlantsDirectory)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (
|
||||
new DirectoryIterator(
|
||||
$PlantsDirectory
|
||||
)
|
||||
as $PlantDirectory
|
||||
) {
|
||||
if (
|
||||
$PlantDirectory->isDot() ||
|
||||
!$PlantDirectory->isDir()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$PlantName =
|
||||
$PlantDirectory->getFilename();
|
||||
|
||||
$Manifest[$PlantName] = [];
|
||||
|
||||
|
||||
foreach (
|
||||
new DirectoryIterator(
|
||||
$PlantDirectory->getPathname()
|
||||
)
|
||||
as $VariantDirectory
|
||||
) {
|
||||
if (
|
||||
$VariantDirectory->isDot() ||
|
||||
!$VariantDirectory->isDir()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$VariantName =
|
||||
$VariantDirectory->getFilename();
|
||||
|
||||
$Images = [];
|
||||
|
||||
|
||||
foreach (
|
||||
new DirectoryIterator(
|
||||
$VariantDirectory->getPathname()
|
||||
)
|
||||
as $Image
|
||||
) {
|
||||
if (!$Image->isFile()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
preg_match(
|
||||
"/^([0-9]+)\.png$/i",
|
||||
$Image->getFilename(),
|
||||
$Matches
|
||||
) !== 1
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ImageNumber =
|
||||
(int) $Matches[1];
|
||||
|
||||
if ($ImageNumber < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$Images[$ImageNumber] =
|
||||
"/Assets/Img/Garden/Plants/" .
|
||||
$PlantName .
|
||||
"/" .
|
||||
$VariantName .
|
||||
"/" .
|
||||
$Image->getFilename();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sort numerically:
|
||||
*
|
||||
* 1.png
|
||||
* 2.png
|
||||
* ...
|
||||
* 10.png
|
||||
*
|
||||
* instead of:
|
||||
*
|
||||
* 1.png
|
||||
* 10.png
|
||||
* 2.png
|
||||
*/
|
||||
|
||||
ksort(
|
||||
$Images,
|
||||
SORT_NUMERIC
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Require consecutive numbering.
|
||||
*/
|
||||
|
||||
$ExpectedNumber = 1;
|
||||
|
||||
foreach (
|
||||
array_keys($Images)
|
||||
as $ImageNumber
|
||||
) {
|
||||
if (
|
||||
$ImageNumber !==
|
||||
$ExpectedNumber
|
||||
) {
|
||||
throw new RuntimeException(
|
||||
"Missing plant image " .
|
||||
$ExpectedNumber .
|
||||
".png in " .
|
||||
$PlantName .
|
||||
"/" .
|
||||
$VariantName
|
||||
);
|
||||
}
|
||||
|
||||
$ExpectedNumber++;
|
||||
}
|
||||
|
||||
|
||||
if (count($Images) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$Manifest[
|
||||
$PlantName
|
||||
][
|
||||
$VariantName
|
||||
] = array_values(
|
||||
$Images
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
count(
|
||||
$Manifest[$PlantName]
|
||||
) === 0
|
||||
) {
|
||||
unset(
|
||||
$Manifest[$PlantName]
|
||||
);
|
||||
} else {
|
||||
ksort(
|
||||
$Manifest[$PlantName],
|
||||
SORT_NATURAL |
|
||||
SORT_FLAG_CASE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ksort(
|
||||
$Manifest,
|
||||
SORT_NATURAL |
|
||||
SORT_FLAG_CASE
|
||||
);
|
||||
|
||||
|
||||
$ManifestDirectory =
|
||||
$OutputDirectory .
|
||||
"/Scripts/Garden";
|
||||
|
||||
if (!is_dir($ManifestDirectory)) {
|
||||
mkdir(
|
||||
$ManifestDirectory,
|
||||
0777,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$Json = json_encode(
|
||||
$Manifest,
|
||||
JSON_PRETTY_PRINT |
|
||||
JSON_UNESCAPED_SLASHES |
|
||||
JSON_UNESCAPED_UNICODE |
|
||||
JSON_THROW_ON_ERROR
|
||||
);
|
||||
|
||||
|
||||
file_put_contents(
|
||||
$ManifestDirectory .
|
||||
"/PlantImages.js",
|
||||
|
||||
"const PlantImages = " .
|
||||
$Json .
|
||||
";" .
|
||||
PHP_EOL
|
||||
);
|
||||
|
||||
|
||||
echo
|
||||
"Generated Scripts/Garden/PlantImages.js" .
|
||||
PHP_EOL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the previous build.
|
||||
@@ -134,6 +348,10 @@ foreach ($StaticDirectories as $Directory) {
|
||||
);
|
||||
}
|
||||
|
||||
GeneratePlantImageManifest(
|
||||
$RootDirectory,
|
||||
$OutputDirectory
|
||||
);
|
||||
|
||||
/*
|
||||
* Copy index.html.
|
||||
@@ -145,7 +363,6 @@ foreach ($StaticDirectories as $Directory) {
|
||||
"./"
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Build PHP pages.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user