Fixed palette lookup
This commit is contained in:
@@ -15,7 +15,8 @@ add_subdirectory(locale)
|
|||||||
add_asset(SCRIPT init.lua)
|
add_asset(SCRIPT init.lua)
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(entity)
|
# add_subdirectory(entity)
|
||||||
add_subdirectory(map)
|
# add_subdirectory(map)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
||||||
add_subdirectory(scene)
|
add_subdirectory(minesweeper)
|
||||||
|
add_subdirectory(scene)
|
||||||
|
|||||||
6
assets/minesweeper/CMakeLists.txt
Normal file
6
assets/minesweeper/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
add_asset(TILESET ui.png type=PALETTIZED tileWidth=8 tileHeight=8)
|
||||||
BIN
assets/minesweeper/background.png
Normal file
BIN
assets/minesweeper/background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
BIN
assets/minesweeper/border.png
Normal file
BIN
assets/minesweeper/border.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
BIN
assets/minesweeper/cell.png
Normal file
BIN
assets/minesweeper/cell.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
BIN
assets/minesweeper/grid.png
Normal file
BIN
assets/minesweeper/grid.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
BIN
assets/minesweeper/ui.png
Normal file
BIN
assets/minesweeper/ui.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -3,4 +3,5 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
add_asset(PALETTE palette0.png)
|
add_asset(PALETTE palette0.png)
|
||||||
|
add_asset(PALETTE paletteMinesweeper.png)
|
||||||
BIN
assets/palette/paletteMinesweeper.png
Normal file
BIN
assets/palette/paletteMinesweeper.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 127 B |
@@ -3,4 +3,5 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
add_asset(SCRIPT initial.lua)
|
add_asset(SCRIPT initial.lua)
|
||||||
|
add_asset(SCRIPT minesweeper.lua)
|
||||||
27
assets/scene/minesweeper.lua
Normal file
27
assets/scene/minesweeper.lua
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
module('spritebatch')
|
||||||
|
module('camera')
|
||||||
|
module('color')
|
||||||
|
module('ui')
|
||||||
|
module('screen')
|
||||||
|
module('time')
|
||||||
|
module('glm')
|
||||||
|
|
||||||
|
screenSetBackground(colorBlack())
|
||||||
|
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
||||||
|
|
||||||
|
function sceneDispose()
|
||||||
|
end
|
||||||
|
|
||||||
|
function sceneUpdate()
|
||||||
|
end
|
||||||
|
|
||||||
|
function sceneRender()
|
||||||
|
-- UI
|
||||||
|
cameraPushMatrix(camera)
|
||||||
|
camera.bottom = screenGetHeight()
|
||||||
|
camera.right = screenGetWidth()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cameraPopMatrix()
|
||||||
|
end
|
||||||
@@ -35,10 +35,23 @@ def processPalettizedImage(asset):
|
|||||||
imagePalette = extractPaletteFromImage(image)
|
imagePalette = extractPaletteFromImage(image)
|
||||||
|
|
||||||
# Find palette that contains every color
|
# Find palette that contains every color
|
||||||
for palette in palettes:
|
palette = None
|
||||||
if all(color in palette['pixels'] for color in imagePalette):
|
for p in palettes:
|
||||||
|
hasAllColors = True
|
||||||
|
for color in imagePalette:
|
||||||
|
for palColor in p['pixels']:
|
||||||
|
if color[0] == palColor[0] and color[1] == palColor[1] and color[2] == palColor[2] and color[3] == palColor[3]:
|
||||||
|
break
|
||||||
|
elif color[3] == 0 and palColor[3] == 0:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
hasAllColors = False
|
||||||
|
break
|
||||||
|
if hasAllColors:
|
||||||
|
palette = p
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
|
if palette is None:
|
||||||
palette = palettes[0] # Just to avoid reference error
|
palette = palettes[0] # Just to avoid reference error
|
||||||
print(f"No matching palette found for {assetPath}!")
|
print(f"No matching palette found for {assetPath}!")
|
||||||
# Find which pixel is missing
|
# Find which pixel is missing
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import datetime
|
import datetime
|
||||||
@@ -78,6 +79,7 @@ def processPalette(asset):
|
|||||||
|
|
||||||
def processPaletteList():
|
def processPaletteList():
|
||||||
data = f"// Auto-generated palette list\n"
|
data = f"// Auto-generated palette list\n"
|
||||||
|
print(f"Generating palette list with {len(palettes)} palettes.")
|
||||||
for palette in palettes:
|
for palette in palettes:
|
||||||
data += f"#include \"{palette['headerFile']}\"\n"
|
data += f"#include \"{palette['headerFile']}\"\n"
|
||||||
data += f"\n"
|
data += f"\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user