BlueGit

blue-star tribegen

change image resolution, improved colouring method

timfa Tim Falken · pushed by timfa

Authored 2026-01-28 · 9 months ago

Hash
c9349784443eebdaf9d362f8e208b881a1a1d610
Parent
edd0ed4f
7 files changed +45 −11
web/assets/sprites/standard/adult.png Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/baby.png Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/egg.png Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/old.png Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/young.png Binary file +0 −0

The contents of this binary file are not shown.

web/src/Classes/Kobold.php +32 −10
@@ -493,17 +493,39 @@ class Kobold
493 493 $newG = 0;
494 494 $newB = 0;
495 495
496 $newR += (int) (($baseR / 255.0) * $primaryRGB['r']);
497 $newG += (int) (($baseR / 255.0) * $primaryRGB['g']);
498 $newB += (int) (($baseR / 255.0) * $primaryRGB['b']);
496 $rW = $baseR / 255.0;
497 $gW = $baseG / 255.0;
498 $bW = $baseB / 255.0;
499
500 $sum = $rW + $gW + $bW;
501
502 if ($sum > 0) {
503 $newR = ($rW * $primaryRGB['r']
504 + $gW * $secondaryRGB['r']
505 + $bW * $tertiaryRGB['r']) / $sum;
506
507 $newG = ($rW * $primaryRGB['g']
508 + $gW * $secondaryRGB['g']
509 + $bW * $tertiaryRGB['g']) / $sum;
510
511 $newB = ($rW * $primaryRGB['b']
512 + $gW * $secondaryRGB['b']
513 + $bW * $tertiaryRGB['b']) / $sum;
514 } else {
515 $newR = $newG = $newB = 0;
516 }
517
518 $w = min($baseR, $baseG, $baseB) / 255.0;
519
520 $newR = (int) round($newR + (255 - $newR) * $w);
521 $newG = (int) round($newG + (255 - $newG) * $w);
522 $newB = (int) round($newB + (255 - $newB) * $w);
499 523
500 $newR += (int) (($baseG / 255.0) * $secondaryRGB['r']);
501 $newG += (int) (($baseG / 255.0) * $secondaryRGB['g']);
502 $newB += (int) (($baseG / 255.0) * $secondaryRGB['b']);
524 $intensity = max($baseR, $baseG, $baseB) / 255.0; // 0..1 (how "strong" the mask is)
503 525
504 $newR += (int) (($baseB / 255.0) * $tertiaryRGB['r']);
505 $newG += (int) (($baseB / 255.0) * $tertiaryRGB['g']);
506 $newB += (int) (($baseB / 255.0) * $tertiaryRGB['b']);
526 $newR *= $intensity;
527 $newG *= $intensity;
528 $newB *= $intensity;
507 529
508 530 $newR = max(0, min(255, $newR));
509 531 $newG = max(0, min(255, $newG));
@@ -511,7 +533,7 @@ class Kobold
511 533
512 534 $key = $newR . ',' . $newG . ',' . $newB . ',' . $baseA;
513 535 if (!isset($cache[$key])) {
514 $cache[$key] = imagecolorallocatealpha($image, $newR, $newG, $newB, $baseA);
536 $cache[$key] = imagecolorallocatealpha($image, intval($newR), intval($newG), intval($newB), intval($baseA));
515 537 }
516 538
517 539 imagesetpixel($image, $x, $y, $cache[$key]);
@@ -493,17 +493,39 @@ class Kobold
493 $newG = 0;
493 $newG = 0;
494 $newB = 0;
494 $newB = 0;
495
495
496 $newR += (int) (($baseR / 255.0) * $primaryRGB['r']);
496 $rW = $baseR / 255.0;
497 $newG += (int) (($baseR / 255.0) * $primaryRGB['g']);
497 $gW = $baseG / 255.0;
498 $newB += (int) (($baseR / 255.0) * $primaryRGB['b']);
498 $bW = $baseB / 255.0;
499
500 $sum = $rW + $gW + $bW;
501
502 if ($sum > 0) {
503 $newR = ($rW * $primaryRGB['r']
504 + $gW * $secondaryRGB['r']
505 + $bW * $tertiaryRGB['r']) / $sum;
506
507 $newG = ($rW * $primaryRGB['g']
508 + $gW * $secondaryRGB['g']
509 + $bW * $tertiaryRGB['g']) / $sum;
510
511 $newB = ($rW * $primaryRGB['b']
512 + $gW * $secondaryRGB['b']
513 + $bW * $tertiaryRGB['b']) / $sum;
514 } else {
515 $newR = $newG = $newB = 0;
516 }
517
518 $w = min($baseR, $baseG, $baseB) / 255.0;
519
520 $newR = (int) round($newR + (255 - $newR) * $w);
521 $newG = (int) round($newG + (255 - $newG) * $w);
522 $newB = (int) round($newB + (255 - $newB) * $w);
499
523
500 $newR += (int) (($baseG / 255.0) * $secondaryRGB['r']);
524 $intensity = max($baseR, $baseG, $baseB) / 255.0; // 0..1 (how "strong" the mask is)
501 $newG += (int) (($baseG / 255.0) * $secondaryRGB['g']);
502 $newB += (int) (($baseG / 255.0) * $secondaryRGB['b']);
503
525
504 $newR += (int) (($baseB / 255.0) * $tertiaryRGB['r']);
526 $newR *= $intensity;
505 $newG += (int) (($baseB / 255.0) * $tertiaryRGB['g']);
527 $newG *= $intensity;
506 $newB += (int) (($baseB / 255.0) * $tertiaryRGB['b']);
528 $newB *= $intensity;
507
529
508 $newR = max(0, min(255, $newR));
530 $newR = max(0, min(255, $newR));
509 $newG = max(0, min(255, $newG));
531 $newG = max(0, min(255, $newG));
@@ -511,7 +533,7 @@ class Kobold
511
533
512 $key = $newR . ',' . $newG . ',' . $newB . ',' . $baseA;
534 $key = $newR . ',' . $newG . ',' . $newB . ',' . $baseA;
513 if (!isset($cache[$key])) {
535 if (!isset($cache[$key])) {
514 $cache[$key] = imagecolorallocatealpha($image, $newR, $newG, $newB, $baseA);
536 $cache[$key] = imagecolorallocatealpha($image, intval($newR), intval($newG), intval($newB), intval($baseA));
515 }
537 }
516
538
517 imagesetpixel($image, $x, $y, $cache[$key]);
539 imagesetpixel($image, $x, $y, $cache[$key]);
web/src/Database/Database.php +13 −1
@@ -7,7 +7,19 @@ class Database
7 7
8 8 private function __construct()
9 9 {
10 $dbPath = __DIR__ . '\\..\\..\\data\\tribegen.db';
10 $dataDir = __DIR__ . '\\..\\..\\data\\';
11 $dbPath = $dataDir . 'tribegen.db';
12
13 if (!is_dir($dataDir)) {
14 if (!mkdir($dataDir, 0775, true) && !is_dir($dataDir)) {
15 throw new RuntimeException("Failed to create data directory: $dataDir");
16 }
17 }
18
19 if (!is_writable($dataDir)) {
20 throw new RuntimeException("Data directory is not writable: $dataDir");
21 }
22
11 23 $this->pdo = new \PDO('sqlite:' . $dbPath);
12 24 $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
13 25 $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
@@ -7,7 +7,19 @@ class Database
7
7
8 private function __construct()
8 private function __construct()
9 {
9 {
10 $dbPath = __DIR__ . '\\..\\..\\data\\tribegen.db';
10 $dataDir = __DIR__ . '\\..\\..\\data\\';
11 $dbPath = $dataDir . 'tribegen.db';
12
13 if (!is_dir($dataDir)) {
14 if (!mkdir($dataDir, 0775, true) && !is_dir($dataDir)) {
15 throw new RuntimeException("Failed to create data directory: $dataDir");
16 }
17 }
18
19 if (!is_writable($dataDir)) {
20 throw new RuntimeException("Data directory is not writable: $dataDir");
21 }
22
11 $this->pdo = new \PDO('sqlite:' . $dbPath);
23 $this->pdo = new \PDO('sqlite:' . $dbPath);
12 $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
24 $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
13 $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
25 $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);