Mostly nuking old system
This commit is contained in:
1 parent
b37e5f45ca
commit
e5e8c49f6c
97 files changed
+1454
-408
No files matched your search
+1
-11
@@ -4,14 +4,4 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(run_python)
|
||||
add_subdirectory(env_to_h)
|
||||
|
||||
# Function that adds an asset to be compiled
|
||||
function(add_asset ASSET_TYPE ASSET_PATH)
|
||||
set(FULL_ASSET_PATH "${CMAKE_CURRENT_LIST_DIR}/${ASSET_PATH}")
|
||||
string(JOIN "%" ASSETS_ARGS ${ARGN})
|
||||
list(APPEND DUSK_ASSETS
|
||||
"${ASSET_TYPE}#${FULL_ASSET_PATH}#${ASSETS_ARGS}"
|
||||
)
|
||||
set(DUSK_ASSETS ${DUSK_ASSETS} CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
endfunction()
|
||||
add_subdirectory(env_to_h)
|
||||
@@ -1,12 +0,0 @@
|
||||
import sys, os
|
||||
import argparse
|
||||
|
||||
# Check if the script is run with the correct arguments
|
||||
parser = argparse.ArgumentParser(description="Generate chunk header files")
|
||||
parser.add_argument('--assets', required=True, help='Dir to output built assets')
|
||||
parser.add_argument('--headers-dir', required=True, help='Directory to output individual asset headers (required for header build)')
|
||||
parser.add_argument('--output-headers', help='Output header file for built assets (required for header build)')
|
||||
parser.add_argument('--output-assets', required=True, help='Output directory for built assets')
|
||||
parser.add_argument('--output-file', required=True, help='Output file for built assets (required for wad build)')
|
||||
parser.add_argument('--input', required=True, help='Input assets to process', nargs='+')
|
||||
args = parser.parse_args()
|
||||
@@ -1,66 +0,0 @@
|
||||
import sys, os
|
||||
from tools.asset.args import args
|
||||
from tools.asset.process.asset import processAsset
|
||||
from tools.asset.process.palette import processPaletteList
|
||||
from tools.asset.process.tileset import processTilesetList
|
||||
from tools.asset.process.language import processLanguageList
|
||||
from tools.asset.path import getBuiltAssetsRelativePath
|
||||
import zipfile
|
||||
|
||||
# Parse input file args.
|
||||
inputAssets = []
|
||||
for inputArg in args.input:
|
||||
files = inputArg.split('$')
|
||||
for file in files:
|
||||
if str(file).strip() == '':
|
||||
continue
|
||||
|
||||
pieces = file.split('#')
|
||||
|
||||
if len(pieces) < 2:
|
||||
print(f"Error: Invalid input asset format '{file}'. Expected format: type#path[#option1%option2...]")
|
||||
sys.exit(1)
|
||||
|
||||
options = {}
|
||||
if len(pieces) > 2:
|
||||
optionParts = pieces[2].split('%')
|
||||
for part in optionParts:
|
||||
partSplit = part.split('=')
|
||||
|
||||
if len(partSplit) < 1:
|
||||
continue
|
||||
if len(partSplit) == 2:
|
||||
options[partSplit[0]] = partSplit[1]
|
||||
else:
|
||||
options[partSplit[0]] = True
|
||||
|
||||
inputAssets.append({
|
||||
'type': pieces[0],
|
||||
'path': pieces[1],
|
||||
'options': options
|
||||
})
|
||||
|
||||
if not inputAssets:
|
||||
print("Error: No input assets provided.")
|
||||
sys.exit(1)
|
||||
|
||||
# Process each asset.
|
||||
files = []
|
||||
for asset in inputAssets:
|
||||
asset = processAsset(asset)
|
||||
files.extend(asset['files'])
|
||||
|
||||
# Generate additional files
|
||||
files.extend(processLanguageList()['files'])
|
||||
|
||||
# Take assets and add to a zip archive.
|
||||
outputFileName = args.output_file
|
||||
print(f"Creating output file: {outputFileName}")
|
||||
with zipfile.ZipFile(outputFileName, 'w') as zipf:
|
||||
for file in files:
|
||||
relativeOutputPath = getBuiltAssetsRelativePath(file)
|
||||
zipf.write(file, arcname=relativeOutputPath)
|
||||
|
||||
# Generate additional headers.
|
||||
processPaletteList()
|
||||
processTilesetList()
|
||||
@@ -1,12 +0,0 @@
|
||||
processedAssets = {}
|
||||
|
||||
def assetGetCache(assetPath):
|
||||
if assetPath in processedAssets:
|
||||
return processedAssets[assetPath]
|
||||
return None
|
||||
|
||||
def assetCache(assetPath, processedData):
|
||||
if assetPath in processedAssets:
|
||||
return processedAssets[assetPath]
|
||||
processedAssets[assetPath] = processedData
|
||||
return processedData
|
||||
@@ -1,10 +0,0 @@
|
||||
import os
|
||||
from tools.asset.args import args
|
||||
|
||||
def getAssetRelativePath(fullPath):
|
||||
# Get the relative path to the asset
|
||||
return os.path.relpath(fullPath, start=args.assets).replace('\\', '/')
|
||||
|
||||
def getBuiltAssetsRelativePath(fullPath):
|
||||
# Get the relative path to the built asset
|
||||
return os.path.relpath(fullPath, start=args.output_assets).replace('\\', '/')
|
||||
@@ -1,33 +0,0 @@
|
||||
import sys
|
||||
# from processtileset import processTileset
|
||||
from tools.asset.process.image import processImage
|
||||
from tools.asset.process.palette import processPalette
|
||||
from tools.asset.process.tileset import processTileset
|
||||
from tools.asset.process.map import processMap
|
||||
from tools.asset.process.language import processLanguage
|
||||
from tools.asset.process.script import processScript
|
||||
|
||||
processedAssets = []
|
||||
|
||||
def processAsset(asset):
|
||||
if asset['path'] in processedAssets:
|
||||
return
|
||||
processedAssets.append(asset['path'])
|
||||
|
||||
# Handle tiled tilesets
|
||||
t = asset['type'].lower()
|
||||
if t == 'palette':
|
||||
return processPalette(asset)
|
||||
elif t == 'image':
|
||||
return processImage(asset)
|
||||
elif t == 'tileset':
|
||||
return processTileset(asset)
|
||||
elif t == 'map':
|
||||
return processMap(asset)
|
||||
elif t == 'language':
|
||||
return processLanguage(asset)
|
||||
elif t == 'script':
|
||||
return processScript(asset)
|
||||
else:
|
||||
print(f"Error: Unknown asset type '{asset['type']}' for path '{asset['path']}'")
|
||||
sys.exit(1)
|
||||
@@ -1,134 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
from PIL import Image
|
||||
from tools.asset.process.palette import extractPaletteFromImage, palettes
|
||||
from tools.asset.args import args
|
||||
from tools.asset.path import getAssetRelativePath
|
||||
from tools.asset.cache import assetGetCache, assetCache
|
||||
|
||||
images = []
|
||||
|
||||
def processImage(asset):
|
||||
cache = assetGetCache(asset['path'])
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
type = None
|
||||
if 'type' in asset['options']:
|
||||
type = asset['options'].get('type', 'PALETTIZED').upper()
|
||||
|
||||
if type == 'PALETTIZED' or type is None:
|
||||
return assetCache(asset['path'], processPalettizedImage(asset))
|
||||
elif type == 'ALPHA':
|
||||
return assetCache(asset['path'], processAlphaImage(asset))
|
||||
else:
|
||||
print(f"Error: Unknown image type {type} for asset {asset['path']}")
|
||||
sys.exit(1)
|
||||
|
||||
def processPalettizedImage(asset):
|
||||
assetPath = asset['path']
|
||||
cache = assetGetCache(assetPath)
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
image = Image.open(assetPath)
|
||||
imagePalette = extractPaletteFromImage(image)
|
||||
|
||||
# Find palette that contains every color
|
||||
palette = None
|
||||
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:
|
||||
print('Pallete {} does not contain color #{}'.format(p['paletteName'], '{:02x}{:02x}{:02x}{:02x}'.format(color[0], color[1], color[2], color[3])))
|
||||
hasAllColors = False
|
||||
break
|
||||
if hasAllColors:
|
||||
palette = p
|
||||
break
|
||||
|
||||
if palette is None:
|
||||
palette = palettes[0] # Just to avoid reference error
|
||||
print(f"No matching palette found for {assetPath}!")
|
||||
# Find which pixel is missing
|
||||
for color in imagePalette:
|
||||
if color in palette['pixels']:
|
||||
continue
|
||||
# Convert to hex (with alpha)
|
||||
hexColor = '#{:02x}{:02x}{:02x}{:02x}'.format(color[0], color[1], color[2], color[3])
|
||||
print(f"Missing color: {hexColor} in palette {palette['paletteName']}")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"Converting image {assetPath} to use palette")
|
||||
|
||||
paletteIndexes = []
|
||||
for pixel in list(image.getdata()):
|
||||
if pixel[3] == 0:
|
||||
pixel = (0, 0, 0, 0)
|
||||
paletteIndex = palette['pixels'].index(pixel)
|
||||
paletteIndexes.append(paletteIndex)
|
||||
|
||||
data = bytearray()
|
||||
data.extend(b"DPI") # Dusk Palettized Image
|
||||
data.extend(image.width.to_bytes(4, 'little')) # Width
|
||||
data.extend(image.height.to_bytes(4, 'little')) # Height
|
||||
data.append(palette['paletteIndex']) # Palette index
|
||||
for paletteIndex in paletteIndexes:
|
||||
if paletteIndex > 255 or paletteIndex < 0:
|
||||
print(f"Error: Palette index {paletteIndex} exceeds 255!")
|
||||
sys.exit(1)
|
||||
data.append(paletteIndex.to_bytes(1, 'little')[0]) # Pixel index
|
||||
|
||||
relative = getAssetRelativePath(assetPath)
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(assetPath))[0]
|
||||
outputFileRelative = os.path.join(os.path.dirname(relative), f"{fileNameWithoutExt}.dpi")
|
||||
outputFilePath = os.path.join(args.output_assets, outputFileRelative)
|
||||
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
|
||||
with open(outputFilePath, "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
outImage = {
|
||||
"imagePath": outputFileRelative,
|
||||
"files": [ outputFilePath ],
|
||||
'width': image.width,
|
||||
'height': image.height,
|
||||
}
|
||||
return assetCache(assetPath, outImage)
|
||||
|
||||
def processAlphaImage(asset):
|
||||
assetPath = asset['path']
|
||||
cache = assetGetCache(assetPath)
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
print(f"Processing alpha image: {assetPath}")
|
||||
|
||||
data = bytearray()
|
||||
data.extend(b"DAI") # Dusk Alpha Image
|
||||
image = Image.open(assetPath).convert("RGBA")
|
||||
data.extend(image.width.to_bytes(4, 'little')) # Width
|
||||
data.extend(image.height.to_bytes(4, 'little')) # Height
|
||||
for pixel in list(image.getdata()):
|
||||
# Only write alpha channel
|
||||
data.append(pixel[3].to_bytes(1, 'little')[0]) # Pixel alpha
|
||||
|
||||
relative = getAssetRelativePath(assetPath)
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(assetPath))[0]
|
||||
outputFileRelative = os.path.join(os.path.dirname(relative), f"{fileNameWithoutExt}.dai")
|
||||
outputFilePath = os.path.join(args.output_assets, outputFileRelative)
|
||||
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
|
||||
with open(outputFilePath, "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
outImage = {
|
||||
"imagePath": outputFileRelative,
|
||||
"files": [ outputFilePath ],
|
||||
'width': image.width,
|
||||
'height': image.height,
|
||||
}
|
||||
return assetCache(assetPath, outImage)
|
||||
@@ -1,228 +0,0 @@
|
||||
import sys
|
||||
import os
|
||||
from tools.asset.args import args
|
||||
from tools.asset.cache import assetCache, assetGetCache
|
||||
from tools.asset.path import getAssetRelativePath
|
||||
from tools.dusk.defs import defs
|
||||
import polib
|
||||
import re
|
||||
|
||||
LANGUAGE_CHUNK_CHAR_COUNT = int(defs.get('ASSET_LANG_CHUNK_CHAR_COUNT'))
|
||||
|
||||
LANGUAGE_DATA = {}
|
||||
LANGUAGE_KEYS = []
|
||||
|
||||
def processLanguageList():
|
||||
# Language keys header data
|
||||
headerKeys = "// Auto-generated language keys header file.\n"
|
||||
headerKeys += "#pragma once\n"
|
||||
headerKeys += "#include \"dusk.h\"\n\n"
|
||||
|
||||
# This is the desired chunk groups list.. if a language key STARTS with any
|
||||
# of the keys in this list we would "like to" put it in that chunk group.
|
||||
# If there is no match, or the list is full then we will add it to the next
|
||||
# available chunk group (that isn't a 'desired' one). If the chunk becomes
|
||||
# full, then we attempt to make another chunk with the same prefix so that
|
||||
# a second batching can occur.
|
||||
desiredChunkGroups = {
|
||||
'ui': 0
|
||||
}
|
||||
|
||||
# Now, for each language key, create the header reference and index.
|
||||
keyIndex = 0
|
||||
languageKeyIndexes = {}
|
||||
languageKeyChunk = {}
|
||||
languageKeyChunkIndexes = {}
|
||||
languageKeyChunkOffsets = {}
|
||||
for key in LANGUAGE_KEYS:
|
||||
headerKeys += f"#define {getLanguageVariableName(key)} {keyIndex}\n"
|
||||
languageKeyIndexes[key] = keyIndex
|
||||
keyIndex += 1
|
||||
|
||||
# Find desired chunk group
|
||||
assignedChunk = None
|
||||
for desiredKey in desiredChunkGroups:
|
||||
if key.lower().startswith(desiredKey):
|
||||
assignedChunk = desiredChunkGroups[desiredKey]
|
||||
break
|
||||
# If no desired chunk group matched, assign to -1
|
||||
if assignedChunk is None:
|
||||
assignedChunk = -1
|
||||
languageKeyChunk[key] = assignedChunk
|
||||
|
||||
# Setup header.
|
||||
for lang in LANGUAGE_DATA:
|
||||
if key not in LANGUAGE_DATA[lang]:
|
||||
print(f"Warning: Missing translation for key '{key}' in language '{lang}'")
|
||||
sys.exit(1)
|
||||
|
||||
# Seal the header.
|
||||
headerKeys += f"\n#define LANG_KEY_COUNT {len(LANGUAGE_KEYS)}\n"
|
||||
|
||||
# Now we can generate the language string chunks.
|
||||
nextChunkIndex = max(desiredChunkGroups.values()) + 1
|
||||
files = []
|
||||
|
||||
for lang in LANGUAGE_DATA:
|
||||
langData = LANGUAGE_DATA[lang]
|
||||
|
||||
# Key = chunkIndex, value = chunkInfo
|
||||
languageChunks = {}
|
||||
for key in LANGUAGE_KEYS:
|
||||
keyIndex = languageKeyIndexes[key]
|
||||
chunkIndex = languageKeyChunk[key]
|
||||
wasSetChunk = chunkIndex != -1
|
||||
|
||||
# This will keep looping until we find a chunk
|
||||
while True:
|
||||
# Determine the next chunkIndex IF chunkIndex is -1
|
||||
if chunkIndex == -1:
|
||||
chunkIndex = nextChunkIndex
|
||||
|
||||
# Is the chunk full?
|
||||
curLen = languageChunks.get(chunkIndex, {'len': 0})['len']
|
||||
newLen = curLen + len(langData[key])
|
||||
if newLen > LANGUAGE_CHUNK_CHAR_COUNT:
|
||||
# Chunk is full, need to create a new chunk.
|
||||
chunkIndex = -1
|
||||
if wasSetChunk:
|
||||
wasSetChunk = False
|
||||
else:
|
||||
nextChunkIndex += 1
|
||||
continue
|
||||
|
||||
# Chunk is not full, we can use it.
|
||||
if chunkIndex not in languageChunks:
|
||||
languageChunks[chunkIndex] = {
|
||||
'len': 0,
|
||||
'keys': []
|
||||
}
|
||||
languageChunks[chunkIndex]['len'] = newLen
|
||||
languageChunks[chunkIndex]['keys'].append(key)
|
||||
languageKeyChunkIndexes[key] = chunkIndex
|
||||
languageKeyChunkOffsets[key] = curLen
|
||||
break
|
||||
|
||||
# We have now chunked all the keys for this language!
|
||||
langBuffer = b""
|
||||
|
||||
# Write header info
|
||||
langBuffer += b'DLF' # Dusk Language File
|
||||
|
||||
for key in LANGUAGE_KEYS:
|
||||
# Write the chunk that this key belongs to as uint32_t
|
||||
chunkIndex = languageKeyChunkIndexes[key]
|
||||
langBuffer += chunkIndex.to_bytes(4, byteorder='little')
|
||||
|
||||
# Write the offset for this key as uint32_t
|
||||
offset = languageKeyChunkOffsets[key]
|
||||
langBuffer += offset.to_bytes(4, byteorder='little')
|
||||
|
||||
# Write the length of the string as uint32_t
|
||||
strData = langData[key].encode('utf-8')
|
||||
langBuffer += len(strData).to_bytes(4, byteorder='little')
|
||||
|
||||
# Now write out each chunk's string data, packed tight and no null term.
|
||||
for chunkIndex in sorted(languageChunks.keys()):
|
||||
chunkInfo = languageChunks[chunkIndex]
|
||||
for key in chunkInfo['keys']:
|
||||
strData = langData[key].encode('utf-8')
|
||||
langBuffer += strData
|
||||
|
||||
# Now pad the chunk to full size
|
||||
curLen = chunkInfo['len']
|
||||
if curLen < LANGUAGE_CHUNK_CHAR_COUNT:
|
||||
padSize = LANGUAGE_CHUNK_CHAR_COUNT - curLen
|
||||
langBuffer += b'\0' * padSize
|
||||
|
||||
# Write out the language data file
|
||||
outputFile = os.path.join(args.output_assets, "language", f"{lang}.dlf")
|
||||
files.append(outputFile)
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, "wb") as f:
|
||||
f.write(langBuffer)
|
||||
|
||||
# Write out the language keys header file
|
||||
outputFile = os.path.join(args.headers_dir, "locale", "language", "keys.h")
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, "w") as f:
|
||||
f.write(headerKeys)
|
||||
|
||||
# Generate language list.
|
||||
langValues = {}
|
||||
headerLocale = "#pragma once\n#include \"locale/localeinfo.h\"\n\n"
|
||||
headerLocale += "typedef enum {\n"
|
||||
count = 0
|
||||
headerLocale += f" DUSK_LOCALE_NULL = {count},\n"
|
||||
count += 1
|
||||
for lang in LANGUAGE_DATA:
|
||||
langKey = lang.replace('-', '_').replace(' ', '_').upper()
|
||||
langValues[lang] = count
|
||||
headerLocale += f" DUSK_LOCALE_{langKey} = {count},\n"
|
||||
count += 1
|
||||
headerLocale += f" DUSK_LOCALE_COUNT = {count}\n"
|
||||
headerLocale += "} dusklocale_t;\n\n"
|
||||
|
||||
headerLocale += f"static const localeinfo_t LOCALE_INFOS[DUSK_LOCALE_COUNT] = {{\n"
|
||||
for lang in LANGUAGE_DATA:
|
||||
langKey = lang.replace('-', '_').replace(' ', '_').upper()
|
||||
headerLocale += f" [DUSK_LOCALE_{langKey}] = {{\n"
|
||||
headerLocale += f" .file = \"{lang}\"\n"
|
||||
headerLocale += f" }},\n"
|
||||
headerLocale += "};\n"
|
||||
|
||||
headerLocale += f"static const char_t *LOCALE_SCRIPT = \n"
|
||||
for lang in LANGUAGE_DATA:
|
||||
langKey = lang.replace('-', '_').replace(' ', '_').upper()
|
||||
langValue = langValues[lang]
|
||||
headerLocale += f" \"DUSK_LOCALE_{langKey} = {langValue}\\n\"\n"
|
||||
headerLocale += ";\n"
|
||||
|
||||
# Write out the locale enum header file
|
||||
outputFile = os.path.join(args.headers_dir, "locale", "locale.h")
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, "w") as f:
|
||||
f.write(headerLocale)
|
||||
|
||||
return {
|
||||
'files': files
|
||||
}
|
||||
|
||||
def getLanguageVariableName(languageKey):
|
||||
# Take the language key, prepend LANG_, uppercase, replace any non symbols
|
||||
# with _
|
||||
key = languageKey.strip().upper()
|
||||
key = re.sub(r'[^A-Z0-9]', '_', key)
|
||||
return f"LANG_{key}"
|
||||
|
||||
def processLanguage(asset):
|
||||
cache = assetGetCache(asset['path'])
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
# Load PO File
|
||||
po = polib.pofile(asset['path'])
|
||||
|
||||
langName = po.metadata.get('Language')
|
||||
if langName not in LANGUAGE_DATA:
|
||||
LANGUAGE_DATA[langName] = {}
|
||||
|
||||
for entry in po:
|
||||
key = entry.msgid
|
||||
val = entry.msgstr
|
||||
|
||||
if key not in LANGUAGE_KEYS:
|
||||
LANGUAGE_KEYS.append(key)
|
||||
|
||||
if key not in LANGUAGE_DATA[langName]:
|
||||
LANGUAGE_DATA[langName][key] = val
|
||||
else:
|
||||
print(f"Error: Duplicate translation key '{key}' in language '{langName}'")
|
||||
sys.exit(1)
|
||||
|
||||
outLanguageData = {
|
||||
'data': po,
|
||||
'path': asset['path'],
|
||||
'files': []
|
||||
}
|
||||
return assetCache(asset['path'], outLanguageData)
|
||||
@@ -1,154 +0,0 @@
|
||||
import struct
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
from tools.asset.args import args
|
||||
from tools.asset.cache import assetCache, assetGetCache
|
||||
from tools.asset.path import getAssetRelativePath
|
||||
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, CHUNK_TILE_COUNT
|
||||
from tools.dusk.map import Map
|
||||
from tools.dusk.chunk import Chunk
|
||||
|
||||
def convertModelData(modelData):
|
||||
# TLDR; Model data stores things efficiently with indices, but we buffer it
|
||||
# out to 6 vertex quads for simplicity.
|
||||
outVertices = []
|
||||
outUVs = []
|
||||
outColors = []
|
||||
for indice in modelData['indices']:
|
||||
vertex = modelData['vertices'][indice]
|
||||
uv = modelData['uvs'][indice]
|
||||
color = modelData['colors'][indice]
|
||||
outVertices.append(vertex)
|
||||
outUVs.append(uv)
|
||||
outColors.append(color)
|
||||
|
||||
return {
|
||||
'vertices': outVertices,
|
||||
'uvs': outUVs,
|
||||
'colors': outColors
|
||||
}
|
||||
|
||||
def processChunk(chunk):
|
||||
cache = assetGetCache(chunk.getFilename())
|
||||
if cache:
|
||||
return cache
|
||||
|
||||
baseModel = {
|
||||
'vertices': [],
|
||||
'colors': [],
|
||||
'uvs': []
|
||||
}
|
||||
models = [ baseModel ]
|
||||
|
||||
for tileIndex, tile in chunk.tiles.items():
|
||||
tileBase = tile.getBaseTileModel()
|
||||
|
||||
convertedBase = convertModelData(tileBase)
|
||||
baseModel['vertices'].extend(convertedBase['vertices'])
|
||||
baseModel['colors'].extend(convertedBase['colors'])
|
||||
baseModel['uvs'].extend(convertedBase['uvs'])
|
||||
|
||||
# Generate binary buffer for efficient output
|
||||
buffer = bytearray()
|
||||
buffer.extend(b'DMC')# Header
|
||||
buffer.extend(len(chunk.tiles).to_bytes(4, 'little')) # Number of tiles
|
||||
buffer.extend(len(models).to_bytes(1, 'little')) # Number of models
|
||||
buffer.extend(len(chunk.entities).to_bytes(1, 'little')) # Number of entities
|
||||
|
||||
# Buffer tile data as array of uint8_t
|
||||
for tileIndex, tile in chunk.tiles.items():
|
||||
buffer.extend(tile.shape.to_bytes(1, 'little'))
|
||||
|
||||
# # For each model
|
||||
for model in models:
|
||||
vertexCount = len(model['vertices'])
|
||||
buffer.extend(vertexCount.to_bytes(4, 'little'))
|
||||
for i in range(vertexCount):
|
||||
vertex = model['vertices'][i]
|
||||
uv = model['uvs'][i]
|
||||
color = model['colors'][i]
|
||||
|
||||
buffer.extend(color[0].to_bytes(1, 'little'))
|
||||
buffer.extend(color[1].to_bytes(1, 'little'))
|
||||
buffer.extend(color[2].to_bytes(1, 'little'))
|
||||
buffer.extend(color[3].to_bytes(1, 'little'))
|
||||
|
||||
buffer.extend(bytearray(struct.pack('<f', uv[0])))
|
||||
buffer.extend(bytearray(struct.pack('<f', uv[1])))
|
||||
|
||||
buffer.extend(bytearray(struct.pack('<f', vertex[0])))
|
||||
buffer.extend(bytearray(struct.pack('<f', vertex[1])))
|
||||
buffer.extend(bytearray(struct.pack('<f', vertex[2])))
|
||||
|
||||
# For each entity
|
||||
for entity in chunk.entities.values():
|
||||
buffer.extend(entity.type.to_bytes(1, 'little'))
|
||||
buffer.extend(entity.localX.to_bytes(1, 'little'))
|
||||
buffer.extend(entity.localY.to_bytes(1, 'little'))
|
||||
buffer.extend(entity.localZ.to_bytes(1, 'little'))
|
||||
pass
|
||||
|
||||
# Write out map file
|
||||
relative = getAssetRelativePath(chunk.getFilename())
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(relative))[0]
|
||||
outputFileRelative = os.path.join(os.path.dirname(relative), f"{fileNameWithoutExt}.dmc")
|
||||
outputFilePath = os.path.join(args.output_assets, outputFileRelative)
|
||||
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
|
||||
with open(outputFilePath, "wb") as f:
|
||||
f.write(buffer)
|
||||
|
||||
outChunk = {
|
||||
'files': [ outputFilePath ],
|
||||
'chunk': chunk
|
||||
}
|
||||
return assetCache(chunk.getFilename(), outChunk)
|
||||
|
||||
def processMap(asset):
|
||||
cache = assetGetCache(asset['path'])
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
map = Map(None)
|
||||
map.load(asset['path'])
|
||||
chunksDir = map.getChunkDirectory()
|
||||
|
||||
files = os.listdir(chunksDir)
|
||||
if len(files) == 0:
|
||||
print(f"Error: No chunk files found in {chunksDir}.")
|
||||
sys.exit(1)
|
||||
|
||||
chunkFiles = []
|
||||
for fileName in files:
|
||||
if not fileName.endswith('.json'):
|
||||
continue
|
||||
|
||||
fNameNoExt = os.path.splitext(fileName)[0]
|
||||
fnPieces = fNameNoExt.split('_')
|
||||
if len(fnPieces) != 3:
|
||||
print(f"Error: Chunk filename {fileName} does not contain valid chunk coordinates.")
|
||||
sys.exit(1)
|
||||
chunk = Chunk(map, int(fnPieces[0]), int(fnPieces[1]), int(fnPieces[2]))
|
||||
chunk.load()
|
||||
result = processChunk(chunk)
|
||||
chunkFiles.extend(result['files'])
|
||||
|
||||
# Map file
|
||||
outBuffer = bytearray()
|
||||
outBuffer.extend(b'DMF')
|
||||
outBuffer.extend(len(chunkFiles).to_bytes(4, 'little'))
|
||||
|
||||
# DMF (Dusk Map file)
|
||||
fileRelative = getAssetRelativePath(asset['path'])
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(fileRelative))[0]
|
||||
outputMapRelative = os.path.join(os.path.dirname(fileRelative), f"{fileNameWithoutExt}.dmf")
|
||||
outputMapPath = os.path.join(args.output_assets, outputMapRelative)
|
||||
os.makedirs(os.path.dirname(outputMapPath), exist_ok=True)
|
||||
with open(outputMapPath, "wb") as f:
|
||||
f.write(outBuffer)
|
||||
|
||||
outMap = {
|
||||
'files': chunkFiles
|
||||
}
|
||||
outMap['files'].append(outputMapPath)
|
||||
return assetCache(asset['path'], outMap)
|
||||
@@ -1,96 +0,0 @@
|
||||
import json
|
||||
import os
|
||||
from PIL import Image
|
||||
import datetime
|
||||
from tools.asset.args import args
|
||||
from tools.asset.cache import assetCache, assetGetCache
|
||||
|
||||
palettes = []
|
||||
|
||||
def extractPaletteFromImage(image):
|
||||
# goes through and finds all unique colors in the image
|
||||
if image.mode != 'RGBA':
|
||||
image = image.convert('RGBA')
|
||||
pixels = list(image.getdata())
|
||||
uniqueColors = []
|
||||
for color in pixels:
|
||||
# We treat all alpha 0 as rgba(0,0,0,0) for palette purposes
|
||||
if color[3] == 0:
|
||||
color = (0, 0, 0, 0)
|
||||
if color not in uniqueColors:
|
||||
uniqueColors.append(color)
|
||||
return uniqueColors
|
||||
|
||||
def processPalette(asset):
|
||||
print(f"Processing palette: {asset['path']}")
|
||||
cache = assetGetCache(asset['path'])
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
paletteIndex = len(palettes)
|
||||
image = Image.open(asset['path'])
|
||||
pixels = extractPaletteFromImage(image)
|
||||
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(asset['path']))[0]
|
||||
fileNameWithoutPalette = os.path.splitext(fileNameWithoutExt)[0]
|
||||
|
||||
# PSP requires that the palette size be a power of two, so we will pad the
|
||||
# palette with transparent colors if needed.
|
||||
def mathNextPowTwo(x):
|
||||
return 1 << (x - 1).bit_length()
|
||||
|
||||
nextPowTwo = mathNextPowTwo(len(pixels))
|
||||
while len(pixels) < nextPowTwo:
|
||||
pixels.append((0, 0, 0, 0))
|
||||
|
||||
# Header
|
||||
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
data = f"// Palette Generated for {asset['path']} at {now}\n"
|
||||
data += f"#include \"display/palette/palette.h\"\n\n"
|
||||
data += f"#define PALETTE_{paletteIndex}_COLOR_COUNT {len(pixels)}\n\n"
|
||||
data += f"#pragma pack(push, 1)\n"
|
||||
data += f"static const color_t PALETTE_{paletteIndex}_COLORS[PALETTE_{paletteIndex}_COLOR_COUNT] = {{\n"
|
||||
for pixel in pixels:
|
||||
data += f" {{ 0x{pixel[0]:02X}, 0x{pixel[1]:02X}, 0x{pixel[2]:02X}, 0x{pixel[3]:02X} }},\n"
|
||||
data += f"}};\n"
|
||||
data += f"#pragma pack(pop)\n\n"
|
||||
data += f"static const palette_t PALETTE_{paletteIndex} = {{\n"
|
||||
data += f" .colorCount = PALETTE_{paletteIndex}_COLOR_COUNT,\n"
|
||||
data += f" .colors = PALETTE_{paletteIndex}_COLORS,\n"
|
||||
data += f"}};\n"
|
||||
|
||||
# Write Header
|
||||
outputFile = os.path.join(args.headers_dir, "display", "palette", f"palette_{paletteIndex}.h")
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, "w") as f:
|
||||
f.write(data)
|
||||
|
||||
palette = {
|
||||
"paletteIndex": paletteIndex,
|
||||
"paletteName": fileNameWithoutPalette,
|
||||
"pixels": pixels,
|
||||
"headerFile": os.path.relpath(outputFile, args.headers_dir),
|
||||
"asset": asset,
|
||||
"files": [ ],# No zippable files.
|
||||
}
|
||||
|
||||
palettes.append(palette)
|
||||
return assetCache(asset['path'], palette)
|
||||
|
||||
def processPaletteList():
|
||||
data = f"// Auto-generated palette list\n"
|
||||
print(f"Generating palette list with {len(palettes)} palettes.")
|
||||
for palette in palettes:
|
||||
data += f"#include \"{palette['headerFile']}\"\n"
|
||||
data += f"\n"
|
||||
data += f"#define PALETTE_LIST_COUNT {len(palettes)}\n\n"
|
||||
data += f"static const palette_t* PALETTE_LIST[PALETTE_LIST_COUNT] = {{\n"
|
||||
for palette in palettes:
|
||||
data += f" &PALETTE_{palette['paletteIndex']},\n"
|
||||
data += f"}};\n"
|
||||
|
||||
# Write the palette list to a header file
|
||||
outputFile = os.path.join(args.headers_dir, "display", "palette", "palettelist.h")
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, "w") as f:
|
||||
f.write(data)
|
||||
@@ -1,43 +0,0 @@
|
||||
import sys
|
||||
import os
|
||||
from tools.asset.args import args
|
||||
from tools.asset.cache import assetCache, assetGetCache
|
||||
from tools.asset.path import getAssetRelativePath
|
||||
from tools.dusk.defs import fileDefs
|
||||
|
||||
def processScript(asset):
|
||||
cache = assetGetCache(asset['path'])
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
# Load the lua file as a string
|
||||
with open(asset['path'], 'r', encoding='utf-8') as f:
|
||||
luaCode = f.read()
|
||||
|
||||
# TODO: I will precompile or minify the Lua code here in the future
|
||||
|
||||
# Replace all definitions in the code
|
||||
for key, val in fileDefs.items():
|
||||
luaCode = luaCode.replace(key, str(val))
|
||||
|
||||
# Create output Dusk Script File (DSF) data
|
||||
data = ""
|
||||
data += "DSF"
|
||||
data += luaCode
|
||||
|
||||
# Write to relative output file path.
|
||||
relative = getAssetRelativePath(asset['path'])
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(asset['path']))[0]
|
||||
outputFileRelative = os.path.join(os.path.dirname(relative), f"{fileNameWithoutExt}.dsf")
|
||||
outputFilePath = os.path.join(args.output_assets, outputFileRelative)
|
||||
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
|
||||
with open(outputFilePath, "wb") as f:
|
||||
f.write(data.encode('utf-8'))
|
||||
|
||||
outScript = {
|
||||
'data': data,
|
||||
'path': asset['path'],
|
||||
'files': [ outputFilePath ],
|
||||
'scriptPath': outputFileRelative,
|
||||
}
|
||||
return assetCache(asset['path'], outScript)
|
||||
@@ -1,178 +0,0 @@
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
import datetime
|
||||
from xml.etree import ElementTree
|
||||
from tools.asset.process.image import processImage
|
||||
from tools.asset.path import getAssetRelativePath
|
||||
from tools.asset.args import args
|
||||
from tools.asset.cache import assetGetCache, assetCache
|
||||
|
||||
tilesets = []
|
||||
|
||||
def loadTilesetFromTSX(asset):
|
||||
# Load the TSX file
|
||||
tree = ElementTree.parse(asset['path'])
|
||||
root = tree.getroot()
|
||||
|
||||
# Expect tileheight, tilewidth, columns and tilecount attributes
|
||||
if 'tilewidth' not in root.attrib or 'tileheight' not in root.attrib or 'columns' not in root.attrib or 'tilecount' not in root.attrib:
|
||||
print(f"Error: TSX file {asset['path']} is missing required attributes (tilewidth, tileheight, columns, tilecount)")
|
||||
sys.exit(1)
|
||||
|
||||
tileWidth = int(root.attrib['tilewidth'])
|
||||
tileHeight = int(root.attrib['tileheight'])
|
||||
columns = int(root.attrib['columns'])
|
||||
tileCount = int(root.attrib['tilecount'])
|
||||
rows = (tileCount + columns - 1) // columns # Calculate rows based on tileCount and columns
|
||||
|
||||
# Find the image element
|
||||
imageElement = root.find('image')
|
||||
if imageElement is None or 'source' not in imageElement.attrib:
|
||||
print(f"Error: TSX file {asset['path']} is missing an image element with a source attribute")
|
||||
sys.exit(1)
|
||||
|
||||
imagePath = imageElement.attrib['source']
|
||||
|
||||
# Image is relative to the TSX file
|
||||
imageAssetPath = os.path.join(os.path.dirname(asset['path']), imagePath)
|
||||
|
||||
image = processImage({
|
||||
'path': imageAssetPath,
|
||||
'options': asset['options'],
|
||||
})
|
||||
|
||||
return {
|
||||
"image": image,
|
||||
"tileWidth": tileWidth,
|
||||
"tileHeight": tileHeight,
|
||||
"columns": columns,
|
||||
"rows": rows,
|
||||
"originalWidth": tileWidth * columns,
|
||||
"originalHeight": tileHeight * rows,
|
||||
}
|
||||
|
||||
def loadTilesetFromArgs(asset):
|
||||
# We need to determine how big each tile is. This can either be provided as
|
||||
# an arg of tileWidth/tileHeight or as a count of rows/columns.
|
||||
# Additionally, if the image has been factored, then the user can provide both
|
||||
# tile sizes AND cols/rows to indicate the original size of the image.
|
||||
image = processImage(asset)
|
||||
|
||||
tileWidth, tileHeight = None, None
|
||||
columns, rows = None, None
|
||||
originalWidth, originalHeight = image['width'], image['height']
|
||||
|
||||
if 'tileWidth' in asset['options'] and 'columns' in asset['options']:
|
||||
tileWidth = int(asset['options']['tileWidth'])
|
||||
columns = int(asset['options']['columns'])
|
||||
originalWidth = tileWidth * columns
|
||||
elif 'tileWidth' in asset['options']:
|
||||
tileWidth = int(asset['options']['tileWidth'])
|
||||
columns = image['width'] // tileWidth
|
||||
elif 'columns' in asset['options']:
|
||||
columns = int(asset['options']['columns'])
|
||||
tileWidth = image['width'] // columns
|
||||
else:
|
||||
print(f"Error: Tileset {asset['path']} must specify either tileWidth or columns")
|
||||
sys.exit(1)
|
||||
|
||||
if 'tileHeight' in asset['options'] and 'rows' in asset['options']:
|
||||
tileHeight = int(asset['options']['tileHeight'])
|
||||
rows = int(asset['options']['rows'])
|
||||
originalHeight = tileHeight * rows
|
||||
elif 'tileHeight' in asset['options']:
|
||||
tileHeight = int(asset['options']['tileHeight'])
|
||||
rows = image['height'] // tileHeight
|
||||
elif 'rows' in asset['options']:
|
||||
rows = int(asset['options']['rows'])
|
||||
tileHeight = image['height'] // rows
|
||||
else:
|
||||
print(f"Error: Tileset {asset['path']} must specify either tileHeight or rows")
|
||||
sys.exit(1)
|
||||
|
||||
return {
|
||||
"image": image,
|
||||
"tileWidth": tileWidth,
|
||||
"tileHeight": tileHeight,
|
||||
"columns": columns,
|
||||
"rows": rows,
|
||||
"originalWidth": originalWidth,
|
||||
"originalHeight": originalHeight,
|
||||
}
|
||||
|
||||
def processTileset(asset):
|
||||
cache = assetGetCache(asset['path'])
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
print(f"Processing tileset: {asset['path']}")
|
||||
tilesetData = None
|
||||
if asset['path'].endswith('.tsx'):
|
||||
tilesetData = loadTilesetFromTSX(asset)
|
||||
else:
|
||||
tilesetData = loadTilesetFromArgs(asset)
|
||||
|
||||
fileNameWithoutExtension = os.path.splitext(os.path.basename(asset['path']))[0]
|
||||
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
tilesetName = fileNameWithoutExtension
|
||||
tilesetNameUpper = tilesetName.upper()
|
||||
|
||||
widthScale = tilesetData['originalWidth'] / tilesetData['image']['width']
|
||||
heightScale = tilesetData['originalHeight'] / tilesetData['image']['height']
|
||||
|
||||
# Create header
|
||||
data = f"// Tileset Generated for {asset['path']} at {now}\n"
|
||||
data += f"#pragma once\n"
|
||||
data += f"#include \"display/tileset/tileset.h\"\n\n"
|
||||
data += f"static const tileset_t TILESET_{tilesetNameUpper} = {{\n"
|
||||
data += f" .name = {json.dumps(tilesetName)},\n"
|
||||
data += f" .tileWidth = {tilesetData['tileWidth']},\n"
|
||||
data += f" .tileHeight = {tilesetData['tileHeight']},\n"
|
||||
data += f" .tileCount = {tilesetData['columns'] * tilesetData['rows']},\n"
|
||||
data += f" .columns = {tilesetData['columns']},\n"
|
||||
data += f" .rows = {tilesetData['rows']},\n"
|
||||
data += f" .uv = {{ {widthScale / tilesetData['columns']}f, {heightScale / tilesetData['rows']}f }},\n"
|
||||
data += f" .image = {json.dumps(tilesetData['image']['imagePath'])},\n"
|
||||
data += f"}};\n"
|
||||
|
||||
|
||||
# Write Header
|
||||
outputFile = os.path.join(args.headers_dir, "display", "tileset", f"tileset_{tilesetName}.h")
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, 'w') as f:
|
||||
f.write(data)
|
||||
|
||||
print(f"Write header for tileset: {outputFile}")
|
||||
|
||||
tileset = {
|
||||
"files": [],
|
||||
"image": tilesetData['image'],
|
||||
"headerFile": os.path.relpath(outputFile, args.headers_dir),
|
||||
"tilesetName": tilesetName,
|
||||
"tilesetNameUpper": tilesetNameUpper,
|
||||
"tilesetIndex": len(tilesets),
|
||||
"tilesetData": tilesetData,
|
||||
"files": tilesetData['image']['files'],
|
||||
}
|
||||
|
||||
tilesets.append(tileset)
|
||||
return assetCache(asset['path'], tileset)
|
||||
|
||||
def processTilesetList():
|
||||
data = f"// Tileset List Generated at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
|
||||
data += f"#pragma once\n"
|
||||
for tileset in tilesets:
|
||||
data += f"#include \"{tileset['headerFile']}\"\n"
|
||||
data += f"\n"
|
||||
data += f"#define TILESET_LIST_COUNT {len(tilesets)}\n\n"
|
||||
data += f"static const tileset_t* TILESET_LIST[TILESET_LIST_COUNT] = {{\n"
|
||||
for tileset in tilesets:
|
||||
data += f" &TILESET_{tileset['tilesetNameUpper']},\n"
|
||||
data += f"}};\n"
|
||||
|
||||
# Write header.
|
||||
outputFile = os.path.join(args.headers_dir, "display", "tileset", f"tilesetlist.h")
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, 'w') as f:
|
||||
f.write(data)
|
||||
@@ -1,7 +1,6 @@
|
||||
import argparse
|
||||
import os
|
||||
import csv
|
||||
from tools.util.type import detectType, stringToCType, typeToCType
|
||||
|
||||
parser = argparse.ArgumentParser(description="Color CSV to .h defines")
|
||||
parser.add_argument("--csv", required=True, help="Path to color CSV file")
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
import json
|
||||
import os
|
||||
from tools.dusk.event import Event
|
||||
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, CHUNK_VERTEX_COUNT_MAX, TILE_SHAPE_NULL
|
||||
from tools.dusk.tile import Tile
|
||||
from tools.dusk.entity import Entity
|
||||
from tools.dusk.region import Region
|
||||
from tools.editor.map.vertexbuffer import VertexBuffer
|
||||
from OpenGL.GL import *
|
||||
|
||||
class Chunk:
|
||||
def __init__(self, map, x, y, z):
|
||||
self.map = map
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.current = {}
|
||||
self.original = {}
|
||||
self.entities = {}
|
||||
self.regions = {}
|
||||
self.onChunkData = Event()
|
||||
self.dirty = False
|
||||
|
||||
self.tiles = {}
|
||||
self.vertexBuffer = VertexBuffer()
|
||||
|
||||
# Test Region
|
||||
region = self.regions[0] = Region(self)
|
||||
region.minX = 0
|
||||
region.minY = 0
|
||||
region.minZ = 0
|
||||
region.maxX = 32
|
||||
region.maxY = 32
|
||||
region.maxZ = 32
|
||||
region.updateVertexs()
|
||||
|
||||
# Gen tiles.
|
||||
tileIndex = 0
|
||||
for tz in range(CHUNK_DEPTH):
|
||||
for ty in range(CHUNK_HEIGHT):
|
||||
for tx in range(CHUNK_WIDTH):
|
||||
self.tiles[tileIndex] = Tile(self, tx, ty, tz, tileIndex)
|
||||
tileIndex += 1
|
||||
|
||||
# Update vertices
|
||||
self.tileUpdateVertices()
|
||||
|
||||
def reload(self, newX, newY, newZ):
|
||||
self.x = newX
|
||||
self.y = newY
|
||||
self.z = newZ
|
||||
self.entities = {}
|
||||
for tile in self.tiles.values():
|
||||
tile.chunkReload(newX, newY, newZ)
|
||||
self.load()
|
||||
|
||||
def tileUpdateVertices(self):
|
||||
self.vertexBuffer.clear()
|
||||
for tile in self.tiles.values():
|
||||
tile.buffer(self.vertexBuffer)
|
||||
self.vertexBuffer.buildData()
|
||||
|
||||
def load(self):
|
||||
fname = self.getFilename()
|
||||
if not fname or not os.path.exists(fname):
|
||||
self.new()
|
||||
return
|
||||
try:
|
||||
with open(fname, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
if not 'shapes' in data:
|
||||
data['shapes'] = []
|
||||
|
||||
# For each tile.
|
||||
for tile in self.tiles.values():
|
||||
tile.load(data)
|
||||
|
||||
# For each entity.
|
||||
self.entities = {}
|
||||
if 'entities' in data:
|
||||
for id, entData in enumerate(data['entities']):
|
||||
ent = Entity(self)
|
||||
ent.load(entData)
|
||||
self.entities[id] = ent
|
||||
|
||||
self.tileUpdateVertices()
|
||||
self.dirty = False
|
||||
self.onChunkData.invoke(self)
|
||||
self.map.onEntityData.invoke()
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to load chunk file: {e}")
|
||||
|
||||
def save(self):
|
||||
if not self.isDirty():
|
||||
return
|
||||
|
||||
dataOut = {
|
||||
'shapes': [],
|
||||
'entities': []
|
||||
}
|
||||
|
||||
for tile in self.tiles.values():
|
||||
dataOut['shapes'].append(tile.shape)
|
||||
|
||||
for ent in self.entities.values():
|
||||
entData = {}
|
||||
ent.save(entData)
|
||||
dataOut['entities'].append(entData)
|
||||
|
||||
fname = self.getFilename()
|
||||
if not fname:
|
||||
raise ValueError("No filename specified for saving chunk.")
|
||||
try:
|
||||
with open(fname, 'w') as f:
|
||||
json.dump(dataOut, f)
|
||||
self.dirty = False
|
||||
self.onChunkData.invoke(self)
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to save chunk file: {e}")
|
||||
|
||||
def new(self):
|
||||
for tile in self.tiles.values():
|
||||
tile.shape = TILE_SHAPE_NULL
|
||||
|
||||
self.tileUpdateVertices()
|
||||
self.dirty = False
|
||||
self.onChunkData.invoke(self)
|
||||
|
||||
def isDirty(self):
|
||||
return self.dirty
|
||||
|
||||
def getFilename(self):
|
||||
if not self.map or not hasattr(self.map, 'getChunkDirectory'):
|
||||
return None
|
||||
dirPath = self.map.getChunkDirectory()
|
||||
if dirPath is None:
|
||||
return None
|
||||
return f"{dirPath}/{self.x}_{self.y}_{self.z}.json"
|
||||
|
||||
def draw(self):
|
||||
self.vertexBuffer.draw()
|
||||
|
||||
def addEntity(self, localX=0, localY=0, localZ=0):
|
||||
ent = Entity(self, localX, localY, localZ)
|
||||
self.entities[len(self.entities)] = ent
|
||||
self.map.onEntityData.invoke()
|
||||
self.dirty = True
|
||||
return ent
|
||||
|
||||
def removeEntity(self, entity):
|
||||
for key, val in list(self.entities.items()):
|
||||
if val == entity:
|
||||
del self.entities[key]
|
||||
self.map.onEntityData.invoke()
|
||||
self.dirty = True
|
||||
return True
|
||||
return False
|
||||
@@ -1,49 +0,0 @@
|
||||
from dotenv import load_dotenv, dotenv_values
|
||||
import os
|
||||
import sys
|
||||
|
||||
current_file_path = os.path.abspath(__file__)
|
||||
duskDefsPath = os.path.join(os.path.dirname(current_file_path), "..", "..", "src", "duskdefs.env")
|
||||
|
||||
# Ensure the .env file exists
|
||||
if not os.path.isfile(duskDefsPath):
|
||||
print(f"Error: .env file not found at {duskDefsPath}")
|
||||
sys.exit(1)
|
||||
|
||||
load_dotenv(dotenv_path=duskDefsPath)
|
||||
defs = {key: os.getenv(key) for key in os.environ.keys()}
|
||||
|
||||
fileDefs = dotenv_values(dotenv_path=duskDefsPath)
|
||||
|
||||
# Parsed out definitions
|
||||
CHUNK_WIDTH = int(defs.get('CHUNK_WIDTH'))
|
||||
CHUNK_HEIGHT = int(defs.get('CHUNK_HEIGHT'))
|
||||
CHUNK_DEPTH = int(defs.get('CHUNK_DEPTH'))
|
||||
CHUNK_TILE_COUNT = CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH
|
||||
CHUNK_VERTEX_COUNT_MAX = int(defs.get('CHUNK_VERTEX_COUNT_MAX'))
|
||||
|
||||
TILE_WIDTH = float(defs.get('TILE_WIDTH'))
|
||||
TILE_HEIGHT = float(defs.get('TILE_HEIGHT'))
|
||||
TILE_DEPTH = float(defs.get('TILE_DEPTH'))
|
||||
|
||||
RPG_CAMERA_PIXELS_PER_UNIT = float(defs.get('RPG_CAMERA_PIXELS_PER_UNIT'))
|
||||
RPG_CAMERA_Z_OFFSET = float(defs.get('RPG_CAMERA_Z_OFFSET'))
|
||||
RPG_CAMERA_FOV = float(defs.get('RPG_CAMERA_FOV'))
|
||||
|
||||
MAP_WIDTH = 5
|
||||
MAP_HEIGHT = 5
|
||||
MAP_DEPTH = 3
|
||||
MAP_CHUNK_COUNT = MAP_WIDTH * MAP_HEIGHT * MAP_DEPTH
|
||||
|
||||
TILE_SHAPES = {}
|
||||
for key in defs.keys():
|
||||
if key.startswith('TILE_SHAPE_'):
|
||||
globals()[key] = int(defs.get(key))
|
||||
TILE_SHAPES[key] = int(defs.get(key))
|
||||
|
||||
ENTITY_TYPES = {}
|
||||
for key in defs.keys():
|
||||
if key.startswith('ENTITY_TYPE_'):
|
||||
globals()[key] = int(defs.get(key))
|
||||
if key != 'ENTITY_TYPE_COUNT':
|
||||
ENTITY_TYPES[key] = int(defs.get(key))
|
||||
@@ -1,90 +0,0 @@
|
||||
from tools.dusk.defs import ENTITY_TYPE_NULL, ENTITY_TYPE_NPC, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
||||
from tools.editor.map.vertexbuffer import VertexBuffer
|
||||
|
||||
class Entity:
|
||||
def __init__(self, chunk, localX=0, localY=0, localZ=0):
|
||||
self.type = ENTITY_TYPE_NPC
|
||||
self.name = "Unititled"
|
||||
self.localX = localX % CHUNK_WIDTH
|
||||
self.localY = localY % CHUNK_HEIGHT
|
||||
self.localZ = localZ % CHUNK_DEPTH
|
||||
|
||||
self.chunk = chunk
|
||||
self.vertexBuffer = VertexBuffer()
|
||||
pass
|
||||
|
||||
def load(self, obj):
|
||||
self.type = obj.get('type', ENTITY_TYPE_NULL)
|
||||
self.localX = obj.get('x', 0)
|
||||
self.localY = obj.get('y', 0)
|
||||
self.localZ = obj.get('z', 0)
|
||||
self.name = obj.get('name', "Untitled")
|
||||
pass
|
||||
|
||||
def save(self, obj):
|
||||
obj['type'] = self.type
|
||||
obj['name'] = self.name
|
||||
obj['x'] = self.localX
|
||||
obj['y'] = self.localY
|
||||
obj['z'] = self.localZ
|
||||
pass
|
||||
|
||||
def setType(self, entityType):
|
||||
if self.type == entityType:
|
||||
return
|
||||
self.type = entityType
|
||||
self.chunk.dirty = True
|
||||
self.chunk.map.onEntityData.invoke()
|
||||
|
||||
def setName(self, name):
|
||||
if self.name == name:
|
||||
return
|
||||
self.name = name
|
||||
self.chunk.dirty = True
|
||||
self.chunk.map.onEntityData.invoke()
|
||||
|
||||
def draw(self):
|
||||
self.vertexBuffer.clear()
|
||||
|
||||
startX = (self.chunk.x * CHUNK_WIDTH + self.localX) * TILE_WIDTH
|
||||
startY = (self.chunk.y * CHUNK_HEIGHT + self.localY) * TILE_HEIGHT
|
||||
startZ = (self.chunk.z * CHUNK_DEPTH + self.localZ) * TILE_DEPTH
|
||||
w = TILE_WIDTH
|
||||
h = TILE_HEIGHT
|
||||
d = TILE_DEPTH
|
||||
|
||||
# Center
|
||||
startX -= w / 2
|
||||
startY -= h / 2
|
||||
startZ -= d / 2
|
||||
|
||||
# Offset upwards a little
|
||||
startZ += 1
|
||||
|
||||
# Buffer simple quad at current position (need 6 positions)
|
||||
self.vertexBuffer.vertices = [
|
||||
startX, startY, startZ,
|
||||
startX + w, startY, startZ,
|
||||
startX + w, startY + h, startZ,
|
||||
startX, startY, startZ,
|
||||
startX + w, startY + h, startZ,
|
||||
startX, startY + h, startZ,
|
||||
]
|
||||
self.vertexBuffer.colors = [
|
||||
1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 0.0, 1.0, 1.0,
|
||||
1.0, 0.0, 1.0, 1.0,
|
||||
]
|
||||
self.vertexBuffer.uvs = [
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
]
|
||||
self.vertexBuffer.buildData()
|
||||
self.vertexBuffer.draw()
|
||||
@@ -1,18 +0,0 @@
|
||||
class Event:
|
||||
def __init__(self):
|
||||
self._subscribers = []
|
||||
|
||||
def sub(self, callback):
|
||||
"""Subscribe a callback to the event."""
|
||||
if callback not in self._subscribers:
|
||||
self._subscribers.append(callback)
|
||||
|
||||
def unsub(self, callback):
|
||||
"""Unsubscribe a callback from the event."""
|
||||
if callback in self._subscribers:
|
||||
self._subscribers.remove(callback)
|
||||
|
||||
def invoke(self, *args, **kwargs):
|
||||
"""Invoke all subscribers with the given arguments."""
|
||||
for callback in self._subscribers:
|
||||
callback(*args, **kwargs)
|
||||
@@ -1,259 +0,0 @@
|
||||
import json
|
||||
import sys
|
||||
from tools.dusk.event import Event
|
||||
from PyQt5.QtWidgets import QFileDialog, QMessageBox
|
||||
from PyQt5.QtCore import QTimer
|
||||
import os
|
||||
from tools.dusk.chunk import Chunk
|
||||
from tools.dusk.defs import MAP_WIDTH, MAP_HEIGHT, MAP_DEPTH, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH
|
||||
import traceback
|
||||
|
||||
MAP_DEFAULT_PATH = os.path.join(os.path.dirname(__file__), '../../assets/map/')
|
||||
EDITOR_CONFIG_PATH = os.path.join(os.path.dirname(__file__), '.editor')
|
||||
|
||||
class Map:
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.data = {}
|
||||
self.dataOriginal = {}
|
||||
self.position = [None, None, None] # x, y, z
|
||||
self.topLeftX = None
|
||||
self.topLeftY = None
|
||||
self.topLeftZ = None
|
||||
self.chunks = {}
|
||||
self.onMapData = Event()
|
||||
self.onPositionChange = Event()
|
||||
self.onEntityData = Event()
|
||||
self.mapFileName = None
|
||||
self.lastFile = None
|
||||
self.firstLoad = True
|
||||
|
||||
index = 0
|
||||
for x in range(MAP_WIDTH):
|
||||
for y in range(MAP_HEIGHT):
|
||||
for z in range(MAP_DEPTH):
|
||||
self.chunks[index] = Chunk(self, x, y, z)
|
||||
index += 1
|
||||
|
||||
# Only in editor instances:
|
||||
self.moveTo(0, 0, 0)
|
||||
if parent is not None:
|
||||
QTimer.singleShot(16, self.loadLastFile)
|
||||
|
||||
def loadLastFile(self):
|
||||
if not os.path.exists(EDITOR_CONFIG_PATH):
|
||||
return
|
||||
try:
|
||||
with open(EDITOR_CONFIG_PATH, 'r') as f:
|
||||
config = json.load(f)
|
||||
lastFile = config.get('lastFile')
|
||||
lastPosition = config.get('lastPosition')
|
||||
leftPanelIndex = config.get('leftPanelIndex')
|
||||
if lastFile and os.path.exists(lastFile):
|
||||
self.load(lastFile)
|
||||
if lastPosition and isinstance(lastPosition, list) and len(lastPosition) == 3:
|
||||
self.moveTo(*lastPosition)
|
||||
if leftPanelIndex is not None:
|
||||
self.parent.leftPanel.tabs.setCurrentIndex(leftPanelIndex)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
def updateEditorConfig(self):
|
||||
if self.parent is None:
|
||||
return
|
||||
try:
|
||||
mapFileName = self.getMapFilename()
|
||||
config = {
|
||||
'lastFile': mapFileName if mapFileName else "",
|
||||
'lastPosition': self.position,
|
||||
'leftPanelIndex': self.parent.leftPanel.tabs.currentIndex()
|
||||
}
|
||||
config_dir = os.path.dirname(EDITOR_CONFIG_PATH)
|
||||
if not os.path.exists(config_dir):
|
||||
os.makedirs(config_dir, exist_ok=True)
|
||||
with open(EDITOR_CONFIG_PATH, 'w') as f:
|
||||
json.dump(config, f, indent=2)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
def newFile(self):
|
||||
self.data = {}
|
||||
self.dataOriginal = {}
|
||||
self.mapFileName = None
|
||||
self.lastFile = None
|
||||
for chunk in self.chunks.values():
|
||||
chunk.new()
|
||||
self.moveTo(0, 0, 0)
|
||||
self.onMapData.invoke(self.data)
|
||||
self.updateEditorConfig()
|
||||
|
||||
def save(self, fname=None):
|
||||
if not self.getMapFilename() and fname is None:
|
||||
filePath, _ = QFileDialog.getSaveFileName(None, "Save Map File", MAP_DEFAULT_PATH, "Map Files (*.json)")
|
||||
if not filePath:
|
||||
return
|
||||
self.mapFileName = filePath
|
||||
if fname:
|
||||
self.mapFileName = fname
|
||||
try:
|
||||
with open(self.getMapFilename(), 'w') as f:
|
||||
json.dump(self.data, f, indent=2)
|
||||
self.dataOriginal = json.loads(json.dumps(self.data)) # Deep copy
|
||||
for chunk in self.chunks.values():
|
||||
chunk.save()
|
||||
self.updateEditorConfig()
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
QMessageBox.critical(None, "Save Error", f"Failed to save map file:\n{e}")
|
||||
|
||||
def load(self, fileName):
|
||||
try:
|
||||
with open(fileName, 'r') as f:
|
||||
self.data = json.load(f)
|
||||
self.mapFileName = fileName
|
||||
self.dataOriginal = json.loads(json.dumps(self.data)) # Deep copy
|
||||
for chunk in self.chunks.values():
|
||||
chunk.load()
|
||||
self.onMapData.invoke(self.data)
|
||||
self.updateEditorConfig()
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
QMessageBox.critical(None, "Load Error", f"Failed to load map file:\n{e}")
|
||||
|
||||
def isMapFileDirty(self):
|
||||
return json.dumps(self.data, sort_keys=True) != json.dumps(self.dataOriginal, sort_keys=True)
|
||||
|
||||
def isDirty(self):
|
||||
return self.isMapFileDirty() or self.anyChunksDirty()
|
||||
|
||||
def getMapFilename(self):
|
||||
return self.mapFileName if self.mapFileName and os.path.exists(self.mapFileName) else None
|
||||
|
||||
def getMapDirectory(self):
|
||||
if self.mapFileName is None:
|
||||
return None
|
||||
dirname = os.path.dirname(self.mapFileName)
|
||||
return dirname
|
||||
|
||||
def getChunkDirectory(self):
|
||||
dirName = self.getMapDirectory()
|
||||
if dirName is None:
|
||||
return None
|
||||
return os.path.join(dirName, 'chunks')
|
||||
|
||||
def anyChunksDirty(self):
|
||||
for chunk in self.chunks.values():
|
||||
if chunk.isDirty():
|
||||
return True
|
||||
return False
|
||||
|
||||
def moveTo(self, x, y, z):
|
||||
if self.position == [x, y, z]:
|
||||
return
|
||||
|
||||
# We need to decide if the chunks should be unloaded here or not.
|
||||
newTopLeftChunkX = x // CHUNK_WIDTH - (MAP_WIDTH // 2)
|
||||
newTopLeftChunkY = y // CHUNK_HEIGHT - (MAP_HEIGHT // 2)
|
||||
newTopLeftChunkZ = z // CHUNK_DEPTH - (MAP_DEPTH // 2)
|
||||
|
||||
if (newTopLeftChunkX != self.topLeftX or
|
||||
newTopLeftChunkY != self.topLeftY or
|
||||
newTopLeftChunkZ != self.topLeftZ):
|
||||
|
||||
chunksToUnload = []
|
||||
chunksToKeep = []
|
||||
for chunk in self.chunks.values():
|
||||
chunkWorldX = chunk.x
|
||||
chunkWorldY = chunk.y
|
||||
chunkWorldZ = chunk.z
|
||||
if (chunkWorldX < newTopLeftChunkX or
|
||||
chunkWorldX >= newTopLeftChunkX + MAP_WIDTH or
|
||||
chunkWorldY < newTopLeftChunkY or
|
||||
chunkWorldY >= newTopLeftChunkY + MAP_HEIGHT or
|
||||
chunkWorldZ < newTopLeftChunkZ or
|
||||
chunkWorldZ >= newTopLeftChunkZ + MAP_DEPTH):
|
||||
chunksToUnload.append(chunk)
|
||||
else:
|
||||
chunksToKeep.append(chunk)
|
||||
|
||||
# Unload chunks that are out of the new bounds.
|
||||
for chunk in chunksToUnload:
|
||||
if chunk.isDirty():
|
||||
print(f"Can't move map, some chunks are dirty: ({chunk.x}, {chunk.y}, {chunk.z})")
|
||||
return
|
||||
|
||||
# Now we can safely unload the chunks.
|
||||
chunkIndex = 0
|
||||
newChunks = {}
|
||||
for chunk in chunksToKeep:
|
||||
newChunks[chunkIndex] = chunk
|
||||
chunkIndex += 1
|
||||
|
||||
for xPos in range(newTopLeftChunkX, newTopLeftChunkX + MAP_WIDTH):
|
||||
for yPos in range(newTopLeftChunkY, newTopLeftChunkY + MAP_HEIGHT):
|
||||
for zPos in range(newTopLeftChunkZ, newTopLeftChunkZ + MAP_DEPTH):
|
||||
# Check if we already have this chunk.
|
||||
found = False
|
||||
for chunk in chunksToKeep:
|
||||
if chunk.x == xPos and chunk.y == yPos and chunk.z == zPos:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
# Create a new chunk.
|
||||
newChunk = chunksToUnload.pop()
|
||||
newChunk.reload(xPos, yPos, zPos)
|
||||
newChunks[chunkIndex] = newChunk
|
||||
chunkIndex += 1
|
||||
|
||||
self.chunks = newChunks
|
||||
self.topLeftX = newTopLeftChunkX
|
||||
self.topLeftY = newTopLeftChunkY
|
||||
self.topLeftZ = newTopLeftChunkZ
|
||||
|
||||
self.position = [x, y, z]
|
||||
self.onPositionChange.invoke(self.position)
|
||||
if not self.firstLoad:
|
||||
self.updateEditorConfig()
|
||||
self.firstLoad = False
|
||||
|
||||
def moveRelative(self, x, y, z):
|
||||
self.moveTo(
|
||||
self.position[0] + x,
|
||||
self.position[1] + y,
|
||||
self.position[2] + z
|
||||
)
|
||||
|
||||
def draw(self):
|
||||
for chunk in self.chunks.values():
|
||||
chunk.draw()
|
||||
|
||||
for chunk in self.chunks.values():
|
||||
for entity in chunk.entities.values():
|
||||
entity.draw()
|
||||
|
||||
# Only render on Region tab
|
||||
if self.parent.leftPanel.tabs.currentWidget() == self.parent.leftPanel.regionPanel:
|
||||
for chunk in self.chunks.values():
|
||||
for region in chunk.regions.values():
|
||||
region.draw()
|
||||
|
||||
def getChunkAtWorldPos(self, x, y, z):
|
||||
chunkX = x // CHUNK_WIDTH
|
||||
chunkY = y // CHUNK_HEIGHT
|
||||
chunkZ = z // CHUNK_DEPTH
|
||||
for chunk in self.chunks.values():
|
||||
if chunk.x == chunkX and chunk.y == chunkY and chunk.z == chunkZ:
|
||||
return chunk
|
||||
return None
|
||||
|
||||
def getTileAtWorldPos(self, x, y, z):
|
||||
chunk = self.getChunkAtWorldPos(x, y, z)
|
||||
if not chunk:
|
||||
print("No chunk found at position:", (x, y, z))
|
||||
return None
|
||||
|
||||
tileX = x % CHUNK_WIDTH
|
||||
tileY = y % CHUNK_HEIGHT
|
||||
tileZ = z % CHUNK_DEPTH
|
||||
tileIndex = tileX + tileY * CHUNK_WIDTH + tileZ * CHUNK_WIDTH * CHUNK_HEIGHT
|
||||
return chunk.tiles.get(tileIndex)
|
||||
@@ -1,141 +0,0 @@
|
||||
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
||||
from tools.editor.map.vertexbuffer import VertexBuffer
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
|
||||
class Region:
|
||||
def __init__(self, chunk):
|
||||
self.minX = 0
|
||||
self.minY = 0
|
||||
self.minZ = 0
|
||||
self.maxX = 0
|
||||
self.maxY = 0
|
||||
self.maxZ = 0
|
||||
self.chunk = chunk
|
||||
self.vertexBuffer = VertexBuffer()
|
||||
self.color = (1.0, 0.0, 0.0)
|
||||
self.updateVertexs()
|
||||
pass
|
||||
|
||||
def updateVertexs(self):
|
||||
# Draw a quad, semi transparent with solid outlines
|
||||
vminX = (self.minX * CHUNK_WIDTH) * TILE_WIDTH
|
||||
vminY = (self.minY * CHUNK_HEIGHT) * TILE_HEIGHT
|
||||
vminZ = (self.minZ * CHUNK_DEPTH) * TILE_DEPTH
|
||||
vmaxX = (self.maxX * CHUNK_WIDTH) * TILE_WIDTH
|
||||
vmaxY = (self.maxY * CHUNK_HEIGHT) * TILE_HEIGHT
|
||||
vmaxZ = (self.maxZ * CHUNK_DEPTH) * TILE_DEPTH
|
||||
alpha = 0.25
|
||||
|
||||
# Move back half a tile width
|
||||
vminX -= TILE_WIDTH / 2
|
||||
vmaxX -= TILE_WIDTH / 2
|
||||
vminY -= TILE_HEIGHT / 2
|
||||
vmaxY -= TILE_HEIGHT / 2
|
||||
vminZ -= TILE_DEPTH / 2
|
||||
vmaxZ -= TILE_DEPTH / 2
|
||||
|
||||
# Cube (6 verts per face)
|
||||
self.vertexBuffer.vertices = [
|
||||
# Front face
|
||||
vminX, vminY, vmaxZ,
|
||||
vmaxX, vminY, vmaxZ,
|
||||
vmaxX, vmaxY, vmaxZ,
|
||||
vminX, vminY, vmaxZ,
|
||||
vmaxX, vmaxY, vmaxZ,
|
||||
vminX, vmaxY, vmaxZ,
|
||||
|
||||
# Back face
|
||||
vmaxX, vminY, vminZ,
|
||||
vminX, vminY, vminZ,
|
||||
vminX, vmaxY, vminZ,
|
||||
vmaxX, vminY, vminZ,
|
||||
vminX, vmaxY, vminZ,
|
||||
vmaxX, vmaxY, vminZ,
|
||||
|
||||
# Left face
|
||||
vminX, vminY, vminZ,
|
||||
vminX, vminY, vmaxZ,
|
||||
vminX, vmaxY, vmaxZ,
|
||||
vminX, vminY, vminZ,
|
||||
vminX, vmaxY, vmaxZ,
|
||||
vminX, vmaxY, vminZ,
|
||||
|
||||
# Right face
|
||||
vmaxX, vminY, vmaxZ,
|
||||
vmaxX, vminY, vminZ,
|
||||
vmaxX, vmaxY, vminZ,
|
||||
vmaxX, vminY, vmaxZ,
|
||||
vmaxX, vmaxY, vminZ,
|
||||
vmaxX, vmaxY, vmaxZ,
|
||||
|
||||
# Top face
|
||||
vminX, vmaxY, vmaxZ,
|
||||
vmaxX, vmaxY, vmaxZ,
|
||||
vmaxX, vmaxY, vminZ,
|
||||
vminX, vmaxY, vmaxZ,
|
||||
vmaxX, vmaxY, vminZ,
|
||||
vminX, vmaxY, vminZ,
|
||||
|
||||
# Bottom face
|
||||
vminX, vminY, vminZ,
|
||||
vmaxX, vminY, vminZ,
|
||||
vmaxX, vminY, vmaxZ,
|
||||
vminX, vminY, vminZ,
|
||||
vmaxX, vminY, vmaxZ,
|
||||
vminX, vminY, vmaxZ,
|
||||
]
|
||||
|
||||
self.vertexBuffer.colors = [
|
||||
# Front face
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
|
||||
# Back face
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
|
||||
# Left face
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
|
||||
# Right face
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
|
||||
# Top face
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
|
||||
# Bottom face
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
self.color[0], self.color[1], self.color[2], alpha,
|
||||
]
|
||||
self.vertexBuffer.buildData()
|
||||
|
||||
def draw(self):
|
||||
self.vertexBuffer.draw()
|
||||
@@ -1,206 +0,0 @@
|
||||
from OpenGL.GL import *
|
||||
from tools.dusk.defs import (
|
||||
TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH,
|
||||
CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH,
|
||||
TILE_SHAPE_NULL, TILE_SHAPE_FLOOR,
|
||||
TILE_SHAPE_RAMP_NORTH, TILE_SHAPE_RAMP_SOUTH,
|
||||
TILE_SHAPE_RAMP_EAST, TILE_SHAPE_RAMP_WEST,
|
||||
TILE_SHAPE_RAMP_SOUTHWEST, TILE_SHAPE_RAMP_SOUTHEAST,
|
||||
TILE_SHAPE_RAMP_NORTHWEST, TILE_SHAPE_RAMP_NORTHEAST
|
||||
)
|
||||
|
||||
def getItem(arr, index, default):
|
||||
if index < len(arr):
|
||||
return arr[index]
|
||||
return default
|
||||
|
||||
class Tile:
|
||||
def __init__(self, chunk, x, y, z, tileIndex):
|
||||
self.shape = TILE_SHAPE_NULL
|
||||
|
||||
self.chunk = chunk
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.index = tileIndex
|
||||
|
||||
self.posX = x * TILE_WIDTH + chunk.x * CHUNK_WIDTH * TILE_WIDTH
|
||||
self.posY = y * TILE_HEIGHT + chunk.y * CHUNK_HEIGHT * TILE_HEIGHT
|
||||
self.posZ = z * TILE_DEPTH + chunk.z * CHUNK_DEPTH * TILE_DEPTH
|
||||
|
||||
def chunkReload(self, newX, newY, newZ):
|
||||
self.posX = self.x * TILE_WIDTH + newX * CHUNK_WIDTH * TILE_WIDTH
|
||||
self.posY = self.y * TILE_HEIGHT + newY * CHUNK_HEIGHT * TILE_HEIGHT
|
||||
self.posZ = self.z * TILE_DEPTH + newZ * CHUNK_DEPTH * TILE_DEPTH
|
||||
|
||||
def load(self, chunkData):
|
||||
self.shape = getItem(chunkData['shapes'], self.index, TILE_SHAPE_NULL)
|
||||
|
||||
def setShape(self, shape):
|
||||
if shape == self.shape:
|
||||
return
|
||||
|
||||
self.shape = shape
|
||||
self.chunk.dirty = True
|
||||
self.chunk.tileUpdateVertices()
|
||||
self.chunk.onChunkData.invoke(self.chunk)
|
||||
|
||||
def getBaseTileModel(self):
|
||||
vertices = []
|
||||
indices = []
|
||||
uvs = []
|
||||
colors = []
|
||||
|
||||
if self.shape == TILE_SHAPE_NULL:
|
||||
pass
|
||||
|
||||
elif self.shape == TILE_SHAPE_FLOOR:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (255, 255, 255, 255) ] * 4
|
||||
|
||||
elif self.shape == TILE_SHAPE_RAMP_NORTH:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (255, 0, 0, 255) ] * 4
|
||||
|
||||
elif self.shape == TILE_SHAPE_RAMP_SOUTH:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (0, 255, 0, 255) ] * 4
|
||||
|
||||
elif self.shape == TILE_SHAPE_RAMP_EAST:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (0, 0, 255, 255) ] * 4
|
||||
|
||||
elif self.shape == TILE_SHAPE_RAMP_WEST:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (255, 255, 0, 255) ] * 4
|
||||
|
||||
elif self.shape == TILE_SHAPE_RAMP_SOUTHWEST:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (255, 128, 0, 255) ] * 4
|
||||
|
||||
elif self.shape == TILE_SHAPE_RAMP_NORTHWEST:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (128, 255, 0, 255) ] * 4
|
||||
|
||||
elif self.shape == TILE_SHAPE_RAMP_NORTHEAST:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (0, 255, 128, 255) ] * 4
|
||||
|
||||
elif self.shape == TILE_SHAPE_RAMP_SOUTHEAST:
|
||||
vertices = [
|
||||
(self.posX, self.posY, self.posZ),
|
||||
(self.posX + TILE_WIDTH, self.posY, self.posZ + TILE_DEPTH),
|
||||
(self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH),
|
||||
(self.posX, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH)
|
||||
]
|
||||
indices = [0, 1, 2, 0, 2, 3]
|
||||
uvs = [ (0, 0), (1, 0), (1, 1), (0, 1) ]
|
||||
colors = [ (255, 128, 255, 255) ] * 4
|
||||
|
||||
else:
|
||||
# Solid black cube for unknown shape
|
||||
x0, y0, z0 = self.posX, self.posY, self.posZ
|
||||
x1, y1, z1 = self.posX + TILE_WIDTH, self.posY + TILE_HEIGHT, self.posZ + TILE_DEPTH
|
||||
vertices = [
|
||||
(x0, y0, z0), (x1, y0, z0), (x1, y1, z0), (x0, y1, z0), # bottom
|
||||
(x0, y0, z1), (x1, y0, z1), (x1, y1, z1), (x0, y1, z1) # top
|
||||
]
|
||||
indices = [
|
||||
0,1,2, 0,2,3, # bottom
|
||||
4,5,6, 4,6,7, # top
|
||||
0,1,5, 0,5,4, # front
|
||||
2,3,7, 2,7,6, # back
|
||||
1,2,6, 1,6,5, # right
|
||||
3,0,4, 3,4,7 # left
|
||||
]
|
||||
uvs = [ (0,0) ] * 8
|
||||
colors = [ (0,0,0,255) ] * 8
|
||||
|
||||
return {
|
||||
'vertices': vertices,
|
||||
'indices': indices,
|
||||
'uvs': uvs,
|
||||
'colors': colors
|
||||
}
|
||||
|
||||
def buffer(self, vertexBuffer):
|
||||
if self.shape == TILE_SHAPE_NULL:
|
||||
return
|
||||
|
||||
# New code:
|
||||
baseData = self.getBaseTileModel()
|
||||
|
||||
# Base data is indiced but we need to buffer unindiced data
|
||||
for index in baseData['indices']:
|
||||
verts = baseData['vertices'][index]
|
||||
uv = baseData['uvs'][index]
|
||||
color = baseData['colors'][index]
|
||||
|
||||
vertexBuffer.vertices.extend([
|
||||
verts[0] - (TILE_WIDTH / 2.0),
|
||||
verts[1] - (TILE_HEIGHT / 2.0),
|
||||
verts[2] - (TILE_DEPTH / 2.0)
|
||||
])
|
||||
|
||||
vertexBuffer.colors.extend([
|
||||
color[0] / 255.0,
|
||||
color[1] / 255.0,
|
||||
color[2] / 255.0,
|
||||
color[3] / 255.0
|
||||
])
|
||||
@@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication, QVBoxLayout, QPushButton,
|
||||
QDialog
|
||||
)
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
from tools.editor.maptool import MapWindow
|
||||
from tools.editor.langtool import LangToolWindow
|
||||
from tools.editor.cutscenetool import CutsceneToolWindow
|
||||
|
||||
DEFAULT_TOOL = None
|
||||
DEFAULT_TOOL = "map"
|
||||
# DEFAULT_TOOL = "cutscene"
|
||||
|
||||
TOOLS = [
|
||||
("Map Editor", "map", MapWindow),
|
||||
("Language Editor", "language", LangToolWindow),
|
||||
("Cutscene Editor", "cutscene", CutsceneToolWindow),
|
||||
]
|
||||
|
||||
class EditorChoiceDialog(QDialog):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Choose Tool")
|
||||
layout = QVBoxLayout(self)
|
||||
self.selected = None
|
||||
for label, key, win_cls in TOOLS:
|
||||
btn = QPushButton(label)
|
||||
btn.clicked.connect(lambda checked, w=win_cls: self.choose_tool(w))
|
||||
layout.addWidget(btn)
|
||||
|
||||
def choose_tool(self, win_cls):
|
||||
self.selected = win_cls
|
||||
self.accept()
|
||||
|
||||
def get_choice(self):
|
||||
return self.selected
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
tool_map = { key: win_cls for _, key, win_cls in TOOLS }
|
||||
if DEFAULT_TOOL in tool_map:
|
||||
win_cls = tool_map[DEFAULT_TOOL]
|
||||
else:
|
||||
choice_dialog = EditorChoiceDialog()
|
||||
if choice_dialog.exec_() == QDialog.Accepted:
|
||||
win_cls = choice_dialog.get_choice()
|
||||
else:
|
||||
sys.exit(0)
|
||||
win = win_cls()
|
||||
win.show()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,58 +0,0 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLineEdit, QLabel, QSizePolicy, QComboBox, QHBoxLayout, QSpacerItem
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from .cutscenewait import CutsceneWaitEditor
|
||||
from .cutscenetext import CutsceneTextEditor
|
||||
|
||||
EDITOR_MAP = (
|
||||
( "wait", "Wait", CutsceneWaitEditor ),
|
||||
( "text", "Text", CutsceneTextEditor )
|
||||
)
|
||||
|
||||
class CutsceneItemEditor(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.layout = QVBoxLayout(self)
|
||||
self.layout.setAlignment(Qt.AlignTop | Qt.AlignLeft)
|
||||
self.layout.addWidget(QLabel("Item Properties:"))
|
||||
|
||||
rowLayout = QHBoxLayout()
|
||||
rowLayout.setSpacing(8)
|
||||
|
||||
rowLayout.addWidget(QLabel("Name:"))
|
||||
self.nameInput = QLineEdit()
|
||||
rowLayout.addWidget(self.nameInput)
|
||||
|
||||
rowLayout.addWidget(QLabel("Type:"))
|
||||
self.typeDropdown = QComboBox()
|
||||
self.typeDropdown.addItems([typeName for typeKey, typeName, editorClass in EDITOR_MAP])
|
||||
rowLayout.addWidget(self.typeDropdown)
|
||||
self.layout.addLayout(rowLayout)
|
||||
|
||||
self.activeEditor = None
|
||||
|
||||
# Events
|
||||
self.nameInput.textChanged.connect(self.onNameChanged)
|
||||
self.typeDropdown.currentTextChanged.connect(self.onTypeChanged)
|
||||
|
||||
# First load
|
||||
self.onNameChanged(self.nameInput.text())
|
||||
self.onTypeChanged(self.typeDropdown.currentText())
|
||||
|
||||
def onNameChanged(self, nameText):
|
||||
pass
|
||||
|
||||
def onTypeChanged(self, typeText):
|
||||
typeKey = typeText.lower()
|
||||
|
||||
# Remove existing editor
|
||||
if self.activeEditor:
|
||||
self.layout.removeWidget(self.activeEditor)
|
||||
self.activeEditor.deleteLater()
|
||||
self.activeEditor = None
|
||||
|
||||
# Create new editor
|
||||
for key, name, editorClass in EDITOR_MAP:
|
||||
if key == typeKey:
|
||||
self.activeEditor = editorClass()
|
||||
self.layout.addWidget(self.activeEditor)
|
||||
break
|
||||
@@ -1,54 +0,0 @@
|
||||
from PyQt5.QtWidgets import QMenuBar, QAction, QFileDialog, QMessageBox
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
|
||||
class CutsceneMenuBar(QMenuBar):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
fileMenu = self.addMenu("File")
|
||||
|
||||
self.newAction = QAction("New", self)
|
||||
self.newAction.setShortcut(QKeySequence.New)
|
||||
self.newAction.triggered.connect(self.newFile)
|
||||
fileMenu.addAction(self.newAction)
|
||||
|
||||
self.openAction = QAction("Open", self)
|
||||
self.openAction.setShortcut(QKeySequence.Open)
|
||||
self.openAction.triggered.connect(self.openFile)
|
||||
fileMenu.addAction(self.openAction)
|
||||
|
||||
self.saveAction = QAction("Save", self)
|
||||
self.saveAction.setShortcut(QKeySequence.Save)
|
||||
self.saveAction.triggered.connect(self.saveFile)
|
||||
fileMenu.addAction(self.saveAction)
|
||||
|
||||
self.saveAsAction = QAction("Save As", self)
|
||||
self.saveAsAction.setShortcut(QKeySequence.SaveAs)
|
||||
self.saveAsAction.triggered.connect(self.saveFileAs)
|
||||
fileMenu.addAction(self.saveAsAction)
|
||||
|
||||
def newFile(self):
|
||||
self.parent.clearCutscene()
|
||||
|
||||
def openFile(self):
|
||||
path, _ = QFileDialog.getOpenFileName(self.parent, "Open Cutscene File", "", "JSON Files (*.json);;All Files (*)")
|
||||
if not path:
|
||||
return
|
||||
|
||||
# TODO: Load file contents into timeline
|
||||
self.parent.currentFile = path
|
||||
pass
|
||||
|
||||
def saveFile(self):
|
||||
if not self.parent.currentFile:
|
||||
self.saveFileAs()
|
||||
return
|
||||
|
||||
# TODO: Save timeline to self.parent.currentFile
|
||||
pass
|
||||
|
||||
def saveFileAs(self):
|
||||
path, _ = QFileDialog.getSaveFileName(self.parent, "Save Cutscene File As", "", "JSON Files (*.json);;All Files (*)")
|
||||
if path:
|
||||
self.parent.currentFile = path
|
||||
self.saveFile()
|
||||
@@ -1,21 +0,0 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QTextEdit
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
class CutsceneTextEditor(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
label = QLabel("Text:")
|
||||
label.setSizePolicy(label.sizePolicy().Expanding, label.sizePolicy().Fixed)
|
||||
layout.addWidget(label)
|
||||
self.textInput = QTextEdit()
|
||||
self.textInput.setSizePolicy(self.textInput.sizePolicy().Expanding, self.textInput.sizePolicy().Expanding)
|
||||
layout.addWidget(self.textInput, stretch=1)
|
||||
|
||||
def setText(self, text):
|
||||
self.textInput.setPlainText(text)
|
||||
|
||||
def getText(self):
|
||||
return self.textInput.toPlainText()
|
||||
@@ -1,20 +0,0 @@
|
||||
from PyQt5.QtWidgets import QWidget, QFormLayout, QDoubleSpinBox, QLabel
|
||||
|
||||
class CutsceneWaitEditor(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
layout = QFormLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
self.waitTimeInput = QDoubleSpinBox()
|
||||
self.waitTimeInput.setMinimum(0.0)
|
||||
self.waitTimeInput.setMaximum(9999.0)
|
||||
self.waitTimeInput.setDecimals(2)
|
||||
self.waitTimeInput.setSingleStep(0.1)
|
||||
layout.addRow(QLabel("Wait Time (seconds):"), self.waitTimeInput)
|
||||
|
||||
def setWaitTime(self, value):
|
||||
self.waitTimeInput.setValue(value)
|
||||
|
||||
def getWaitTime(self):
|
||||
return self.waitTimeInput.value()
|
||||
@@ -1,101 +0,0 @@
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QListWidget, QListWidgetItem, QMenuBar, QAction, QFileDialog, QMessageBox
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
from tools.editor.cutscene.cutsceneitemeditor import CutsceneItemEditor
|
||||
from tools.editor.cutscene.cutscenemenubar import CutsceneMenuBar
|
||||
import sys
|
||||
|
||||
class CutsceneToolWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Dusk Cutscene Editor")
|
||||
self.setGeometry(100, 100, 800, 600)
|
||||
self.nextItemNumber = 1 # Track next available number
|
||||
self.currentFile = None
|
||||
self.dirty = False # Track unsaved changes
|
||||
|
||||
# File menu (handled by CutsceneMenuBar)
|
||||
menubar = CutsceneMenuBar(self)
|
||||
self.setMenuBar(menubar)
|
||||
|
||||
# Main layout: horizontal split
|
||||
central = QWidget()
|
||||
mainLayout = QHBoxLayout(central)
|
||||
self.setCentralWidget(central)
|
||||
|
||||
# Timeline
|
||||
leftPanel = QWidget()
|
||||
leftLayout = QVBoxLayout(leftPanel)
|
||||
|
||||
self.timelineList = QListWidget()
|
||||
self.timelineList.setSelectionMode(QListWidget.SingleSelection)
|
||||
leftLayout.addWidget(QLabel("Cutscene Timeline"))
|
||||
leftLayout.addWidget(self.timelineList)
|
||||
|
||||
btnLayout = QHBoxLayout()
|
||||
self.addBtn = QPushButton("Add")
|
||||
self.removeBtn = QPushButton("Remove")
|
||||
btnLayout.addWidget(self.addBtn)
|
||||
btnLayout.addWidget(self.removeBtn)
|
||||
leftLayout.addLayout(btnLayout)
|
||||
mainLayout.addWidget(leftPanel, 2)
|
||||
|
||||
# Property editor
|
||||
self.editorPanel = QWidget()
|
||||
self.editorLayout = QVBoxLayout(self.editorPanel)
|
||||
self.itemEditor = None # Only create when needed
|
||||
mainLayout.addWidget(self.editorPanel, 3)
|
||||
|
||||
# Events
|
||||
self.timelineList.currentItemChanged.connect(self.onItemSelected)
|
||||
self.addBtn.clicked.connect(self.addCutsceneItem)
|
||||
self.removeBtn.clicked.connect(self.removeCutsceneItem)
|
||||
|
||||
def addCutsceneItem(self):
|
||||
name = f"Cutscene item {self.nextItemNumber}"
|
||||
timelineItem = QListWidgetItem(name)
|
||||
self.timelineList.addItem(timelineItem)
|
||||
self.timelineList.setCurrentItem(timelineItem)
|
||||
self.nextItemNumber += 1
|
||||
self.dirty = True
|
||||
|
||||
def removeCutsceneItem(self):
|
||||
row = self.timelineList.currentRow()
|
||||
if row < 0:
|
||||
return
|
||||
self.timelineList.takeItem(row)
|
||||
self.dirty = True
|
||||
|
||||
# Remove editor if nothing selected
|
||||
if self.timelineList.currentItem() is None or self.itemEditor is None:
|
||||
return
|
||||
|
||||
self.editorLayout.removeWidget(self.itemEditor)
|
||||
self.itemEditor.deleteLater()
|
||||
self.itemEditor = None
|
||||
|
||||
def clearCutscene(self):
|
||||
self.timelineList.clear()
|
||||
self.nextItemNumber = 1
|
||||
self.currentFile = None
|
||||
self.dirty = False
|
||||
if self.itemEditor:
|
||||
self.editorLayout.removeWidget(self.itemEditor)
|
||||
|
||||
def onItemSelected(self, current, previous):
|
||||
if current:
|
||||
if not self.itemEditor:
|
||||
self.itemEditor = CutsceneItemEditor()
|
||||
self.editorLayout.addWidget(self.itemEditor)
|
||||
return
|
||||
|
||||
if not self.itemEditor:
|
||||
return
|
||||
self.editorLayout.removeWidget(self.itemEditor)
|
||||
self.itemEditor.deleteLater()
|
||||
self.itemEditor = None
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = CutsceneToolWindow()
|
||||
window.show()
|
||||
sys.exit(app.exec_())
|
||||
@@ -1,202 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QAction, QMenuBar, QMessageBox, QFileDialog, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QTableWidget, QTableWidgetItem, QHeaderView, QPushButton, QTabWidget, QFormLayout
|
||||
from PyQt5.QtCore import Qt
|
||||
import sys
|
||||
import os
|
||||
import polib
|
||||
|
||||
class LangToolWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Dusk Language Editor")
|
||||
self.setGeometry(100, 100, 800, 600)
|
||||
self.current_file = None
|
||||
self.dirty = False
|
||||
self.init_menu()
|
||||
self.init_ui()
|
||||
|
||||
def init_ui(self):
|
||||
central = QWidget()
|
||||
layout = QVBoxLayout(central)
|
||||
|
||||
tabs = QTabWidget()
|
||||
# Header Tab
|
||||
header_tab = QWidget()
|
||||
header_layout = QFormLayout(header_tab)
|
||||
self.language_edit = QLineEdit()
|
||||
self.language_edit.setMaximumWidth(220)
|
||||
header_layout.addRow(QLabel("Language:"), self.language_edit)
|
||||
self.plural_edit = QLineEdit()
|
||||
self.plural_edit.setMaximumWidth(320)
|
||||
header_layout.addRow(QLabel("Plural-Forms:"), self.plural_edit)
|
||||
self.content_type_edit = QLineEdit("text/plain; charset=UTF-8")
|
||||
self.content_type_edit.setMaximumWidth(320)
|
||||
header_layout.addRow(QLabel("Content-Type:"), self.content_type_edit)
|
||||
tabs.addTab(header_tab, "Header")
|
||||
|
||||
# Strings Tab
|
||||
strings_tab = QWidget()
|
||||
strings_layout = QVBoxLayout(strings_tab)
|
||||
self.po_table = QTableWidget()
|
||||
self.po_table.setColumnCount(2)
|
||||
self.po_table.setHorizontalHeaderLabels(["msgid", "msgstr"])
|
||||
self.po_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
self.po_table.verticalHeader().setMinimumWidth(22)
|
||||
self.po_table.verticalHeader().setDefaultAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
||||
strings_layout.addWidget(self.po_table)
|
||||
row_btn_layout = QHBoxLayout()
|
||||
add_row_btn = QPushButton("Add Row")
|
||||
remove_row_btn = QPushButton("Remove Row")
|
||||
row_btn_layout.addWidget(add_row_btn)
|
||||
row_btn_layout.addWidget(remove_row_btn)
|
||||
strings_layout.addLayout(row_btn_layout)
|
||||
tabs.addTab(strings_tab, "Strings")
|
||||
|
||||
layout.addWidget(tabs)
|
||||
|
||||
add_row_btn.clicked.connect(self.add_row)
|
||||
remove_row_btn.clicked.connect(self.remove_row)
|
||||
self.add_row_btn = add_row_btn
|
||||
self.remove_row_btn = remove_row_btn
|
||||
|
||||
self.setCentralWidget(central)
|
||||
|
||||
# Connect edits to dirty flag
|
||||
self.language_edit.textChanged.connect(self.set_dirty)
|
||||
self.plural_edit.textChanged.connect(self.set_dirty)
|
||||
self.content_type_edit.textChanged.connect(self.set_dirty)
|
||||
self.po_table.itemChanged.connect(self.set_dirty)
|
||||
|
||||
def set_dirty(self):
|
||||
self.dirty = True
|
||||
self.update_save_action()
|
||||
|
||||
def init_menu(self):
|
||||
menubar = self.menuBar()
|
||||
file_menu = menubar.addMenu("File")
|
||||
|
||||
new_action = QAction("New", self)
|
||||
open_action = QAction("Open", self)
|
||||
save_action = QAction("Save", self)
|
||||
save_as_action = QAction("Save As", self)
|
||||
|
||||
new_action.triggered.connect(lambda: self.handle_file_action("new"))
|
||||
open_action.triggered.connect(lambda: self.handle_file_action("open"))
|
||||
save_action.triggered.connect(self.handle_save)
|
||||
save_as_action.triggered.connect(self.handle_save_as)
|
||||
|
||||
file_menu.addAction(new_action)
|
||||
file_menu.addAction(open_action)
|
||||
file_menu.addAction(save_action)
|
||||
file_menu.addAction(save_as_action)
|
||||
|
||||
self.save_action = save_action # Store reference for enabling/disabling
|
||||
self.update_save_action()
|
||||
|
||||
def update_save_action(self):
|
||||
self.save_action.setEnabled(self.current_file is not None)
|
||||
|
||||
def handle_file_action(self, action):
|
||||
if self.dirty:
|
||||
reply = QMessageBox.question(self, "Save Changes?", "Do you want to save changes before proceeding?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
|
||||
if reply == QMessageBox.Cancel:
|
||||
return
|
||||
elif reply == QMessageBox.Yes:
|
||||
self.handle_save()
|
||||
if action == "new":
|
||||
self.new_file()
|
||||
elif action == "open":
|
||||
default_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../assets/locale"))
|
||||
file_path, _ = QFileDialog.getOpenFileName(self, "Open Language File", default_dir, "PO Files (*.po)")
|
||||
if file_path:
|
||||
self.open_file(file_path)
|
||||
|
||||
def new_file(self):
|
||||
self.current_file = None
|
||||
self.dirty = False
|
||||
self.language_edit.setText("")
|
||||
self.plural_edit.setText("")
|
||||
self.po_table.setRowCount(0)
|
||||
self.update_save_action()
|
||||
|
||||
def open_file(self, file_path):
|
||||
self.current_file = file_path
|
||||
self.dirty = False
|
||||
self.update_save_action()
|
||||
self.load_po_file(file_path)
|
||||
|
||||
def load_po_file(self, file_path):
|
||||
po = polib.pofile(file_path)
|
||||
language = po.metadata.get('Language', '')
|
||||
plural = po.metadata.get('Plural-Forms', '')
|
||||
content_type = po.metadata.get('Content-Type', 'text/plain; charset=UTF-8')
|
||||
self.language_edit.setText(language)
|
||||
self.plural_edit.setText(plural)
|
||||
self.content_type_edit.setText(content_type)
|
||||
self.po_table.setRowCount(len(po))
|
||||
for row, entry in enumerate(po):
|
||||
self.po_table.setItem(row, 0, QTableWidgetItem(entry.msgid))
|
||||
self.po_table.setItem(row, 1, QTableWidgetItem(entry.msgstr))
|
||||
|
||||
def save_file(self, file_path):
|
||||
po = polib.POFile()
|
||||
po.metadata = {
|
||||
'Language': self.language_edit.text(),
|
||||
'Content-Type': self.content_type_edit.text(),
|
||||
'Plural-Forms': self.plural_edit.text(),
|
||||
}
|
||||
for row in range(self.po_table.rowCount()):
|
||||
msgid_item = self.po_table.item(row, 0)
|
||||
msgstr_item = self.po_table.item(row, 1)
|
||||
msgid = msgid_item.text() if msgid_item else ''
|
||||
msgstr = msgstr_item.text() if msgstr_item else ''
|
||||
if msgid or msgstr:
|
||||
entry = polib.POEntry(msgid=msgid, msgstr=msgstr)
|
||||
po.append(entry)
|
||||
po.save(file_path)
|
||||
self.dirty = False
|
||||
self.update_save_action()
|
||||
|
||||
def handle_save(self):
|
||||
if self.current_file:
|
||||
self.save_file(self.current_file)
|
||||
else:
|
||||
self.handle_save_as()
|
||||
|
||||
def handle_save_as(self):
|
||||
default_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../assets/locale"))
|
||||
file_path, _ = QFileDialog.getSaveFileName(self, "Save Language File As", default_dir, "PO Files (*.po)")
|
||||
if file_path:
|
||||
self.current_file = file_path
|
||||
self.update_save_action()
|
||||
self.save_file(file_path)
|
||||
|
||||
def add_row(self):
|
||||
row = self.po_table.rowCount()
|
||||
self.po_table.insertRow(row)
|
||||
self.po_table.setItem(row, 0, QTableWidgetItem(""))
|
||||
self.po_table.setItem(row, 1, QTableWidgetItem(""))
|
||||
self.po_table.setCurrentCell(row, 0)
|
||||
self.set_dirty()
|
||||
|
||||
def remove_row(self):
|
||||
row = self.po_table.currentRow()
|
||||
if row >= 0:
|
||||
self.po_table.removeRow(row)
|
||||
self.set_dirty()
|
||||
|
||||
def closeEvent(self, event):
|
||||
if self.dirty:
|
||||
reply = QMessageBox.question(self, "Save Changes?", "Do you want to save changes before exiting?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
|
||||
if reply == QMessageBox.Cancel:
|
||||
event.ignore()
|
||||
return
|
||||
elif reply == QMessageBox.Yes:
|
||||
self.handle_save()
|
||||
event.accept()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = LangToolWindow()
|
||||
window.show()
|
||||
sys.exit(app.exec_())
|
||||
@@ -1,55 +0,0 @@
|
||||
import math
|
||||
import time
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH, RPG_CAMERA_PIXELS_PER_UNIT, RPG_CAMERA_Z_OFFSET, RPG_CAMERA_FOV
|
||||
|
||||
class Camera:
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.pixelsPerUnit = RPG_CAMERA_PIXELS_PER_UNIT
|
||||
self.yOffset = RPG_CAMERA_Z_OFFSET
|
||||
self.fov = RPG_CAMERA_FOV
|
||||
self.scale = 8.0
|
||||
self.lastTime = time.time()
|
||||
self.lookAtTarget = [0.0, 0.0, 0.0]
|
||||
|
||||
def setup(self, vw, vh, duration=0.1):
|
||||
now = time.time()
|
||||
delta = now - self.lastTime
|
||||
self.lastTime = now
|
||||
# Calculate ease factor for exponential smoothing over 'duration' seconds
|
||||
ease = 1 - math.exp(-delta / duration)
|
||||
|
||||
z = (vh / 2.0) / (
|
||||
(self.pixelsPerUnit * self.scale) * math.tan(math.radians(self.fov / 2.0))
|
||||
)
|
||||
lookAt = [
|
||||
self.parent.map.position[0] * TILE_WIDTH,
|
||||
self.parent.map.position[1] * TILE_HEIGHT,
|
||||
self.parent.map.position[2] * TILE_DEPTH,
|
||||
]
|
||||
aspectRatio = vw / vh
|
||||
|
||||
# Ease the lookAt target
|
||||
for i in range(3):
|
||||
self.lookAtTarget[i] += (lookAt[i] - self.lookAtTarget[i]) * ease
|
||||
|
||||
# Camera position is now based on the eased lookAtTarget
|
||||
cameraPosition = (
|
||||
self.lookAtTarget[0],
|
||||
self.lookAtTarget[1] + self.yOffset,
|
||||
self.lookAtTarget[2] + z
|
||||
)
|
||||
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
glLoadIdentity()
|
||||
gluPerspective(self.fov, aspectRatio, 0.1, 1000.0)
|
||||
glScalef(1.0, -1.0, 1.0) # Flip the projection matrix upside down
|
||||
glMatrixMode(GL_MODELVIEW)
|
||||
glLoadIdentity()
|
||||
gluLookAt(
|
||||
cameraPosition[0], cameraPosition[1], cameraPosition[2],
|
||||
self.lookAtTarget[0], self.lookAtTarget[1], self.lookAtTarget[2],
|
||||
0.0, 1.0, 0.0
|
||||
)
|
||||
@@ -1,80 +0,0 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QGridLayout, QTreeWidget, QTreeWidgetItem, QComboBox
|
||||
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPES
|
||||
|
||||
class ChunkPanel(QWidget):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
layout = QVBoxLayout(self)
|
||||
|
||||
# Tile shape dropdown
|
||||
self.tileShapeDropdown = QComboBox()
|
||||
self.tileShapeDropdown.addItems(TILE_SHAPES.keys())
|
||||
self.tileShapeDropdown.setToolTip("Tile Shape")
|
||||
layout.addWidget(self.tileShapeDropdown)
|
||||
|
||||
# Add expandable tree list
|
||||
self.tree = QTreeWidget()
|
||||
self.tree.setHeaderLabel("Chunks")
|
||||
self.tree.expandAll() # Expand by default, remove if you want collapsed
|
||||
layout.addWidget(self.tree) # Removed invalid stretch factor
|
||||
|
||||
# Add stretch so tree expands
|
||||
layout.setStretchFactor(self.tree, 1)
|
||||
|
||||
# Event subscriptions
|
||||
self.parent.map.onMapData.sub(self.onMapData)
|
||||
self.parent.map.onPositionChange.sub(self.onPositionChange)
|
||||
self.tileShapeDropdown.currentTextChanged.connect(self.onTileShapeChanged)
|
||||
|
||||
# For each chunk
|
||||
for chunk in self.parent.map.chunks.values():
|
||||
# Create tree element
|
||||
item = QTreeWidgetItem(self.tree, ["Chunk ({}, {}, {})".format(chunk.x, chunk.y, chunk.z)])
|
||||
chunk.chunkPanelTree = item
|
||||
chunk.chunkPanelTree.setExpanded(True)
|
||||
item.setData(0, 0, chunk) # Store chunk reference
|
||||
|
||||
chunk.onChunkData.sub(self.onChunkData)
|
||||
|
||||
def onMapData(self, data):
|
||||
pass
|
||||
|
||||
def onPositionChange(self, pos):
|
||||
self.updateChunkList()
|
||||
|
||||
tile = self.parent.map.getTileAtWorldPos(*self.parent.map.position)
|
||||
if tile is None:
|
||||
return
|
||||
|
||||
key = "TILE_SHAPE_NULL"
|
||||
for k, v in TILE_SHAPES.items():
|
||||
if v != tile.shape:
|
||||
continue
|
||||
key = k
|
||||
break
|
||||
self.tileShapeDropdown.setCurrentText(key)
|
||||
|
||||
def onTileShapeChanged(self, shape_key):
|
||||
tile = self.parent.map.getTileAtWorldPos(*self.parent.map.position)
|
||||
|
||||
if tile is None or shape_key not in TILE_SHAPES:
|
||||
return
|
||||
tile.setShape(TILE_SHAPES[shape_key])
|
||||
|
||||
def updateChunkList(self):
|
||||
# Clear existing items
|
||||
currentChunk = self.parent.map.getChunkAtWorldPos(*self.parent.map.position)
|
||||
|
||||
# Example tree items
|
||||
for chunk in self.parent.map.chunks.values():
|
||||
title = "Chunk ({}, {}, {})".format(chunk.x, chunk.y, chunk.z)
|
||||
if chunk == currentChunk:
|
||||
title += " [C]"
|
||||
if chunk.isDirty():
|
||||
title += " *"
|
||||
item = chunk.chunkPanelTree
|
||||
item.setText(0, title)
|
||||
|
||||
def onChunkData(self, chunk):
|
||||
self.updateChunkList()
|
||||
@@ -1,154 +0,0 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QHBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem
|
||||
from PyQt5.QtCore import Qt
|
||||
from tools.dusk.entity import Entity
|
||||
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, ENTITY_TYPES, ENTITY_TYPE_NULL
|
||||
|
||||
class EntityPanel(QWidget):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
layout = QVBoxLayout(self)
|
||||
self.setLayout(layout)
|
||||
|
||||
# Top panel placeholder
|
||||
topWidget = QLabel("Entity Editor")
|
||||
layout.addWidget(topWidget)
|
||||
|
||||
# Name input
|
||||
nameLayout = QHBoxLayout()
|
||||
nameLabel = QLabel("Name:")
|
||||
self.nameInput = QLineEdit()
|
||||
nameLayout.addWidget(nameLabel)
|
||||
nameLayout.addWidget(self.nameInput)
|
||||
layout.addLayout(nameLayout)
|
||||
|
||||
# Entity Type dropdown (single selection)
|
||||
typeLayout = QHBoxLayout()
|
||||
typeLabel = QLabel("Type:")
|
||||
self.typeDropdown = QComboBox()
|
||||
self.typeDropdown.addItems(ENTITY_TYPES)
|
||||
typeLayout.addWidget(typeLabel)
|
||||
typeLayout.addWidget(self.typeDropdown)
|
||||
layout.addLayout(typeLayout)
|
||||
|
||||
# Entity list and buttons
|
||||
self.entityList = QListWidget()
|
||||
self.entityList.addItems([])
|
||||
layout.addWidget(self.entityList, stretch=1)
|
||||
|
||||
btnLayout = QHBoxLayout()
|
||||
self.btnAdd = QPushButton("Add")
|
||||
self.btnRemove = QPushButton("Remove")
|
||||
btnLayout.addWidget(self.btnAdd)
|
||||
btnLayout.addWidget(self.btnRemove)
|
||||
layout.addLayout(btnLayout)
|
||||
|
||||
# Events
|
||||
self.btnAdd.clicked.connect(self.onAddEntity)
|
||||
self.btnRemove.clicked.connect(self.onRemoveEntity)
|
||||
self.parent.map.onEntityData.sub(self.onEntityData)
|
||||
self.parent.map.onPositionChange.sub(self.onPositionChange)
|
||||
self.entityList.itemClicked.connect(self.onEntityClicked)
|
||||
self.entityList.itemDoubleClicked.connect(self.onEntityDoubleClicked)
|
||||
self.typeDropdown.currentIndexChanged.connect(self.onTypeSelected)
|
||||
self.nameInput.textChanged.connect(self.onNameChanged)
|
||||
|
||||
# Call once to populate
|
||||
self.onEntityData()
|
||||
self.onEntityUnselect()
|
||||
|
||||
def onEntityUnselect(self):
|
||||
self.entityList.setCurrentItem(None)
|
||||
self.nameInput.setText("")
|
||||
self.typeDropdown.setCurrentIndex(ENTITY_TYPE_NULL)
|
||||
|
||||
def onEntitySelect(self, entity):
|
||||
self.entityList.setCurrentItem(entity.item)
|
||||
self.nameInput.setText(entity.name)
|
||||
self.typeDropdown.setCurrentIndex(entity.type)
|
||||
|
||||
def onEntityDoubleClicked(self, item):
|
||||
entity = item.data(Qt.UserRole)
|
||||
chunk = entity.chunk
|
||||
worldX = (chunk.x * CHUNK_WIDTH) + entity.localX
|
||||
worldY = (chunk.y * CHUNK_HEIGHT) + entity.localY
|
||||
worldZ = (chunk.z * CHUNK_DEPTH) + entity.localZ
|
||||
self.parent.map.moveTo(worldX, worldY, worldZ)
|
||||
|
||||
def onEntityClicked(self, item):
|
||||
pass
|
||||
|
||||
def onAddEntity(self):
|
||||
chunk = self.parent.map.getChunkAtWorldPos(*self.parent.map.position)
|
||||
if chunk is None:
|
||||
return
|
||||
|
||||
localX = (self.parent.map.position[0] - (chunk.x * CHUNK_WIDTH)) % CHUNK_WIDTH
|
||||
localY = (self.parent.map.position[1] - (chunk.y * CHUNK_HEIGHT)) % CHUNK_HEIGHT
|
||||
localZ = (self.parent.map.position[2] - (chunk.z * CHUNK_DEPTH)) % CHUNK_DEPTH
|
||||
|
||||
# Make sure there's not already an entity here
|
||||
for ent in chunk.entities.values():
|
||||
if ent.localX == localX and ent.localY == localY and ent.localZ == localZ:
|
||||
print("Entity already exists at this location")
|
||||
return
|
||||
|
||||
ent = chunk.addEntity(localX, localY, localZ)
|
||||
|
||||
def onRemoveEntity(self):
|
||||
item = self.entityList.currentItem()
|
||||
if item is None:
|
||||
return
|
||||
entity = item.data(Qt.UserRole)
|
||||
if entity:
|
||||
chunk = entity.chunk
|
||||
chunk.removeEntity(entity)
|
||||
pass
|
||||
|
||||
def onEntityData(self):
|
||||
self.onEntityUnselect()
|
||||
self.entityList.clear()
|
||||
for chunk in self.parent.map.chunks.values():
|
||||
for id, entity in chunk.entities.items():
|
||||
item = QListWidgetItem(entity.name)
|
||||
item.setData(Qt.UserRole, entity) # Store the entity object
|
||||
entity.item = item
|
||||
self.entityList.addItem(item)
|
||||
|
||||
# Select if there is something at current position
|
||||
self.onPositionChange(self.parent.map.position)
|
||||
|
||||
def onPositionChange(self, position):
|
||||
self.onEntityUnselect()
|
||||
|
||||
# Get Entity at..
|
||||
chunk = self.parent.map.getChunkAtWorldPos(*position)
|
||||
if chunk is None:
|
||||
return
|
||||
|
||||
localX = (position[0] - (chunk.x * CHUNK_WIDTH)) % CHUNK_WIDTH
|
||||
localY = (position[1] - (chunk.y * CHUNK_HEIGHT)) % CHUNK_HEIGHT
|
||||
localZ = (position[2] - (chunk.z * CHUNK_DEPTH)) % CHUNK_DEPTH
|
||||
|
||||
for ent in chunk.entities.values():
|
||||
if ent.localX != localX or ent.localY != localY or ent.localZ != localZ:
|
||||
continue
|
||||
self.onEntitySelect(ent)
|
||||
self.entityList.setCurrentItem(ent.item)
|
||||
break
|
||||
|
||||
def onTypeSelected(self, index):
|
||||
item = self.entityList.currentItem()
|
||||
if item is None:
|
||||
return
|
||||
entity = item.data(Qt.UserRole)
|
||||
if entity:
|
||||
entity.setType(index)
|
||||
|
||||
def onNameChanged(self, text):
|
||||
item = self.entityList.currentItem()
|
||||
if item is None:
|
||||
return
|
||||
entity = item.data(Qt.UserRole)
|
||||
if entity:
|
||||
entity.setName(text)
|
||||
@@ -1,41 +0,0 @@
|
||||
from PyQt5.QtCore import QTimer
|
||||
from PyQt5.QtWidgets import QOpenGLWidget
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
|
||||
class GLWidget(QOpenGLWidget):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
self.timer = QTimer(self)
|
||||
self.timer.timeout.connect(self.update)
|
||||
self.timer.start(16) # ~60 FPS
|
||||
|
||||
def initializeGL(self):
|
||||
glClearColor(0.392, 0.584, 0.929, 1.0)
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
glEnable(GL_BLEND)
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||
glEnable(GL_POLYGON_OFFSET_FILL)
|
||||
glPolygonOffset(1.0, 1.0)
|
||||
glDisable(GL_POLYGON_OFFSET_FILL)
|
||||
|
||||
def resizeGL(self, w, h):
|
||||
pass
|
||||
|
||||
def paintGL(self):
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
glLoadIdentity()
|
||||
|
||||
w = self.width()
|
||||
h = self.height()
|
||||
if h <= 0:
|
||||
h = 1
|
||||
if w <= 0:
|
||||
w = 1
|
||||
|
||||
glViewport(0, 0, w, h)
|
||||
self.parent.camera.setup(w, h)
|
||||
self.parent.grid.draw()
|
||||
self.parent.map.draw()
|
||||
self.parent.selectBox.draw()
|
||||
@@ -1,46 +0,0 @@
|
||||
from OpenGL.GL import *
|
||||
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
||||
|
||||
class Grid:
|
||||
def __init__(self, lines=1000):
|
||||
self.cellWidth = TILE_WIDTH
|
||||
self.cellHeight = TILE_HEIGHT
|
||||
self.lines = lines
|
||||
self.enabled = True
|
||||
|
||||
def draw(self):
|
||||
if not self.enabled:
|
||||
return
|
||||
center = [0.01,0.01,0.01]
|
||||
halfWidth = self.cellWidth * self.lines // 2
|
||||
halfHeight = self.cellHeight * self.lines // 2
|
||||
# Draw origin axes
|
||||
glBegin(GL_LINES)
|
||||
|
||||
# X axis - RED
|
||||
glColor3f(1.0, 0.0, 0.0)
|
||||
glVertex3f(center[0] - halfWidth, center[1], center[2])
|
||||
glVertex3f(center[0] + halfWidth, center[1], center[2])
|
||||
|
||||
# Y axis - GREEN
|
||||
glColor3f(0.0, 1.0, 0.0)
|
||||
glVertex3f(center[0], center[1] - halfHeight, center[2])
|
||||
glVertex3f(center[0], center[1] + halfHeight, center[2])
|
||||
|
||||
# Z axis - BLUE
|
||||
glColor3f(0.0, 0.0, 1.0)
|
||||
glVertex3f(center[0], center[1], center[2] - halfWidth)
|
||||
glVertex3f(center[0], center[1], center[2] + halfWidth)
|
||||
glEnd()
|
||||
|
||||
# Draw grid
|
||||
glColor3f(0.8, 0.8, 0.8)
|
||||
glBegin(GL_LINES)
|
||||
for i in range(-self.lines // 2, self.lines // 2 + 1):
|
||||
# Vertical lines
|
||||
glVertex3f(center[0] + i * self.cellWidth, center[1] - halfHeight, center[2])
|
||||
glVertex3f(center[0] + i * self.cellWidth, center[1] + halfHeight, center[2])
|
||||
# Horizontal lines
|
||||
glVertex3f(center[0] - halfWidth, center[1] + i * self.cellHeight, center[2])
|
||||
glVertex3f(center[0] + halfWidth, center[1] + i * self.cellHeight, center[2])
|
||||
glEnd()
|
||||
@@ -1,83 +0,0 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, QHBoxLayout, QMessageBox
|
||||
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH
|
||||
|
||||
class MapInfoPanel(QWidget):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
|
||||
# Components
|
||||
layout = QVBoxLayout()
|
||||
|
||||
mapTitleLabel = QLabel("Map Title")
|
||||
self.mapTitleInput = QLineEdit()
|
||||
layout.addWidget(mapTitleLabel)
|
||||
layout.addWidget(self.mapTitleInput)
|
||||
|
||||
tilePositionLabel = QLabel("Tile Position")
|
||||
layout.addWidget(tilePositionLabel)
|
||||
tilePositionRow = QHBoxLayout()
|
||||
self.tileXInput = QLineEdit()
|
||||
self.tileXInput.setPlaceholderText("X")
|
||||
tilePositionRow.addWidget(self.tileXInput)
|
||||
self.tileYInput = QLineEdit()
|
||||
self.tileYInput.setPlaceholderText("Y")
|
||||
tilePositionRow.addWidget(self.tileYInput)
|
||||
self.tileZInput = QLineEdit()
|
||||
self.tileZInput.setPlaceholderText("Z")
|
||||
tilePositionRow.addWidget(self.tileZInput)
|
||||
self.tileGo = QPushButton("Go")
|
||||
tilePositionRow.addWidget(self.tileGo)
|
||||
layout.addLayout(tilePositionRow)
|
||||
|
||||
self.chunkPosLabel = QLabel()
|
||||
layout.addWidget(self.chunkPosLabel)
|
||||
self.chunkLabel = QLabel()
|
||||
layout.addWidget(self.chunkLabel)
|
||||
|
||||
layout.addStretch()
|
||||
self.setLayout(layout)
|
||||
|
||||
# Events
|
||||
self.tileGo.clicked.connect(self.goToPosition)
|
||||
self.tileXInput.returnPressed.connect(self.goToPosition)
|
||||
self.tileYInput.returnPressed.connect(self.goToPosition)
|
||||
self.tileZInput.returnPressed.connect(self.goToPosition)
|
||||
self.parent.map.onPositionChange.sub(self.updatePositionLabels)
|
||||
self.parent.map.onMapData.sub(self.onMapData)
|
||||
self.mapTitleInput.textChanged.connect(self.onMapNameChange)
|
||||
|
||||
# Initial label setting
|
||||
self.updatePositionLabels(self.parent.map.position)
|
||||
|
||||
def goToPosition(self):
|
||||
try:
|
||||
x = int(self.tileXInput.text())
|
||||
y = int(self.tileYInput.text())
|
||||
z = int(self.tileZInput.text())
|
||||
self.parent.map.moveTo(x, y, z)
|
||||
except ValueError:
|
||||
QMessageBox.warning(self, "Invalid Input", "Please enter valid integer coordinates.")
|
||||
|
||||
def updatePositionLabels(self, pos):
|
||||
self.tileXInput.setText(str(pos[0]))
|
||||
self.tileYInput.setText(str(pos[1]))
|
||||
self.tileZInput.setText(str(pos[2]))
|
||||
|
||||
chunkTileX = pos[0] % CHUNK_WIDTH
|
||||
chunkTileY = pos[1] % CHUNK_HEIGHT
|
||||
chunkTileZ = pos[2] % CHUNK_DEPTH
|
||||
chunkTileIndex = chunkTileX + chunkTileY * CHUNK_WIDTH + chunkTileZ * CHUNK_WIDTH * CHUNK_HEIGHT
|
||||
self.chunkPosLabel.setText(f"Chunk Position: {chunkTileX}, {chunkTileY}, {chunkTileZ} ({chunkTileIndex})")
|
||||
|
||||
chunkX = pos[0] // CHUNK_WIDTH
|
||||
chunkY = pos[1] // CHUNK_HEIGHT
|
||||
chunkZ = pos[2] // CHUNK_DEPTH
|
||||
self.chunkLabel.setText(f"Chunk: {chunkX}, {chunkY}, {chunkZ}")
|
||||
|
||||
def onMapData(self, data):
|
||||
self.updatePositionLabels(self.parent.map.position)
|
||||
self.mapTitleInput.setText(data.get("mapName", ""))
|
||||
|
||||
def onMapNameChange(self, text):
|
||||
self.parent.map.data['mapName'] = text
|
||||
@@ -1,51 +0,0 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QGridLayout, QPushButton, QTabWidget, QLabel
|
||||
from tools.editor.map.chunkpanel import ChunkPanel
|
||||
from tools.editor.map.entitypanel import EntityPanel
|
||||
from tools.editor.map.regionpanel import RegionPanel
|
||||
|
||||
class MapLeftPanel(QWidget):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
layout = QVBoxLayout(self)
|
||||
self.setLayout(layout)
|
||||
|
||||
# Nav buttons
|
||||
self.chunkInfoLabel = QLabel("Tile Information")
|
||||
layout.addWidget(self.chunkInfoLabel)
|
||||
grid = QGridLayout()
|
||||
self.btnUp = QPushButton("U")
|
||||
self.btnN = QPushButton("N")
|
||||
self.btnDown = QPushButton("D")
|
||||
self.btnW = QPushButton("W")
|
||||
self.btnS = QPushButton("S")
|
||||
self.btnE = QPushButton("E")
|
||||
|
||||
grid.addWidget(self.btnUp, 0, 0)
|
||||
grid.addWidget(self.btnN, 0, 1)
|
||||
grid.addWidget(self.btnDown, 0, 2)
|
||||
grid.addWidget(self.btnW, 1, 0)
|
||||
grid.addWidget(self.btnS, 1, 1)
|
||||
grid.addWidget(self.btnE, 1, 2)
|
||||
layout.addLayout(grid)
|
||||
|
||||
# Panels
|
||||
self.chunkPanel = ChunkPanel(self.parent)
|
||||
self.entityPanel = EntityPanel(self.parent)
|
||||
self.regionPanel = RegionPanel(self.parent)
|
||||
|
||||
# Tabs
|
||||
self.tabs = QTabWidget()
|
||||
self.tabs.addTab(self.chunkPanel, "Tiles")
|
||||
self.tabs.addTab(self.entityPanel, "Entities")
|
||||
self.tabs.addTab(self.regionPanel, "Regions")
|
||||
self.tabs.addTab(None, "Triggers")
|
||||
layout.addWidget(self.tabs)
|
||||
|
||||
# Event subscriptions
|
||||
self.btnN.clicked.connect(lambda: self.parent.map.moveRelative(0, -1, 0))
|
||||
self.btnS.clicked.connect(lambda: self.parent.map.moveRelative(0, 1, 0))
|
||||
self.btnE.clicked.connect(lambda: self.parent.map.moveRelative(1, 0, 0))
|
||||
self.btnW.clicked.connect(lambda: self.parent.map.moveRelative(-1, 0, 0))
|
||||
self.btnUp.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, 1))
|
||||
self.btnDown.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, -1))
|
||||
@@ -1,46 +0,0 @@
|
||||
import os
|
||||
from PyQt5.QtWidgets import QAction, QMenuBar, QFileDialog
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
from tools.dusk.map import MAP_DEFAULT_PATH
|
||||
|
||||
class MapMenubar:
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.menubar = QMenuBar(parent)
|
||||
parent.setMenuBar(self.menubar)
|
||||
|
||||
self.fileMenu = self.menubar.addMenu("File")
|
||||
self.actionNew = QAction("New", parent)
|
||||
self.actionOpen = QAction("Open", parent)
|
||||
self.actionSave = QAction("Save", parent)
|
||||
self.actionSaveAs = QAction("Save As", parent)
|
||||
|
||||
self.actionNew.setShortcut(QKeySequence("Ctrl+N"))
|
||||
self.actionOpen.setShortcut(QKeySequence("Ctrl+O"))
|
||||
self.actionSave.setShortcut(QKeySequence("Ctrl+S"))
|
||||
self.actionSaveAs.setShortcut(QKeySequence("Ctrl+Shift+S"))
|
||||
|
||||
self.actionNew.triggered.connect(self.newFile)
|
||||
self.actionOpen.triggered.connect(self.openFile)
|
||||
self.actionSave.triggered.connect(self.saveFile)
|
||||
self.actionSaveAs.triggered.connect(self.saveAsFile)
|
||||
self.fileMenu.addAction(self.actionNew)
|
||||
self.fileMenu.addAction(self.actionOpen)
|
||||
self.fileMenu.addAction(self.actionSave)
|
||||
self.fileMenu.addAction(self.actionSaveAs)
|
||||
|
||||
def newFile(self):
|
||||
self.parent.map.newFile()
|
||||
|
||||
def openFile(self):
|
||||
filePath, _ = QFileDialog.getOpenFileName(self.menubar, "Open Map File", MAP_DEFAULT_PATH, "Map Files (*.json)")
|
||||
if filePath:
|
||||
self.parent.map.load(filePath)
|
||||
|
||||
def saveFile(self):
|
||||
self.parent.map.save()
|
||||
|
||||
def saveAsFile(self):
|
||||
filePath, _ = QFileDialog.getSaveFileName(self.menubar, "Save Map File As", MAP_DEFAULT_PATH, "Map Files (*.json)")
|
||||
if filePath:
|
||||
self.parent.map.save(filePath)
|
||||
@@ -1,15 +0,0 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QHBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem
|
||||
from PyQt5.QtCore import Qt
|
||||
from tools.dusk.entity import Entity
|
||||
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, ENTITY_TYPES, ENTITY_TYPE_NULL
|
||||
|
||||
class RegionPanel(QWidget):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
layout = QVBoxLayout(self)
|
||||
self.setLayout(layout)
|
||||
|
||||
# Top panel placeholder
|
||||
topWidget = QLabel("Region Editor")
|
||||
layout.addWidget(topWidget)
|
||||
@@ -1,44 +0,0 @@
|
||||
import OpenGL.GL as gl
|
||||
from tools.dusk.defs import defs
|
||||
import colorsys
|
||||
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
||||
|
||||
class SelectBox:
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.hue = 0.0
|
||||
|
||||
def draw(self):
|
||||
position = [
|
||||
self.parent.map.position[0] * TILE_WIDTH - (TILE_WIDTH / 2.0),
|
||||
self.parent.map.position[1] * TILE_HEIGHT - (TILE_HEIGHT / 2.0),
|
||||
self.parent.map.position[2] * TILE_DEPTH - (TILE_DEPTH / 2.0)
|
||||
]
|
||||
|
||||
vertices = [
|
||||
(position[0], position[1], position[2]),
|
||||
(position[0]+TILE_WIDTH, position[1], position[2]),
|
||||
(position[0]+TILE_WIDTH, position[1]+TILE_HEIGHT, position[2]),
|
||||
(position[0], position[1]+TILE_HEIGHT, position[2]),
|
||||
(position[0], position[1], position[2]+TILE_DEPTH),
|
||||
(position[0]+TILE_WIDTH, position[1], position[2]+TILE_DEPTH),
|
||||
(position[0]+TILE_WIDTH, position[1]+TILE_HEIGHT, position[2]+TILE_DEPTH),
|
||||
(position[0], position[1]+TILE_HEIGHT, position[2]+TILE_DEPTH)
|
||||
]
|
||||
edges = [
|
||||
(0, 1), (1, 2), (2, 3), (3, 0), # bottom face
|
||||
(4, 5), (5, 6), (6, 7), (7, 4), # top face
|
||||
(4, 5), (5, 6), (6, 7), (7, 4), # top face
|
||||
(0, 4), (1, 5), (2, 6), (3, 7) # vertical edges
|
||||
]
|
||||
|
||||
# Cycle hue
|
||||
self.hue = (self.hue + 0.01) % 1.0
|
||||
r, g, b = colorsys.hsv_to_rgb(self.hue, 1.0, 1.0)
|
||||
gl.glColor3f(r, g, b)
|
||||
gl.glLineWidth(2.0)
|
||||
gl.glBegin(gl.GL_LINES)
|
||||
for edge in edges:
|
||||
for vertex in edge:
|
||||
gl.glVertex3f(*vertices[vertex])
|
||||
gl.glEnd()
|
||||
@@ -1,18 +0,0 @@
|
||||
from PyQt5.QtWidgets import QStatusBar, QLabel
|
||||
|
||||
class StatusBar(QStatusBar):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
self.leftLabel = QLabel("")
|
||||
self.rightLabel = QLabel("")
|
||||
self.addWidget(self.leftLabel, 1)
|
||||
self.addPermanentWidget(self.rightLabel)
|
||||
|
||||
parent.map.onMapData.sub(self.onMapData)
|
||||
|
||||
def setStatus(self, message):
|
||||
self.leftLabel.setText(message)
|
||||
|
||||
def onMapData(self, data):
|
||||
self.rightLabel.setText(self.parent.map.mapFileName if self.parent.map.mapFileName else "Untitled.json")
|
||||
@@ -1,80 +0,0 @@
|
||||
from OpenGL.GL import *
|
||||
import array
|
||||
|
||||
class VertexBuffer:
|
||||
def __init__(self, componentsPerVertex=3):
|
||||
self.componentsPerVertex = componentsPerVertex
|
||||
self.vertices = []
|
||||
self.colors = []
|
||||
self.uvs = []
|
||||
self.data = None
|
||||
self.colorData = None
|
||||
self.uvData = None
|
||||
|
||||
def buildData(self):
|
||||
hasColors = len(self.colors) > 0
|
||||
hasUvs = len(self.uvs) > 0
|
||||
|
||||
vertexCount = len(self.vertices) // self.componentsPerVertex
|
||||
|
||||
dataList = []
|
||||
colorList = []
|
||||
uvList = []
|
||||
|
||||
for i in range(vertexCount):
|
||||
vStart = i * self.componentsPerVertex
|
||||
dataList.extend(self.vertices[vStart:vStart+self.componentsPerVertex])
|
||||
|
||||
if hasColors:
|
||||
cStart = i * 4 # Assuming RGBA
|
||||
colorList.extend(self.colors[cStart:cStart+4])
|
||||
|
||||
if hasUvs:
|
||||
uStart = i * 2 # Assuming UV
|
||||
uvList.extend(self.uvs[uStart:uStart+2])
|
||||
|
||||
self.data = array.array('f', dataList)
|
||||
|
||||
if hasColors:
|
||||
self.colorData = array.array('f', colorList)
|
||||
else:
|
||||
self.colorData = None
|
||||
|
||||
if hasUvs:
|
||||
self.uvData = array.array('f', uvList)
|
||||
else:
|
||||
self.uvData = None
|
||||
|
||||
def draw(self, mode=GL_TRIANGLES, count=-1):
|
||||
if count == -1:
|
||||
count = len(self.data) // self.componentsPerVertex
|
||||
|
||||
if count == 0:
|
||||
return
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY)
|
||||
glVertexPointer(self.componentsPerVertex, GL_FLOAT, 0, self.data.tobytes())
|
||||
|
||||
if self.colorData:
|
||||
glEnableClientState(GL_COLOR_ARRAY)
|
||||
glColorPointer(4, GL_FLOAT, 0, self.colorData.tobytes())
|
||||
|
||||
if self.uvData:
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, self.uvData.tobytes())
|
||||
|
||||
glDrawArrays(mode, 0, count)
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY)
|
||||
if self.colorData:
|
||||
glDisableClientState(GL_COLOR_ARRAY)
|
||||
if self.uvData:
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY)
|
||||
|
||||
def clear(self):
|
||||
self.vertices = []
|
||||
self.colors = []
|
||||
self.uvs = []
|
||||
self.data = array.array('f')
|
||||
self.colorData = None
|
||||
self.uvData = None
|
||||
@@ -1,143 +0,0 @@
|
||||
import os
|
||||
from PyQt5.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QMessageBox
|
||||
from PyQt5.QtCore import Qt
|
||||
from tools.editor.map.glwidget import GLWidget
|
||||
from tools.editor.map.mapleftpanel import MapLeftPanel
|
||||
from tools.editor.map.mapinfopanel import MapInfoPanel
|
||||
from tools.editor.map.menubar import MapMenubar
|
||||
from tools.editor.map.statusbar import StatusBar
|
||||
from tools.dusk.map import Map
|
||||
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPE_NULL, TILE_SHAPE_FLOOR
|
||||
from tools.editor.map.selectbox import SelectBox
|
||||
from tools.editor.map.camera import Camera
|
||||
from tools.editor.map.grid import Grid
|
||||
|
||||
class MapWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.insertPressed = False
|
||||
self.deletePressed = False
|
||||
|
||||
# Subclasses
|
||||
self.map = Map(self)
|
||||
self.camera = Camera(self)
|
||||
self.grid = Grid()
|
||||
self.selectBox = SelectBox(self)
|
||||
|
||||
# Window setup
|
||||
self.setWindowTitle("Dusk Map Editor")
|
||||
self.resize(1600, 900)
|
||||
|
||||
# Menubar (TESTING)
|
||||
self.menubar = MapMenubar(self)
|
||||
|
||||
central = QWidget()
|
||||
self.setCentralWidget(central)
|
||||
mainLayout = QHBoxLayout(central)
|
||||
|
||||
# Left panel (tabs + nav buttons)
|
||||
self.leftPanel = MapLeftPanel(self)
|
||||
self.leftPanel.setFixedWidth(350)
|
||||
mainLayout.addWidget(self.leftPanel)
|
||||
|
||||
# Center panel (GLWidget + controls)
|
||||
self.glWidget = GLWidget(self)
|
||||
mainLayout.addWidget(self.glWidget, stretch=3)
|
||||
|
||||
# Right panel (MapInfoPanel)
|
||||
self.mapInfoPanel = MapInfoPanel(self)
|
||||
rightWidget = self.mapInfoPanel
|
||||
rightWidget.setFixedWidth(250)
|
||||
mainLayout.addWidget(rightWidget)
|
||||
|
||||
# Status bar
|
||||
self.statusBar = StatusBar(self)
|
||||
self.setStatusBar(self.statusBar)
|
||||
|
||||
self.installEventFilter(self)
|
||||
self.installEventFilterRecursively(self)
|
||||
|
||||
def installEventFilterRecursively(self, widget):
|
||||
for child in widget.findChildren(QWidget):
|
||||
child.installEventFilter(self)
|
||||
self.installEventFilterRecursively(child)
|
||||
|
||||
def closeEvent(self, event):
|
||||
if not self.map.isDirty():
|
||||
event.accept()
|
||||
return
|
||||
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"Unsaved Changes",
|
||||
"You have unsaved changes. Do you want to save before closing?",
|
||||
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel,
|
||||
QMessageBox.Save
|
||||
)
|
||||
if reply == QMessageBox.Save:
|
||||
self.map.save()
|
||||
elif reply == QMessageBox.Cancel:
|
||||
event.ignore()
|
||||
return
|
||||
event.accept()
|
||||
|
||||
def eventFilter(self, obj, event):
|
||||
if event.type() == event.KeyPress:
|
||||
amtX, amtY, amtZ = 0, 0, 0
|
||||
|
||||
key = event.key()
|
||||
if key == Qt.Key_Left:
|
||||
amtX = -1
|
||||
elif key == Qt.Key_Right:
|
||||
amtX = 1
|
||||
elif key == Qt.Key_Up:
|
||||
amtY = -1
|
||||
elif key == Qt.Key_Down:
|
||||
amtY = 1
|
||||
elif key == Qt.Key_PageUp:
|
||||
amtZ = 1
|
||||
elif key == Qt.Key_PageDown:
|
||||
amtZ = -1
|
||||
|
||||
if event.modifiers() & Qt.ShiftModifier:
|
||||
amtX *= CHUNK_WIDTH
|
||||
amtY *= CHUNK_HEIGHT
|
||||
amtZ *= CHUNK_DEPTH
|
||||
|
||||
if amtX != 0 or amtY != 0 or amtZ != 0:
|
||||
self.map.moveRelative(amtX, amtY, amtZ)
|
||||
if self.insertPressed:
|
||||
tile = self.map.getTileAtWorldPos(*self.map.position)
|
||||
if tile is not None and tile.shape == TILE_SHAPE_NULL:
|
||||
tile.setShape(TILE_SHAPE_FLOOR)
|
||||
if self.deletePressed:
|
||||
tile = self.map.getTileAtWorldPos(*self.map.position)
|
||||
if tile is not None:
|
||||
tile.setShape(TILE_SHAPE_NULL)
|
||||
event.accept()
|
||||
return True
|
||||
|
||||
if key == Qt.Key_Delete:
|
||||
tile = self.map.getTileAtWorldPos(*self.map.position)
|
||||
self.deletePressed = True
|
||||
if tile is not None:
|
||||
tile.setShape(TILE_SHAPE_NULL)
|
||||
event.accept()
|
||||
return True
|
||||
if key == Qt.Key_Insert:
|
||||
tile = self.map.getTileAtWorldPos(*self.map.position)
|
||||
self.insertPressed = True
|
||||
if tile is not None and tile.shape == TILE_SHAPE_NULL:
|
||||
tile.setShape(TILE_SHAPE_FLOOR)
|
||||
event.accept()
|
||||
elif event.type() == event.KeyRelease:
|
||||
key = event.key()
|
||||
if key == Qt.Key_Delete:
|
||||
self.deletePressed = False
|
||||
event.accept()
|
||||
return True
|
||||
if key == Qt.Key_Insert:
|
||||
self.insertPressed = False
|
||||
event.accept()
|
||||
return super().eventFilter(obj, event)
|
||||
@@ -1,7 +1,6 @@
|
||||
import argparse
|
||||
import os
|
||||
import csv
|
||||
from tools.util.type import detectType, stringToCType, typeToCType
|
||||
|
||||
parser = argparse.ArgumentParser(description="Input CSV to .h defines")
|
||||
parser.add_argument("--csv", required=True, help="Path to Input CSV file")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import argparse
|
||||
import os
|
||||
import csv
|
||||
from tools.util.type import detectType, stringToCType, typeToCType
|
||||
|
||||
parser = argparse.ArgumentParser(description="Item CSV to .h defines")
|
||||
parser.add_argument("--csv", required=True, help="Path to item CSV file")
|
||||
|
||||
@@ -0,0 +1,698 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Dusk Tools / Palette Indexer</title>
|
||||
|
||||
<style type="text/css">
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Dusk Palette Indexer</h1>
|
||||
<p>
|
||||
This tool takes an input image and creates a palettized version of it.
|
||||
You will get two files, a .dpf (Dusk Palette File) and a .dpt
|
||||
(Dusk Palettized Texture). The first being the palette, which I recommend
|
||||
reusing across multiple images, and the second being the indexed image,
|
||||
which uses the colors from the palette.
|
||||
</p>
|
||||
<p>
|
||||
Also, dusk previously supported Alpha textures, but due to so many little
|
||||
platform differences I realized it is simpler and about as much work to
|
||||
get palettized textures working instead. As a result I suggest creating a
|
||||
single palette for your alpha textures, and reusing that globally.
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<h2>Input Image</h2>
|
||||
<div>
|
||||
<input type="file" data-file-input />
|
||||
</div>
|
||||
<p data-file-error style="color:red;display:none;"></p>
|
||||
<canvas data-input-preview style="border:1px solid black;"></canvas>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Palette</h2>
|
||||
<div>
|
||||
<button data-palette-add>Add Color</button>
|
||||
<button data-palette-append>Append Palette</button>
|
||||
<button data-palette-clear>Clear Palette</button>
|
||||
<button data-palette-optimize>Optimize Palette</button>
|
||||
</div>
|
||||
|
||||
<div data-palette-entries style="display:grid;grid-template-columns:repeat(auto-fill, minmax(400px, 1fr));gap:16px;margin-top:16px;"></div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Preview Background:
|
||||
<button data-page-bg-white>White</button>
|
||||
<button data-page-bg-transparent>Black</button>
|
||||
<button data-page-bg-checkerboard>Checkerboard</button>
|
||||
<button data-page-bg-magenta>Magenta</button>
|
||||
<button data-page-bg-blue>Blue</button>
|
||||
<button data-page-bg-green>Green</button>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Palette Preview</h2>
|
||||
|
||||
<h3>Palette</h3>
|
||||
<div>
|
||||
<button data-palette-download>Download Palette</button>
|
||||
</div>
|
||||
<canvas data-palette-preview style="border:1px solid black;"></canvas>
|
||||
<p data-palette-information></p>
|
||||
|
||||
<h3>Indexed Image</h3>
|
||||
<div>
|
||||
<button data-indexed-download>Download Indexed Image</button>
|
||||
</div>
|
||||
<div data-output-error style="color:red;display:none;"></div>
|
||||
<div>
|
||||
<label>
|
||||
Preview Scale:
|
||||
<input type="number" value="2" data-indexed-preview-scale min="1" step="1" />
|
||||
</label>
|
||||
</div>
|
||||
<canvas data-output-preview style="border:1px solid black;"></canvas>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
const elError = document.querySelector('[data-file-error]');
|
||||
const elFile = document.querySelector('[data-file-input]');
|
||||
const elInputPreview = document.querySelector('[data-input-preview]');
|
||||
const elPalettePreview = document.querySelector('[data-palette-preview]');
|
||||
const elOutputPreview = document.querySelector('[data-output-preview]');
|
||||
const elPaletteInformation = document.querySelector('[data-palette-information]');
|
||||
const elSourceFromInput = document.querySelector('[data-source-from-input]');
|
||||
const elPaletteAdd = document.querySelector('[data-palette-add]');
|
||||
const elPaletteEntries = document.querySelector('[data-palette-entries]');
|
||||
const elPreviewScale = document.querySelector('[data-indexed-preview-scale]');
|
||||
const elClearPalette = document.querySelector('[data-palette-clear]');
|
||||
const elAppendPalette = document.querySelector('[data-palette-append]');
|
||||
const elOutputError = document.querySelector('[data-output-error]');
|
||||
const elOptimizePalette = document.querySelector('[data-palette-optimize]');
|
||||
const btnBackgroundWhite = document.querySelector('[data-page-bg-white]');
|
||||
const btnBackgroundTransparent = document.querySelector('[data-page-bg-transparent]');
|
||||
const btnBackgroundCheckerboard = document.querySelector('[data-page-bg-checkerboard]');
|
||||
const btnBackgroundMagenta = document.querySelector('[data-page-bg-magenta]');
|
||||
const btnBackgroundBlue = document.querySelector('[data-page-bg-blue]');
|
||||
const btnBackgroundGreen = document.querySelector('[data-page-bg-green]');
|
||||
const btnDownloadPalette = document.querySelector('[data-palette-download]');
|
||||
const btnDownloadImage = document.querySelector('[data-indexed-download]');
|
||||
|
||||
let imageWidth = 0;
|
||||
let imageHeight = 0;
|
||||
let palette = [];// Array of [ r, g, b, a ]
|
||||
let indexedImage = [ ];// Array of indexes
|
||||
|
||||
const nextPowerOfTwo = (x) => {
|
||||
return Math.pow(2, Math.ceil(Math.log2(x)));
|
||||
}
|
||||
|
||||
const sourcePaletteFromImage = (image) => {
|
||||
// Get unique colors
|
||||
const elCanvas = document.createElement('canvas');
|
||||
elCanvas.width = image.width;
|
||||
elCanvas.height = image.height;
|
||||
const ctx = elCanvas.getContext('2d');
|
||||
ctx.drawImage(image, 0, 0);
|
||||
const imageData = ctx.getImageData(0, 0, image.width, image.height);
|
||||
const data = imageData.data;
|
||||
|
||||
const palette = [];
|
||||
for(let i = 0; i < data.length; i += 4) {
|
||||
const color = [ data[i], data[i + 1], data[i + 2], data[i + 3] ];
|
||||
if(!palette.some(c => c[0] === color[0] && c[1] === color[1] && c[2] === color[2] && c[3] === color[3])) {
|
||||
palette.push(color);
|
||||
}
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
const updateOutput = () => {
|
||||
elOutputError.style.display = 'none';
|
||||
|
||||
// Update palette preview
|
||||
const paletteScale = 8;
|
||||
const uniquePalette = palette.filter((color, index) => {
|
||||
if(color[3] === 0) {
|
||||
// Find any other fully transparent pixel.
|
||||
return index === palette.findIndex(c => c[3] === 0);
|
||||
}
|
||||
return index === palette.findIndex(c => c[0] === color[0] && c[1] === color[1] && c[2] === color[2] && c[3] === color[3]);
|
||||
});
|
||||
elPalettePreview.width = uniquePalette.length * paletteScale;
|
||||
elPalettePreview.height = paletteScale;
|
||||
const paletteCtx = elPalettePreview.getContext('2d');
|
||||
uniquePalette.forEach((color, index) => {
|
||||
paletteCtx.fillStyle = `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${color[3] / 255})`;
|
||||
paletteCtx.fillRect(index * paletteScale, 0, paletteScale, paletteScale);
|
||||
});
|
||||
elPaletteInformation.textContent = `Palette contains ${uniquePalette.length} colors (${palette.length - uniquePalette.length} duplicates).`;
|
||||
|
||||
// Update palette entries
|
||||
elPaletteEntries.innerHTML = '';
|
||||
palette.forEach((color, index) => {
|
||||
const entry = document.createElement('div');
|
||||
|
||||
const epar = document.createElement('span');
|
||||
epar.textContent = `Index ${index}`;
|
||||
|
||||
const ecolor = document.createElement('span');
|
||||
ecolor.style.display = 'inline-block';
|
||||
ecolor.style.width = '16px';
|
||||
ecolor.style.height = '16px';
|
||||
ecolor.style.marginLeft = '8px';
|
||||
ecolor.style.backgroundColor = `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${color[3] / 255})`;
|
||||
ecolor.style.border = '1px solid black';
|
||||
|
||||
const header = document.createElement('div');
|
||||
header.appendChild(epar);
|
||||
header.appendChild(ecolor);
|
||||
|
||||
const inputR = document.createElement('input');
|
||||
inputR.type = 'number';
|
||||
inputR.value = color[0];
|
||||
inputR.min = 0;
|
||||
inputR.max = 255;
|
||||
inputR.setAttribute('data-palette-index', index);
|
||||
inputR.setAttribute('data-palette-channel', '0');
|
||||
inputR.addEventListener('change', (event) => {
|
||||
const idx = parseInt(event.target.getAttribute('data-palette-index'));
|
||||
const channel = parseInt(event.target.getAttribute('data-palette-channel'));
|
||||
const value = parseInt(event.target.value);
|
||||
if(isNaN(value) || value < 0 || value > 255) {
|
||||
event.target.value = palette[idx][channel];
|
||||
return;
|
||||
}
|
||||
palette[idx][channel] = value;
|
||||
updateOutput();
|
||||
});
|
||||
|
||||
const inputG = document.createElement('input');
|
||||
inputG.type = 'number';
|
||||
inputG.value = color[1];
|
||||
inputG.min = 0;
|
||||
inputG.max = 255;
|
||||
inputG.setAttribute('data-palette-index', index);
|
||||
inputG.setAttribute('data-palette-channel', '1');
|
||||
inputG.addEventListener('change', (event) => {
|
||||
const idx = parseInt(event.target.getAttribute('data-palette-index'));
|
||||
const channel = parseInt(event.target.getAttribute('data-palette-channel'));
|
||||
const value = parseInt(event.target.value);
|
||||
if(isNaN(value) || value < 0 || value > 255) {
|
||||
event.target.value = palette[idx][channel];
|
||||
return;
|
||||
}
|
||||
palette[idx][channel] = value;
|
||||
updateOutput();
|
||||
});
|
||||
|
||||
const inputB = document.createElement('input');
|
||||
inputB.type = 'number';
|
||||
inputB.value = color[2];
|
||||
inputB.min = 0;
|
||||
inputB.max = 255;
|
||||
inputB.setAttribute('data-palette-index', index);
|
||||
inputB.setAttribute('data-palette-channel', '2');
|
||||
inputB.addEventListener('change', (event) => {
|
||||
const idx = parseInt(event.target.getAttribute('data-palette-index'));
|
||||
const channel = parseInt(event.target.getAttribute('data-palette-channel'));
|
||||
const value = parseInt(event.target.value);
|
||||
if(isNaN(value) || value < 0 || value > 255) {
|
||||
event.target.value = palette[idx][channel];
|
||||
return;
|
||||
}
|
||||
palette[idx][channel] = value;
|
||||
updateOutput();
|
||||
});
|
||||
|
||||
const inputA = document.createElement('input');
|
||||
inputA.type = 'number';
|
||||
inputA.value = color[3];
|
||||
inputA.min = 0;
|
||||
inputA.max = 255;
|
||||
inputA.setAttribute('data-palette-index', index);
|
||||
inputA.setAttribute('data-palette-channel', '3');
|
||||
inputA.addEventListener('change', (event) => {
|
||||
const idx = parseInt(event.target.getAttribute('data-palette-index'));
|
||||
const channel = parseInt(event.target.getAttribute('data-palette-channel'));
|
||||
const value = parseInt(event.target.value);
|
||||
if(isNaN(value) || value < 0 || value > 255) {
|
||||
event.target.value = palette[idx][channel];
|
||||
return;
|
||||
}
|
||||
palette[idx][channel] = value;
|
||||
updateOutput();
|
||||
});
|
||||
|
||||
const colorArea = document.createElement('div');
|
||||
colorArea.style.display = 'inline-block';
|
||||
colorArea.appendChild(inputR);
|
||||
colorArea.appendChild(inputG);
|
||||
colorArea.appendChild(inputB);
|
||||
colorArea.appendChild(inputA);
|
||||
|
||||
const buttonArea = document.createElement('div');
|
||||
buttonArea.style.display = 'inline-block';
|
||||
const btnRemove = document.createElement('button');
|
||||
btnRemove.textContent = '-';
|
||||
btnRemove.setAttribute('data-palette-index', index);
|
||||
btnRemove.addEventListener('click', () => {
|
||||
palette.splice(index, 1);
|
||||
updateOutput();
|
||||
});
|
||||
buttonArea.appendChild(btnRemove);
|
||||
|
||||
const btnUp = document.createElement('button');
|
||||
btnUp.textContent = '↑';
|
||||
btnUp.setAttribute('data-palette-index', index);
|
||||
btnUp.addEventListener('click', () => {
|
||||
if(index === 0) return;
|
||||
const temp = palette[index - 1];
|
||||
palette[index - 1] = palette[index];
|
||||
palette[index] = temp;
|
||||
updateOutput();
|
||||
});
|
||||
buttonArea.appendChild(btnUp);
|
||||
|
||||
const btnDown = document.createElement('button');
|
||||
btnDown.textContent = '↓';
|
||||
btnDown.setAttribute('data-palette-index', index);
|
||||
btnDown.addEventListener('click', () => {
|
||||
if(index === palette.length - 1) return;
|
||||
const temp = palette[index + 1];
|
||||
palette[index + 1] = palette[index];
|
||||
palette[index] = temp;
|
||||
updateOutput();
|
||||
});
|
||||
buttonArea.appendChild(btnDown);
|
||||
|
||||
const footer = document.createElement('div');
|
||||
footer.appendChild(colorArea);
|
||||
footer.appendChild(buttonArea);
|
||||
|
||||
entry.appendChild(header);
|
||||
entry.appendChild(footer);
|
||||
elPaletteEntries.appendChild(entry);
|
||||
});
|
||||
|
||||
// Image ready?
|
||||
if(!imageWidth || !imageHeight) return;
|
||||
|
||||
// Update indexed image preview
|
||||
elOutputPreview.width = imageWidth;
|
||||
elOutputPreview.height = imageHeight;
|
||||
const outputCtx = elOutputPreview.getContext('2d');
|
||||
const outputImageData = outputCtx.createImageData(imageWidth, imageHeight);
|
||||
const outputData = outputImageData.data;
|
||||
indexedImage.forEach((index, i) => {
|
||||
let color;
|
||||
if(palette.length <= index) {
|
||||
elOutputError.textContent = `Indexed image references non-existent palette index ${index}.`;
|
||||
elOutputError.style.display = 'block';
|
||||
color = [0, 0, 0, 0];
|
||||
} else {
|
||||
color = palette[index];
|
||||
}
|
||||
outputData[i * 4] = color[0];
|
||||
outputData[i * 4 + 1] = color[1];
|
||||
outputData[i * 4 + 2] = color[2];
|
||||
outputData[i * 4 + 3] = color[3];
|
||||
});
|
||||
outputCtx.putImageData(outputImageData, 0, 0);
|
||||
|
||||
if(elOutputError.style.display === 'none') {;
|
||||
const unusedPaletteIndexes = palette.map((color, index) => {
|
||||
return indexedImage.includes(index) ? null : index;
|
||||
}).filter(Boolean);
|
||||
if(unusedPaletteIndexes.length > 0) {
|
||||
elOutputError.textContent = `Image does not use palette colors; ${unusedPaletteIndexes.join(', ')}.`;
|
||||
elOutputError.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
// Rescale canvas
|
||||
const scale = parseInt(elPreviewScale.value) || 1;
|
||||
elOutputPreview.style.width = `${imageWidth * scale}px`;
|
||||
elOutputPreview.style.height = `${imageHeight * scale}px`;
|
||||
}
|
||||
|
||||
const onImage = img => {
|
||||
if(!img) return onBadFile('Failed to load image');
|
||||
|
||||
elError.style.display = 'none';
|
||||
imageWidth = img.width;
|
||||
imageHeight = img.height;
|
||||
indexedImage = [];
|
||||
|
||||
// Update input preview
|
||||
elInputPreview.width = imageWidth;
|
||||
elInputPreview.height = imageHeight;
|
||||
const ctx = elInputPreview.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
|
||||
// Source palette from input image
|
||||
palette = sourcePaletteFromImage(img);
|
||||
|
||||
// Index the image
|
||||
const imageData = ctx.getImageData(0, 0, imageWidth, imageHeight);
|
||||
const data = imageData.data;
|
||||
for(let i = 0; i < data.length; i += 4) {
|
||||
const color = [ data[i], data[i + 1], data[i + 2], data[i + 3] ];
|
||||
const colorIndex = palette.findIndex(c => c[0] === color[0] && c[1] === color[1] && c[2] === color[2] && c[3] === color[3]);
|
||||
indexedImage.push(colorIndex);
|
||||
}
|
||||
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
const onPalettizedImage = dataView => {
|
||||
if(!dataView) return onBadFile('Failed to load image');
|
||||
|
||||
// Ensure DPT and ver is 1
|
||||
if(dataView.getUint8(0) !== 0x44 || dataView.getUint8(1) !== 0x50 || dataView.getUint8(2) !== 0x54 || dataView.getUint8(3) !== 0x01) {
|
||||
return onBadFile('Invalid DPT file. Expected header "DPT" and version 1.');
|
||||
}
|
||||
|
||||
// Width and Height
|
||||
elError.style.display = 'none';
|
||||
imageWidth = dataView.getUint32(3);
|
||||
imageHeight = dataView.getUint32(7);
|
||||
|
||||
if(imageWidth <= 0 || imageHeight <= 0) {
|
||||
return onBadFile('Invalid image dimensions in DPT file.');
|
||||
}
|
||||
|
||||
if(dataView.byteLength < 11 + imageWidth * imageHeight) {
|
||||
return onBadFile('DPT file does not contain enough data for the specified dimensions.');
|
||||
}
|
||||
|
||||
const uniqueIndexes = []
|
||||
|
||||
// Image data
|
||||
indexedImage = [];
|
||||
for(let i = 11; i < dataView.byteLength; i++) {
|
||||
const index = dataView.getUint8(i);
|
||||
if(!uniqueIndexes.includes(index)) uniqueIndexes.push(index);
|
||||
indexedImage.push(index);
|
||||
}
|
||||
|
||||
const adhocPalette = [];
|
||||
for(let i = 0; i < uniqueIndexes.length; i++) {
|
||||
const index = uniqueIndexes[i];
|
||||
// Get the most different possible color for this index
|
||||
const color = [
|
||||
(index * 37) % 256,
|
||||
(index * 61) % 256,
|
||||
(index * 97) % 256,
|
||||
255
|
||||
];
|
||||
adhocPalette[index] = color;
|
||||
}
|
||||
|
||||
elInputPreview.width = imageWidth;
|
||||
elInputPreview.height = imageHeight;
|
||||
const ctx = elInputPreview.getContext('2d');
|
||||
const imageData = ctx.createImageData(imageWidth, imageHeight);
|
||||
const data = imageData.data;
|
||||
indexedImage.forEach((index, i) => {
|
||||
const color = adhocPalette[index] || [0, 0, 0, 0];
|
||||
data[i * 4] = color[0];
|
||||
data[i * 4 + 1] = color[1];
|
||||
data[i * 4 + 2] = color[2];
|
||||
data[i * 4 + 3] = color[3];
|
||||
});
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
const onBadFile = err => {
|
||||
elError.textContent = err;
|
||||
elError.style.display = 'block';
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
const onFile = file => {
|
||||
// Reset preview
|
||||
elInputPreview.width = 0;
|
||||
elInputPreview.height = 0;
|
||||
image = null;
|
||||
|
||||
if(!file) {
|
||||
onImage(null);
|
||||
return;
|
||||
}
|
||||
|
||||
// If file is image, load as image.
|
||||
if(file.type.startsWith('image/')) {
|
||||
elError.style.display = 'none';
|
||||
const reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
const img = new Image();
|
||||
img.onload = () => onImage(img);
|
||||
img.onerror = () => onImage(null);
|
||||
img.src = event.target.result;
|
||||
};
|
||||
reader.onerror = () => onImage(null);
|
||||
reader.readAsDataURL(file);
|
||||
return;
|
||||
|
||||
} else if(file.name.endsWith('.dpt')) {
|
||||
elError.style.display = 'none';
|
||||
const reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
const arrayBuffer = event.target.result;
|
||||
const dataView = new DataView(arrayBuffer);
|
||||
onPalettizedImage(dataView);
|
||||
};
|
||||
reader.onerror = () => onPalettizedImage(null);
|
||||
reader.readAsArrayBuffer(file);
|
||||
return;
|
||||
}
|
||||
|
||||
onBadFile('Selected file is not a supported image type.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Listeners
|
||||
btnBackgroundWhite.addEventListener('click', () => {
|
||||
document.body.style.background = 'white';
|
||||
});
|
||||
btnBackgroundTransparent.addEventListener('click', () => {
|
||||
document.body.style.background = 'black';
|
||||
});
|
||||
btnBackgroundCheckerboard.addEventListener('click', () => {
|
||||
document.body.style.background = 'repeating-conic-gradient(#ccc 0% 25%, #eee 0% 50%) 50% / 20px 20px';
|
||||
});
|
||||
btnBackgroundMagenta.addEventListener('click', () => {
|
||||
document.body.style.background = 'magenta';
|
||||
});
|
||||
btnBackgroundBlue.addEventListener('click', () => {
|
||||
document.body.style.background = 'blue';
|
||||
});
|
||||
btnBackgroundGreen.addEventListener('click', () => {
|
||||
document.body.style.background = 'green';
|
||||
});
|
||||
|
||||
elFile.addEventListener('change', (event) => {
|
||||
onFile(event?.target?.files[0]);
|
||||
});
|
||||
elPaletteAdd.addEventListener('click', () => {
|
||||
// Add new random color to palette
|
||||
const newColor = [ Math.floor(Math.random() * 256), Math.floor(Math.random() * 256), Math.floor(Math.random() * 256), 255 ];
|
||||
palette.push(newColor);
|
||||
updateOutput();
|
||||
});
|
||||
elPreviewScale.addEventListener('change', () => {
|
||||
updateOutput();
|
||||
});
|
||||
elClearPalette.addEventListener('click', () => {
|
||||
palette = [];
|
||||
updateOutput();
|
||||
});
|
||||
|
||||
elOptimizePalette.addEventListener('click', () => {
|
||||
// Remove unused colors and duplicates from the palette. Treat A=0 as equal
|
||||
const newPalette = [];
|
||||
const indexMap = {};
|
||||
palette.forEach((color, index) => {
|
||||
// Check if color is already in new palette
|
||||
const existingIndex = newPalette.findIndex(c => {
|
||||
if(c[3] === 0 && color[3] === 0) return true;
|
||||
return c[0] === color[0] && c[1] === color[1] && c[2] === color[2] && c[3] === color[3];
|
||||
});
|
||||
if(existingIndex !== -1) {
|
||||
indexMap[index] = existingIndex;
|
||||
} else {
|
||||
indexMap[index] = newPalette.length;
|
||||
newPalette.push(color);
|
||||
}
|
||||
});
|
||||
|
||||
palette = newPalette;
|
||||
|
||||
updateOutput();
|
||||
});
|
||||
|
||||
elAppendPalette.addEventListener('click', () => {
|
||||
// Open file picker
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.addEventListener('change', (event) => {
|
||||
const file = event.target.files[0];
|
||||
if(!file) return;
|
||||
|
||||
// Accept either images or .dpf files
|
||||
if(file.type.startsWith('image/')) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
const newColors = sourcePaletteFromImage(img);
|
||||
palette = palette.concat(newColors);
|
||||
updateOutput();
|
||||
};
|
||||
img.onerror = () => {
|
||||
alert('Failed to load image for palette appending.');
|
||||
};
|
||||
img.src = event.target.result;
|
||||
};
|
||||
reader.onerror = () => {
|
||||
alert('Failed to load image for palette appending.');
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
return;
|
||||
} else if(file.name.endsWith('.dpf')) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
const arrayBuffer = event.target.result;
|
||||
const dataView = new DataView(arrayBuffer);
|
||||
|
||||
// Validate header
|
||||
if(dataView.getUint8(0) !== 0x44 || dataView.getUint8(1) !== 0x50 || dataView.getUint8(2) !== 0x46) {
|
||||
alert('Invalid DPF file.');
|
||||
return;
|
||||
}
|
||||
|
||||
const colorCount = dataView.getUint32(4);
|
||||
const expectedLength = 4 * colorCount + 8;// 3 DPF, 1 ver, 4 color count
|
||||
if(arrayBuffer.byteLength !== expectedLength) {
|
||||
alert('DPF file size does not match expected color count.');
|
||||
return;
|
||||
}
|
||||
|
||||
let offset = 8;
|
||||
for(let i = 0; i < colorCount; i++) {
|
||||
const r = dataView.getUint8(offset);
|
||||
const g = dataView.getUint8(offset + 1);
|
||||
const b = dataView.getUint8(offset + 2);
|
||||
const a = dataView.getUint8(offset + 3);
|
||||
palette.push([r, g, b, a]);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
updateOutput();
|
||||
};
|
||||
reader.onerror = () => {
|
||||
alert('Failed to load DPF file for palette appending.');
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
return;
|
||||
} else {
|
||||
alert('Unsupported file type for palette appending. Please use an image file.');
|
||||
}
|
||||
});
|
||||
|
||||
input.click();
|
||||
});
|
||||
|
||||
btnDownloadPalette.addEventListener('click', () => {
|
||||
// Create Dusk Palette File (.dpf)
|
||||
const header = new Uint8Array([0x44, 0x50, 0x46, 0x01]); // 'DPF' + version 1 + number of colors (4 bytes)
|
||||
|
||||
const colorCount = palette.length;
|
||||
const colorCountBytes = new Uint8Array(4);
|
||||
colorCountBytes[0] = (colorCount >> 24) & 0xFF;
|
||||
colorCountBytes[1] = (colorCount >> 16) & 0xFF;
|
||||
colorCountBytes[2] = (colorCount >> 8) & 0xFF;
|
||||
colorCountBytes[3] = colorCount & 0xFF;
|
||||
|
||||
// add color data (palette.length * 4 bytes)
|
||||
const colorData = new Uint8Array(palette.length * 4);
|
||||
palette.forEach((color, index) => {
|
||||
colorData[index * 4] = color[0];
|
||||
colorData[index * 4 + 1] = color[1];
|
||||
colorData[index * 4 + 2] = color[2];
|
||||
colorData[index * 4 + 3] = color[3];
|
||||
});
|
||||
|
||||
const blob = new Blob([header, colorCountBytes, colorData], { type: 'application/octet-stream' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'palette.dpf';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
|
||||
btnDownloadImage.addEventListener('click', () => {
|
||||
const header = new Uint8Array([0x44, 0x50, 0x54, 0x01]); // 'DPT' + version 1
|
||||
|
||||
// Width
|
||||
const widthBytes = new Uint8Array(4);
|
||||
widthBytes[0] = (imageWidth >> 24) & 0xFF;
|
||||
widthBytes[1] = (imageWidth >> 16) & 0xFF;
|
||||
widthBytes[2] = (imageWidth >> 8) & 0xFF;
|
||||
widthBytes[3] = imageWidth & 0xFF;
|
||||
|
||||
// Height
|
||||
const heightBytes = new Uint8Array(4);
|
||||
heightBytes[0] = (imageHeight >> 24) & 0xFF;
|
||||
heightBytes[1] = (imageHeight >> 16) & 0xFF;
|
||||
heightBytes[2] = (imageHeight >> 8) & 0xFF;
|
||||
heightBytes[3] = imageHeight & 0xFF;
|
||||
|
||||
// add indexed image data (imageWidth * imageHeight bytes)
|
||||
const imageData = new Uint8Array(indexedImage.length);
|
||||
indexedImage.forEach((index, i) => {
|
||||
imageData[i] = index;
|
||||
});
|
||||
|
||||
const blob = new Blob([header, widthBytes, heightBytes, imageData], { type: 'application/octet-stream' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'indexed_image.dpt';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
|
||||
updateOutput();
|
||||
btnBackgroundCheckerboard.click();
|
||||
</script>
|
||||
</html>
|
||||
@@ -1,7 +1,6 @@
|
||||
import argparse
|
||||
import os
|
||||
import csv
|
||||
from tools.util.type import detectType, stringToCType, typeToCType
|
||||
|
||||
parser = argparse.ArgumentParser(description="Story CSV to .h defines")
|
||||
parser.add_argument("--csv", required=True, help="Path to story CSV file")
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Dusk Tools / Tile Joiner</title>
|
||||
|
||||
<style type="text/css">
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Dusk Tile Joiner</h1>
|
||||
<p>
|
||||
Joins multiple tiles together into a single tileset image. Optimizing and
|
||||
allowing it to work on multiple platforms. Output width and height will
|
||||
always be a power of two. This tool will take a while to process images,
|
||||
since all images need to be loaded into memory.
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<div>
|
||||
<input type="file" data-file-input multiple />
|
||||
</div>
|
||||
<p data-file-error style="color:red;display:none;"></p>
|
||||
<textarea readonly data-input-information rows="10" style="width:500px"></textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Settings</h2>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Preview Background:
|
||||
<button data-page-bg-white>White</button>
|
||||
<button data-page-bg-transparent>Black</button>
|
||||
<button data-page-bg-checkerboard>Checkerboard</button>
|
||||
<button data-page-bg-magenta>Magenta</button>
|
||||
<button data-page-bg-blue>Blue</button>
|
||||
<button data-page-bg-green>Green</button>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Joined Preview</h2>
|
||||
<div>
|
||||
<button data-download>Download Joined Image</button>
|
||||
</div>
|
||||
<canvas data-preview-canvas style="border:1px solid black;"></canvas>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
const elFileInput = document.querySelector('[data-file-input]');
|
||||
const elFileError = document.querySelector('[data-file-error]');
|
||||
const elInputInformation = document.querySelector('[data-input-information]');
|
||||
const elPreviewCanvas = document.querySelector('[data-preview-canvas]');
|
||||
const btnDownload = document.querySelector('[data-download]');
|
||||
const btnBackgroundWhite = document.querySelector('[data-page-bg-white]');
|
||||
const btnBackgroundTransparent = document.querySelector('[data-page-bg-transparent]');
|
||||
const btnBackgroundCheckerboard = document.querySelector('[data-page-bg-checkerboard]');
|
||||
const btnBackgroundMagenta = document.querySelector('[data-page-bg-magenta]');
|
||||
const btnBackgroundBlue = document.querySelector('[data-page-bg-blue]');
|
||||
const btnBackgroundGreen = document.querySelector('[data-page-bg-green]');
|
||||
|
||||
let images = {};
|
||||
|
||||
// Methods
|
||||
const nextPowerOfTwo = n => {
|
||||
if(n <= 0) return 1;
|
||||
return 2 ** Math.ceil(Math.log2(n));
|
||||
}
|
||||
|
||||
const onBadImages = error => {
|
||||
elInputInformation.value = '';
|
||||
elFileError.style.display = 'block';
|
||||
elFileError.textContent = error;
|
||||
}
|
||||
|
||||
const onImages = () => {
|
||||
if(!images || Object.keys(images).length <= 1) {
|
||||
return onBadImages('Please select 2 or more image images.');
|
||||
}
|
||||
|
||||
elFileError.style.display = 'none';
|
||||
|
||||
let strInfo = `Selected ${Object.keys(images).length} images:\n`;
|
||||
for(const [name, img] of Object.entries(images)) {
|
||||
strInfo += `- ${name}: ${img.width}x${img.height}\n`;
|
||||
}
|
||||
elInputInformation.value = strInfo;
|
||||
|
||||
// Determine output width and height to pack images together, must be a
|
||||
// power of two. If all images share a given axis (width/height) and that
|
||||
// axis is already a power of two, use that.
|
||||
const firstWidth = Object.values(images)[0].width;
|
||||
const firstHeight = Object.values(images)[0].height;
|
||||
let allImagesShareWidth = Object.values(images).every(img => img.width === firstWidth);
|
||||
let allImagesShareHeight = Object.values(images).every(img => img.height === firstHeight);
|
||||
|
||||
let outputHeight, outputWidth;
|
||||
|
||||
if(allImagesShareWidth && nextPowerOfTwo(firstWidth) === firstWidth) {
|
||||
outputWidth = firstWidth;
|
||||
outputHeight = nextPowerOfTwo(Object.values(images).reduce((sum, img) => sum + img.height, 0));
|
||||
} else if(allImagesShareHeight && nextPowerOfTwo(firstHeight) === firstHeight) {
|
||||
outputHeight = firstHeight;
|
||||
outputWidth = nextPowerOfTwo(Object.values(images).reduce((sum, img) => sum + img.width, 0));
|
||||
} else {
|
||||
onBadImages('All images must share the same width or height, and that dimension must be a power of two.');
|
||||
}
|
||||
|
||||
// Update preview
|
||||
elPreviewCanvas.width = outputWidth;
|
||||
elPreviewCanvas.height = outputHeight;
|
||||
const ctx = elPreviewCanvas.getContext('2d');
|
||||
let currentX = 0;
|
||||
let currentY = 0;
|
||||
for(const img of Object.values(images)) {
|
||||
ctx.drawImage(img, currentX, currentY);
|
||||
if(allImagesShareWidth) {
|
||||
currentY += img.height;
|
||||
} else {
|
||||
currentX += img.width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const onFiles = async files => {
|
||||
images = {};
|
||||
|
||||
if(!files || files.length <= 1) {
|
||||
return onBadImages('Please select 2 or more image files.');
|
||||
}
|
||||
|
||||
let strError = '';
|
||||
for(const file of files) {
|
||||
if(!file.type.startsWith('image/')) {
|
||||
strError += `File is not an image: ${file.name}\n`;
|
||||
}
|
||||
}
|
||||
if(strError) {
|
||||
return onBadImages(strError);
|
||||
}
|
||||
|
||||
try {
|
||||
const fileImages = await Promise.all(Array.from(files).map(file => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = event => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
images[file.name] = img;
|
||||
resolve();
|
||||
}
|
||||
img.onerror = () => {
|
||||
reject(`Failed to load image: ${file.name}`);
|
||||
}
|
||||
img.src = event.target.result;
|
||||
}
|
||||
reader.onerror = () => {
|
||||
reject(`Failed to read file: ${file.name}`);
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}));
|
||||
} catch(error) {
|
||||
return onBadImages(error);
|
||||
}
|
||||
|
||||
onImages();
|
||||
}
|
||||
|
||||
// Listeners
|
||||
elFileInput.addEventListener('change', event => {
|
||||
onFiles(event?.target?.files);
|
||||
});
|
||||
|
||||
btnBackgroundWhite.addEventListener('click', () => {
|
||||
document.body.style.background = 'white';
|
||||
});
|
||||
btnBackgroundTransparent.addEventListener('click', () => {
|
||||
document.body.style.background = 'black';
|
||||
});
|
||||
btnBackgroundCheckerboard.addEventListener('click', () => {
|
||||
document.body.style.background = 'repeating-conic-gradient(#ccc 0% 25%, #eee 0% 50%) 50% / 20px 20px';
|
||||
});
|
||||
btnBackgroundMagenta.addEventListener('click', () => {
|
||||
document.body.style.background = 'magenta';
|
||||
});
|
||||
btnBackgroundBlue.addEventListener('click', () => {
|
||||
document.body.style.background = 'blue';
|
||||
});
|
||||
btnBackgroundGreen.addEventListener('click', () => {
|
||||
document.body.style.background = 'green';
|
||||
});
|
||||
|
||||
btnDownload.addEventListener('click', () => {
|
||||
if(!images || Object.keys(images).length <= 1) {
|
||||
return onBadImages('Please select 2 or more image files before downloading.');
|
||||
}
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.download = 'joined.png';
|
||||
link.href = elPreviewCanvas.toDataURL();
|
||||
link.click();
|
||||
});
|
||||
|
||||
btnBackgroundCheckerboard.click();
|
||||
</script>
|
||||
</html>
|
||||
@@ -0,0 +1,391 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Dusk Tools / Tile Slicer</title>
|
||||
|
||||
<style type="text/css">
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Dusk Tile Slicer</h1>
|
||||
<p>
|
||||
Tool allows you to take a single image and slice it into individual tiles.
|
||||
This should be done as the first step of optimizing tilesets for your
|
||||
dusk game.
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<div>
|
||||
<input type="file" data-file-input />
|
||||
</div>
|
||||
<p data-file-error style="color:red;display:none;"></p>
|
||||
|
||||
<h2>Input Preview</h2>
|
||||
<canvas data-input-preview style="border:1px solid black;"></canvas>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Settings</h2>
|
||||
<div>
|
||||
<label>
|
||||
Tile Width:
|
||||
<input type="number" value="8" data-tile-width />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Tile Height:
|
||||
<input type="number" value="8" data-tile-height />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Padding:
|
||||
<input type="number" value="0" data-tile-padding />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Margin:
|
||||
<input type="number" value="0" data-tile-margin />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Remove Duplicate Tiles:
|
||||
<input type="checkbox" data-remove-duplicates checked />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Remove Empty Tiles:
|
||||
<input type="checkbox" data-remove-empty checked />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Preview Background:
|
||||
<button data-page-bg-white>White</button>
|
||||
<button data-page-bg-transparent>Black</button>
|
||||
<button data-page-bg-checkerboard>Checkerboard</button>
|
||||
<button data-page-bg-magenta>Magenta</button>
|
||||
<button data-page-bg-blue>Blue</button>
|
||||
<button data-page-bg-green>Green</button>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Sliced Preview</h2>
|
||||
<div data-output-preview></div>
|
||||
<div data-output-hover></div>
|
||||
<textarea readonly data-output-information rows="10" style="width:500px"></textarea>
|
||||
<div>
|
||||
<button data-download-archive>Download All Tiles</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
const elError = document.querySelector('[data-file-error]');
|
||||
const elFile = document.querySelector('[data-file-input]');
|
||||
const elInputPreview = document.querySelector('[data-input-preview]');
|
||||
const elOutputPreview = document.querySelector('[data-output-preview]');
|
||||
const elTileWidth = document.querySelector('[data-tile-width]');
|
||||
const elTileHeight = document.querySelector('[data-tile-height]');
|
||||
const elTilePadding = document.querySelector('[data-tile-padding]');
|
||||
const elTileMargin = document.querySelector('[data-tile-margin]');
|
||||
const elRemoveDuplicates = document.querySelector('[data-remove-duplicates]');
|
||||
const elRemoveEmpty = document.querySelector('[data-remove-empty]');
|
||||
const elOutputInformation = document.querySelector('[data-output-information]');
|
||||
const btnBackgroundWhite = document.querySelector('[data-page-bg-white]');
|
||||
const btnBackgroundTransparent = document.querySelector('[data-page-bg-transparent]');
|
||||
const btnBackgroundCheckerboard = document.querySelector('[data-page-bg-checkerboard]');
|
||||
const btnBackgroundMagenta = document.querySelector('[data-page-bg-magenta]');
|
||||
const btnBackgroundBlue = document.querySelector('[data-page-bg-blue]');
|
||||
const btnBackgroundGreen = document.querySelector('[data-page-bg-green]');
|
||||
const btnDownloadTiles = document.querySelector('[data-download-archive]');
|
||||
|
||||
let image = null;
|
||||
let tileCanvases = [];
|
||||
|
||||
// Values updated during processing
|
||||
let cols, rows;
|
||||
let tileWidth, tileHeight;
|
||||
let tilePadding, tileMargin;
|
||||
let emptyTiles, duplicateTiles;
|
||||
let hoveredTileX = -1, hoveredTileY = -1;
|
||||
let tileStatus = {};
|
||||
|
||||
const updateOutputInformation = () => {
|
||||
if(!image) {
|
||||
elOutputInformation.value = 'No image loaded';
|
||||
return;
|
||||
}
|
||||
|
||||
elOutputInformation.value = [
|
||||
`Input Tile Count: ${cols * rows}`,
|
||||
`Output Tile Count: ${tileCanvases.length}`,
|
||||
elRemoveEmpty.checked ? `Empty Tiles Removed: ${emptyTiles}` : null,
|
||||
elRemoveDuplicates.checked ? `Duplicate Tiles Removed: ${duplicateTiles}` : null,
|
||||
hoveredTileX >= 0 && hoveredTileY >= 0 ? `Hovered tile: (${hoveredTileX}, ${hoveredTileY}) (Index ${hoveredTileX + hoveredTileY * cols})` : null,
|
||||
tileStatus[hoveredTileY * cols + hoveredTileX] || null
|
||||
].filter(Boolean).join('\n');
|
||||
|
||||
elOutputPreview.querySelectorAll('canvas').forEach(canvas => {
|
||||
const x = parseInt(canvas.getAttribute('data-tile-x'), 10);
|
||||
const y = parseInt(canvas.getAttribute('data-tile-y'), 10);
|
||||
const isHovered = x === hoveredTileX && y === hoveredTileY;
|
||||
|
||||
canvas.style.border = `1px solid ${isHovered ? 'red' : 'black'}`;
|
||||
});
|
||||
}
|
||||
|
||||
const updateOutput = () => {
|
||||
// Clear previous output
|
||||
elOutputPreview.innerHTML = '';
|
||||
tileCanvases = [];
|
||||
btnDownloadTiles.disabled = true;
|
||||
hoveredTileX = -1;
|
||||
hoveredTileY = -1;
|
||||
|
||||
// Image ready?
|
||||
if(!image) {
|
||||
updateOutputInformation();
|
||||
return;
|
||||
}
|
||||
|
||||
// For each tile, create a canvas and draw the tile on it
|
||||
tileWidth = parseInt(elTileWidth.value, 10);
|
||||
tileHeight = parseInt(elTileHeight.value, 10);
|
||||
tilePadding = parseInt(elTilePadding.value, 10);
|
||||
tileMargin = parseInt(elTileMargin.value, 10);
|
||||
cols = Math.floor((image.width - tileMargin * 2 + tilePadding) / (tileWidth + tilePadding));
|
||||
rows = Math.floor((image.height - tileMargin * 2 + tilePadding) / (tileHeight + tilePadding));
|
||||
|
||||
if(isNaN(cols) || isNaN(rows) || cols <= 0 || rows <= 0) {
|
||||
elError.textContent = 'Invalid tile settings for the given image';
|
||||
elError.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
emptyTiles = 0;
|
||||
duplicateTiles = 0;
|
||||
oldIndexToNewIndex = {};
|
||||
tileStatus = {};
|
||||
for(let y = 0; y < rows; y++) {
|
||||
for(let x = 0; x < cols; x++) {
|
||||
const tileCanvas = document.createElement('canvas');
|
||||
tileCanvas.width = tileWidth;
|
||||
tileCanvas.height = tileHeight;
|
||||
const ctx = tileCanvas.getContext('2d');
|
||||
ctx.drawImage(
|
||||
image,
|
||||
tileMargin + x * (tileWidth + tilePadding),
|
||||
tileMargin + y * (tileHeight + tilePadding),
|
||||
tileWidth,
|
||||
tileHeight,
|
||||
0,
|
||||
0,
|
||||
tileWidth,
|
||||
tileHeight
|
||||
);
|
||||
tileCanvas.setAttribute('data-tile-x', x);
|
||||
tileCanvas.setAttribute('data-tile-y', y);
|
||||
|
||||
// Empty check.
|
||||
if(elRemoveEmpty.checked) {
|
||||
const imageData = ctx.getImageData(0, 0, tileWidth, tileHeight);
|
||||
const isEmpty = !imageData.data.some(channel => channel !== 0);
|
||||
if(isEmpty) {
|
||||
tileStatus[y * cols + x] = 'Removed (Empty)';
|
||||
emptyTiles++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(elRemoveDuplicates.checked) {
|
||||
const tileDataURL = tileCanvas.toDataURL();
|
||||
const duplicateIndex = tileCanvases.findIndex(canvas => canvas.toDataURL() === tileDataURL);
|
||||
if(duplicateIndex !== -1) {
|
||||
tileStatus[y * cols + x] = `Removed (Duplicate of ${duplicateIndex})`;
|
||||
duplicateTiles++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
tileCanvases.push(tileCanvas);
|
||||
elOutputPreview.appendChild(tileCanvas);
|
||||
}
|
||||
}
|
||||
|
||||
btnDownloadTiles.disabled = false;
|
||||
updateOutputInformation();
|
||||
}
|
||||
|
||||
const onImage = img => {
|
||||
elError.style.display = 'none';
|
||||
image = img;
|
||||
|
||||
// Update input preview
|
||||
elInputPreview.width = img.width;
|
||||
elInputPreview.height = img.height;
|
||||
const ctx = elInputPreview.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
const onBadFile = err => {
|
||||
elError.textContent = err;
|
||||
elError.style.display = 'block';
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
const onFile = file => {
|
||||
// Reset preview
|
||||
elInputPreview.width = 0;
|
||||
elInputPreview.height = 0;
|
||||
image = null;
|
||||
|
||||
if(!file) {
|
||||
onBadFile('No file selected');
|
||||
return;
|
||||
}
|
||||
|
||||
if(!file.type.startsWith('image/')) {
|
||||
onBadFile('Selected file is not an image');
|
||||
return;
|
||||
}
|
||||
|
||||
elError.style.display = 'none';
|
||||
const reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
const img = new Image();
|
||||
img.onload = () => onImage(img);
|
||||
img.onerror = () => onBadFile('Failed to load image');
|
||||
img.src = event.target.result;
|
||||
};
|
||||
reader.onerror = () => onBadFile('Failed to read file');
|
||||
reader.readAsDataURL(file);
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
// Listeners
|
||||
elFile.addEventListener('change', (event) => {
|
||||
onFile(event?.target?.files[0]);
|
||||
});
|
||||
elTileWidth.addEventListener('input', updateOutput);
|
||||
elTileHeight.addEventListener('input', updateOutput);
|
||||
elTilePadding.addEventListener('input', updateOutput);
|
||||
elTileMargin.addEventListener('input', updateOutput);
|
||||
elRemoveEmpty.addEventListener('change', updateOutput);
|
||||
elRemoveDuplicates.addEventListener('change', updateOutput);
|
||||
|
||||
btnBackgroundWhite.addEventListener('click', () => {
|
||||
document.body.style.background = 'white';
|
||||
});
|
||||
btnBackgroundTransparent.addEventListener('click', () => {
|
||||
document.body.style.background = 'black';
|
||||
});
|
||||
btnBackgroundCheckerboard.addEventListener('click', () => {
|
||||
document.body.style.background = 'repeating-conic-gradient(#ccc 0% 25%, #eee 0% 50%) 50% / 20px 20px';
|
||||
});
|
||||
btnBackgroundMagenta.addEventListener('click', () => {
|
||||
document.body.style.background = 'magenta';
|
||||
});
|
||||
btnBackgroundBlue.addEventListener('click', () => {
|
||||
document.body.style.background = 'blue';
|
||||
});
|
||||
btnBackgroundGreen.addEventListener('click', () => {
|
||||
document.body.style.background = 'green';
|
||||
});
|
||||
|
||||
btnDownloadTiles.addEventListener('click', () => {
|
||||
if(tileCanvases.length === 0) {
|
||||
alert('No tiles to download');
|
||||
return;
|
||||
}
|
||||
|
||||
const zip = new JSZip();
|
||||
tileCanvases.forEach((canvas, index) => {
|
||||
const dataURL = canvas.toDataURL('image/png');
|
||||
const base64Data = dataURL.split(',')[1];
|
||||
zip.file(`tile_${index}.png`, base64Data, {base64: true});
|
||||
});
|
||||
|
||||
zip.generateAsync({type: 'blob'}).then(content => {
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(content);
|
||||
link.download = 'tiles.zip';
|
||||
link.click();
|
||||
});
|
||||
});
|
||||
|
||||
// On mouse move of input preview
|
||||
elInputPreview.addEventListener('mousemove', (event) => {
|
||||
if(!image || elError.style.display !== 'none') return;
|
||||
|
||||
const rect = elInputPreview.getBoundingClientRect();
|
||||
const x = event.clientX - rect.left;
|
||||
const y = event.clientY - rect.top;
|
||||
|
||||
hoveredTileX = Math.floor((x - tileMargin) / (tileWidth + tilePadding));
|
||||
hoveredTileY = Math.floor((y - tileMargin) / (tileHeight + tilePadding));
|
||||
|
||||
updateOutputInformation();
|
||||
});
|
||||
elInputPreview.addEventListener('mouseleave', () => {
|
||||
hoveredTileX = -1;
|
||||
hoveredTileY = -1;
|
||||
updateOutputInformation();
|
||||
});
|
||||
|
||||
updateOutput();
|
||||
btnBackgroundCheckerboard.click();
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
/*!
|
||||
JSZip v3.10.1 - A JavaScript class for generating and reading zip files
|
||||
<http://stuartk.com/jszip>
|
||||
|
||||
(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
|
||||
Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/main/LICENSE.markdown.
|
||||
|
||||
JSZip uses the library pako released under the MIT license :
|
||||
https://github.com/nodeca/pako/blob/main/LICENSE
|
||||
*/
|
||||
|
||||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JSZip=e()}}(function(){return function s(a,o,h){function u(r,e){if(!o[r]){if(!a[r]){var t="function"==typeof require&&require;if(!e&&t)return t(r,!0);if(l)return l(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var i=o[r]={exports:{}};a[r][0].call(i.exports,function(e){var t=a[r][1][e];return u(t||e)},i,i.exports,s,a,o,h)}return o[r].exports}for(var l="function"==typeof require&&require,e=0;e<h.length;e++)u(h[e]);return u}({1:[function(e,t,r){"use strict";var d=e("./utils"),c=e("./support"),p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(e){for(var t,r,n,i,s,a,o,h=[],u=0,l=e.length,f=l,c="string"!==d.getTypeOf(e);u<e.length;)f=l-u,n=c?(t=e[u++],r=u<l?e[u++]:0,u<l?e[u++]:0):(t=e.charCodeAt(u++),r=u<l?e.charCodeAt(u++):0,u<l?e.charCodeAt(u++):0),i=t>>2,s=(3&t)<<4|r>>4,a=1<f?(15&r)<<2|n>>6:64,o=2<f?63&n:64,h.push(p.charAt(i)+p.charAt(s)+p.charAt(a)+p.charAt(o));return h.join("")},r.decode=function(e){var t,r,n,i,s,a,o=0,h=0,u="data:";if(e.substr(0,u.length)===u)throw new Error("Invalid base64 input, it looks like a data url.");var l,f=3*(e=e.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(e.charAt(e.length-1)===p.charAt(64)&&f--,e.charAt(e.length-2)===p.charAt(64)&&f--,f%1!=0)throw new Error("Invalid base64 input, bad content length.");for(l=c.uint8array?new Uint8Array(0|f):new Array(0|f);o<e.length;)t=p.indexOf(e.charAt(o++))<<2|(i=p.indexOf(e.charAt(o++)))>>4,r=(15&i)<<4|(s=p.indexOf(e.charAt(o++)))>>2,n=(3&s)<<6|(a=p.indexOf(e.charAt(o++))),l[h++]=t,64!==s&&(l[h++]=r),64!==a&&(l[h++]=n);return l}},{"./support":30,"./utils":32}],2:[function(e,t,r){"use strict";var n=e("./external"),i=e("./stream/DataWorker"),s=e("./stream/Crc32Probe"),a=e("./stream/DataLengthProbe");function o(e,t,r,n,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=r,this.compression=n,this.compressedContent=i}o.prototype={getContentWorker:function(){var e=new i(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")),t=this;return e.on("end",function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),e},getCompressedWorker:function(){return new i(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},o.createWorkerFrom=function(e,t,r){return e.pipe(new s).pipe(new a("uncompressedSize")).pipe(t.compressWorker(r)).pipe(new a("compressedSize")).withStreamInfo("compression",t)},t.exports=o},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,r){"use strict";var n=e("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new n("STORE compression")},uncompressWorker:function(){return new n("STORE decompression")}},r.DEFLATE=e("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,r){"use strict";var n=e("./utils");var o=function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t}();t.exports=function(e,t){return void 0!==e&&e.length?"string"!==n.getTypeOf(e)?function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a<s;a++)e=e>>>8^i[255&(e^t[a])];return-1^e}(0|t,e,e.length,0):function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a<s;a++)e=e>>>8^i[255&(e^t.charCodeAt(a))];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,r){"use strict";r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(e,t,r){"use strict";var n=null;n="undefined"!=typeof Promise?Promise:e("lie"),t.exports={Promise:n}},{lie:37}],7:[function(e,t,r){"use strict";var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,i=e("pako"),s=e("./utils"),a=e("./stream/GenericWorker"),o=n?"uint8array":"array";function h(e,t){a.call(this,"FlateWorker/"+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}r.magic="\b\0",s.inherits(h,a),h.prototype.processChunk=function(e){this.meta=e.meta,null===this._pako&&this._createPako(),this._pako.push(s.transformTo(o,e.data),!1)},h.prototype.flush=function(){a.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},h.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this._pako=null},h.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=functLine truncated
|
||||
name:e,dir:i,date:s,comment:t.comment||"",unixPermissions:t.unixPermissions,dosPermissions:t.dosPermissions}).pipe(o)}),o.entriesCount=h}catch(e){o.error(e)}return o}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(e,t,r){"use strict";function n(){if(!(this instanceof n))return new n;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var e=new n;for(var t in this)"function"!=typeof this[t]&&(e[t]=this[t]);return e}}(n.prototype=e("./object")).loadAsync=e("./load"),n.support=e("./support"),n.defaults=e("./defaults"),n.version="3.10.1",n.loadAsync=function(e,t){return(new n).loadAsync(e,t)},n.external=e("./external"),t.exports=n},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(e,t,r){"use strict";var u=e("./utils"),i=e("./external"),n=e("./utf8"),s=e("./zipEntries"),a=e("./stream/Crc32Probe"),l=e("./nodejsUtils");function f(n){return new i.Promise(function(e,t){var r=n.decompressed.getContentWorker().pipe(new a);r.on("error",function(e){t(e)}).on("end",function(){r.streamInfo.crc32!==n.decompressed.crc32?t(new Error("Corrupted zip : CRC32 mismatch")):e()}).resume()})}t.exports=function(e,o){var h=this;return o=u.extend(o||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:n.utf8decode}),l.isNode&&l.isStream(e)?i.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):u.prepareContent("the loaded zip file",e,!0,o.optimizedBinaryString,o.base64).then(function(e){var t=new s(o);return t.load(e),t}).then(function(e){var t=[i.Promise.resolve(e)],r=e.files;if(o.checkCRC32)for(var n=0;n<r.length;n++)t.push(f(r[n]));return i.Promise.all(t)}).then(function(e){for(var t=e.shift(),r=t.files,n=0;n<r.length;n++){var i=r[n],s=i.fileNameStr,a=u.resolve(i.fileNameStr);h.file(a,i.decompressed,{binary:!0,optimizedBinaryString:!0,date:i.date,dir:i.dir,comment:i.fileCommentStr.length?i.fileCommentStr:null,unixPermissions:i.unixPermissions,dosPermissions:i.dosPermissions,createFolders:o.createFolders}),i.dir||(h.file(a).unsafeOriginalName=s)}return t.zipComment.length&&(h.comment=t.zipComment),h})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(e,t,r){"use strict";var n=e("../utils"),i=e("../stream/GenericWorker");function s(e,t){i.call(this,"Nodejs stream input adapter for "+e),this._upstreamEnded=!1,this._bindStream(t)}n.inherits(s,i),s.prototype._bindStream=function(e){var t=this;(this._stream=e).pause(),e.on("data",function(e){t.push({data:e,meta:{percent:0}})}).on("error",function(e){t.isPaused?this.generatedError=e:t.error(e)}).on("end",function(){t.isPaused?t._upstreamEnded=!0:t.end()})},s.prototype.pause=function(){return!!i.prototype.pause.call(this)&&(this._stream.pause(),!0)},s.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},t.exports=s},{"../stream/GenericWorker":28,"../utils":32}],13:[function(e,t,r){"use strict";var i=e("readable-stream").Readable;function n(e,t,r){i.call(this,t),this._helper=e;var n=this;e.on("data",function(e,t){n.push(e)||n._helper.pause(),r&&r(t)}).on("error",function(e){n.emit("error",e)}).on("end",function(){n.push(null)})}e("../utils").inherits(n,i),n.prototype._read=function(){this._helper.resume()},t.exports=n},{"../utils":32,"readable-stream":16}],14:[function(e,t,r){"use strict";t.exports={isNode:"undefined"!=typeof Buffer,newBufferFrom:function(e,t){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(e,t);if("number"==typeof e)throw new Error('The "data" argument must not be a number');return new Buffer(e,t)},allocBuffer:function(e){if(Buffer.alloc)return Buffer.alloc(e);var t=new Buffer(e);return t.fill(0),t},isBuffer:function(e){return Buffer.isBuffer(e)},isStream:function(e){return e&&"function"==typeof e.on&&"function"==typeof e.pause&&"function"==typeof e.resume}}},{}],15:[function(e,t,r){"use strict";function s(e,t,r){var n,i=u.getTypeOf(t),s=u.extend(r||{},f);s.date=s.date||new Date,null!==s.compression&&(s.compression=s.compression.toUpperCase()),"string"==typeof s.unixPermissions&&(s.unixPermissions=parseInt(s.unixPermissions,8)),s.unixPermissions&&16384&s.unixPermissions&&(s.dir=!0),s.dosPermissions&&16&s.dosPermissions&&(s.dir=!0),s.dir&&(e=g(e)),s.createFolders&&(n=_(e))&&b.call(this,n,!0);var a="string"===i&&!1===s.binary&&!1===s.base64;r&&void 0!==r.binary||(s.binary=!a),(t instanceof c&&0===t.uncompressedSize||s.dir||!t||0===t.length)&&(s.base64=!1,s.binary=!0,t="",s.compression="STORE",i="string");var o=null;o=t instanceof c||t instanceof l?t:p.isNode&&p.isStream(t)?new m(e,t):u.prepareContent(e,t,s.binary,s.optimizedBinaryString,s.base64);var h=new d(e,o,s);this.files[e]=h}var i=e("./utf8"),u=e("./utils"),l=e("./stream/GenericWorker"),aLine truncated
|
||||
,t.exports=i},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,r){"use strict";var n=e("./DataReader");function i(e){n.call(this,e)}e("../utils").inherits(i,n),i.prototype.byteAt=function(e){return this.data.charCodeAt(this.zero+e)},i.prototype.lastIndexOfSignature=function(e){return this.data.lastIndexOf(e)-this.zero},i.prototype.readAndCheckSignature=function(e){return e===this.readData(4)},i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./DataReader":18}],21:[function(e,t,r){"use strict";var n=e("./ArrayReader");function i(e){n.call(this,e)}e("../utils").inherits(i,n),i.prototype.readData=function(e){if(this.checkOffset(e),0===e)return new Uint8Array(0);var t=this.data.subarray(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,r){"use strict";var n=e("../utils"),i=e("../support"),s=e("./ArrayReader"),a=e("./StringReader"),o=e("./NodeBufferReader"),h=e("./Uint8ArrayReader");t.exports=function(e){var t=n.getTypeOf(e);return n.checkSupport(t),"string"!==t||i.uint8array?"nodebuffer"===t?new o(e):i.uint8array?new h(n.transformTo("uint8array",e)):new s(n.transformTo("array",e)):new a(e)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,r){"use strict";r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\b"},{}],24:[function(e,t,r){"use strict";var n=e("./GenericWorker"),i=e("../utils");function s(e){n.call(this,"ConvertWorker to "+e),this.destType=e}i.inherits(s,n),s.prototype.processChunk=function(e){this.push({data:i.transformTo(this.destType,e.data),meta:e.meta})},t.exports=s},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,r){"use strict";var n=e("./GenericWorker"),i=e("../crc32");function s(){n.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}e("../utils").inherits(s,n),s.prototype.processChunk=function(e){this.streamInfo.crc32=i(e.data,this.streamInfo.crc32||0),this.push(e)},t.exports=s},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,r){"use strict";var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataLengthProbe for "+e),this.propName=e,this.withStreamInfo(e,0)}n.inherits(s,i),s.prototype.processChunk=function(e){if(e){var t=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=t+e.data.length}i.prototype.processChunk.call(this,e)},t.exports=s},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,r){"use strict";var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataWorker");var t=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,e.then(function(e){t.dataIsReady=!0,t.data=e,t.max=e&&e.length||0,t.type=n.getTypeOf(e),t.isPaused||t._tickAndRepeat()},function(e){t.error(e)})}n.inherits(s,i),s.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this.data=null},s.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,n.delay(this._tickAndRepeat,[],this)),!0)},s.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(n.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},s.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var e=null,t=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":e=this.data.substring(this.index,t);break;case"uint8array":e=this.data.subarray(this.index,t);break;case"array":case"nodebuffer":e=this.data.slice(this.index,t)}return this.index=t,this.push({data:e,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=s},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,r){"use strict";function n(e){this.name=e||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}n.prototype={push:function(e){this.emit("data",e)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(e){this.emit("error",e)}return!0},error:function(e){return!this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit("error",e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(e,t){if(this._listeners[e])for(var r=0;r<this._listeners[e].length;r++)this._listeners[e][r].call(this,t)},pipe:function(e){return e.Line truncated
|
||||
Array(2*s);for(t=r=0;t<s;)if((n=e[t++])<128)a[r++]=n;else if(4<(i=u[n]))a[r++]=65533,t+=i-1;else{for(n&=2===i?31:3===i?15:7;1<i&&t<s;)n=n<<6|63&e[t++],i--;1<i?a[r++]=65533:n<65536?a[r++]=n:(n-=65536,a[r++]=55296|n>>10&1023,a[r++]=56320|1023&n)}return a.length!==r&&(a.subarray?a=a.subarray(0,r):a.length=r),o.applyFromCharCode(a)}(e=o.transformTo(h.uint8array?"uint8array":"array",e))},o.inherits(a,n),a.prototype.processChunk=function(e){var t=o.transformTo(h.uint8array?"uint8array":"array",e.data);if(this.leftOver&&this.leftOver.length){if(h.uint8array){var r=t;(t=new Uint8Array(r.length+this.leftOver.length)).set(this.leftOver,0),t.set(r,this.leftOver.length)}else t=this.leftOver.concat(t);this.leftOver=null}var n=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t}(t),i=t;n!==t.length&&(h.uint8array?(i=t.subarray(0,n),this.leftOver=t.subarray(n,t.length)):(i=t.slice(0,n),this.leftOver=t.slice(n,t.length))),this.push({data:s.utf8decode(i),meta:e.meta})},a.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:s.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},s.Utf8DecodeWorker=a,o.inherits(l,n),l.prototype.processChunk=function(e){this.push({data:s.utf8encode(e.data),meta:e.meta})},s.Utf8EncodeWorker=l},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,a){"use strict";var o=e("./support"),h=e("./base64"),r=e("./nodejsUtils"),u=e("./external");function n(e){return e}function l(e,t){for(var r=0;r<e.length;++r)t[r]=255&e.charCodeAt(r);return t}e("setimmediate"),a.newBlob=function(t,r){a.checkSupport("blob");try{return new Blob([t],{type:r})}catch(e){try{var n=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return n.append(t),n.getBlob(r)}catch(e){throw new Error("Bug : can't construct the Blob.")}}};var i={stringifyByChunk:function(e,t,r){var n=[],i=0,s=e.length;if(s<=r)return String.fromCharCode.apply(null,e);for(;i<s;)"array"===t||"nodebuffer"===t?n.push(String.fromCharCode.apply(null,e.slice(i,Math.min(i+r,s)))):n.push(String.fromCharCode.apply(null,e.subarray(i,Math.min(i+r,s)))),i+=r;return n.join("")},stringifyByChar:function(e){for(var t="",r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},applyCanBeUsed:{uint8array:function(){try{return o.uint8array&&1===String.fromCharCode.apply(null,new Uint8Array(1)).length}catch(e){return!1}}(),nodebuffer:function(){try{return o.nodebuffer&&1===String.fromCharCode.apply(null,r.allocBuffer(1)).length}catch(e){return!1}}()}};function s(e){var t=65536,r=a.getTypeOf(e),n=!0;if("uint8array"===r?n=i.applyCanBeUsed.uint8array:"nodebuffer"===r&&(n=i.applyCanBeUsed.nodebuffer),n)for(;1<t;)try{return i.stringifyByChunk(e,r,t)}catch(e){t=Math.floor(t/2)}return i.stringifyByChar(e)}function f(e,t){for(var r=0;r<e.length;r++)t[r]=e[r];return t}a.applyFromCharCode=s;var c={};c.string={string:n,array:function(e){return l(e,new Array(e.length))},arraybuffer:function(e){return c.string.uint8array(e).buffer},uint8array:function(e){return l(e,new Uint8Array(e.length))},nodebuffer:function(e){return l(e,r.allocBuffer(e.length))}},c.array={string:s,array:n,arraybuffer:function(e){return new Uint8Array(e).buffer},uint8array:function(e){return new Uint8Array(e)},nodebuffer:function(e){return r.newBufferFrom(e)}},c.arraybuffer={string:function(e){return s(new Uint8Array(e))},array:function(e){return f(new Uint8Array(e),new Array(e.byteLength))},arraybuffer:n,uint8array:function(e){return new Uint8Array(e)},nodebuffer:function(e){return r.newBufferFrom(new Uint8Array(e))}},c.uint8array={string:s,array:function(e){return f(e,new Array(e.length))},arraybuffer:function(e){return e.buffer},uint8array:n,nodebuffer:function(e){return r.newBufferFrom(e)}},c.nodebuffer={string:s,array:function(e){return f(e,new Array(e.length))},arraybuffer:function(e){return c.nodebuffer.uint8array(e).buffer},uint8array:function(e){return f(e,new Uint8Array(e.length))},nodebuffer:n},a.transformTo=function(e,t){if(t=t||"",!e)return t;a.checkSupport(e);var r=a.getTypeOf(t);return c[r][e](t)},a.resolve=function(e){for(var t=e.split("/"),r=[],n=0;n<t.length;n++){var i=t[n];"."===i||""===i&&0!==n&&n!==t.length-1||(".."===i?r.pop():r.push(i))}return r.join("/")},a.getTypeOf=function(e){return"string"==typeof e?"string":"[object Array]"===Object.prototype.toString.call(e)?"array":o.nodebuffer&&r.isBuffer(e)?"nodebuffer":o.uint8array&&e instanceof Uint8Array?"uint8array":o.arraybuffer&&e instanceof ArrayBuffer?"arraybuffer":void 0},a.checkSupport=function(e){if(!o[e.toLowerCase()])throw new Error(e+" is not supported by this platform")},a.MAX_VALUE_16BITS=65535,a.MAX_VALUE_32BITS=-1,a.pretty=function(e){var t,r,n="";for(r=0;r<(e||"").length;r++)n+="\\x"+((t=e.charCodeAt(r))<16?"0":"")+t.toString(16).toUpperCase();return n},a.delay=function(e,t,r){setImmediate(function(){e.apply(r||null,t||[])})},a.inherits=functiLine truncated
|
||||
relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var r=this.centralDirOffset+this.centralDirSize;this.zip64&&(r+=20,r+=12+this.zip64EndOfCentralSize);var n=t-r;if(0<n)this.isSignature(t,s.CENTRAL_FILE_HEADER)||(this.reader.zero=n);else if(n<0)throw new Error("Corrupted zip: missing "+Math.abs(n)+" bytes.")},prepareReader:function(e){this.reader=n(e)},load:function(e){this.prepareReader(e),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},t.exports=h},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(e,t,r){"use strict";var n=e("./reader/readerFor"),s=e("./utils"),i=e("./compressedObject"),a=e("./crc32"),o=e("./utf8"),h=e("./compressions"),u=e("./support");function l(e,t){this.options=e,this.loadOptions=t}l.prototype={isEncrypted:function(){return 1==(1&this.bitFlag)},useUTF8:function(){return 2048==(2048&this.bitFlag)},readLocalPart:function(e){var t,r;if(e.skip(22),this.fileNameLength=e.readInt(2),r=e.readInt(2),this.fileName=e.readData(this.fileNameLength),e.skip(r),-1===this.compressedSize||-1===this.uncompressedSize)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if(null===(t=function(e){for(var t in h)if(Object.prototype.hasOwnProperty.call(h,t)&&h[t].magic===e)return h[t];return null}(this.compressionMethod)))throw new Error("Corrupted zip : compression "+s.pretty(this.compressionMethod)+" unknown (inner file : "+s.transformTo("string",this.fileName)+")");this.decompressed=new i(this.compressedSize,this.uncompressedSize,this.crc32,t,e.readData(this.compressedSize))},readCentralPart:function(e){this.versionMadeBy=e.readInt(2),e.skip(2),this.bitFlag=e.readInt(2),this.compressionMethod=e.readString(2),this.date=e.readDate(),this.crc32=e.readInt(4),this.compressedSize=e.readInt(4),this.uncompressedSize=e.readInt(4);var t=e.readInt(2);if(this.extraFieldsLength=e.readInt(2),this.fileCommentLength=e.readInt(2),this.diskNumberStart=e.readInt(2),this.internalFileAttributes=e.readInt(2),this.externalFileAttributes=e.readInt(4),this.localHeaderOffset=e.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");e.skip(t),this.readExtraFields(e),this.parseZIP64ExtraField(e),this.fileComment=e.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var e=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),0==e&&(this.dosPermissions=63&this.externalFileAttributes),3==e&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var e=n(this.extraFields[1].value);this.uncompressedSize===s.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===s.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===s.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===s.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4))}},readExtraFields:function(e){var t,r,n,i=e.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});e.index+4<i;)t=e.readInt(2),r=e.readInt(2),n=e.readData(r),this.extraFields[t]={id:t,length:r,value:n};e.setIndex(i)},handleUTF8:function(){var e=u.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=o.utf8decode(this.fileName),this.fileCommentStr=o.utf8decode(this.fileComment);else{var t=this.findExtraFieldUnicodePath();if(null!==t)this.fileNameStr=t;else{var r=s.transformTo(e,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(r)}var n=this.findExtraFieldUnicodeComment();if(null!==n)this.fileCommentStr=n;else{var i=s.transformTo(e,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(i)}}},findExtraFieldUnicodePath:function(){var e=this.extraFields[28789];if(e){var t=n(e.value);return 1!==t.readInt(1)?null:a(this.fileName)!==t.readInt(4)?null:o.utf8decode(t.readData(e.length-5))}return null},findExtraFieldUnicodeComment:function(){var e=this.extraFields[25461];if(e){var t=n(e.value);return 1!==t.readInt(1)?null:a(this.fileComment)!==t.readInt(4)?null:o.utf8decode(t.readData(e.length-5))}return null}},t.exports=l},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(e,t,r){"use strict";function n(e,t,r){this.name=e,this.dir=r.dir,this.date=r.date,this.comment=r.comment,this.unixPermissions=r.unixPermissions,this.dosPermissions=r.dosPermissions,this._data=t,this._dataBinary=r.binary,this.options={compression:r.compression,compressionOptions:r.compressionOptions}}var s=e("./stream/StreamHelper"),i=e("./stream/DataWoLine truncated
|
||||
0,l.resolve(o,s))},function(e){i||(i=!0,l.reject(o,e))})}},o.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var r=e.length,n=!1;if(!r)return this.resolve([]);var i=-1,s=new this(u);for(;++i<r;)a=e[i],t.resolve(a).then(function(e){n||(n=!0,l.resolve(s,e))},function(e){n||(n=!0,l.reject(s,e))});var a;return s}},{immediate:36}],38:[function(e,t,r){"use strict";var n={};(0,e("./lib/utils/common").assign)(n,e("./lib/deflate"),e("./lib/inflate"),e("./lib/zlib/constants")),t.exports=n},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(e,t,r){"use strict";var a=e("./zlib/deflate"),o=e("./utils/common"),h=e("./utils/strings"),i=e("./zlib/messages"),s=e("./zlib/zstream"),u=Object.prototype.toString,l=0,f=-1,c=0,d=8;function p(e){if(!(this instanceof p))return new p(e);this.options=o.assign({level:f,method:d,chunkSize:16384,windowBits:15,memLevel:8,strategy:c,to:""},e||{});var t=this.options;t.raw&&0<t.windowBits?t.windowBits=-t.windowBits:t.gzip&&0<t.windowBits&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new s,this.strm.avail_out=0;var r=a.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(r!==l)throw new Error(i[r]);if(t.header&&a.deflateSetHeader(this.strm,t.header),t.dictionary){var n;if(n="string"==typeof t.dictionary?h.string2buf(t.dictionary):"[object ArrayBuffer]"===u.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,(r=a.deflateSetDictionary(this.strm,n))!==l)throw new Error(i[r]);this._dict_set=!0}}function n(e,t){var r=new p(t);if(r.push(e,!0),r.err)throw r.msg||i[r.err];return r.result}p.prototype.push=function(e,t){var r,n,i=this.strm,s=this.options.chunkSize;if(this.ended)return!1;n=t===~~t?t:!0===t?4:0,"string"==typeof e?i.input=h.string2buf(e):"[object ArrayBuffer]"===u.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;do{if(0===i.avail_out&&(i.output=new o.Buf8(s),i.next_out=0,i.avail_out=s),1!==(r=a.deflate(i,n))&&r!==l)return this.onEnd(r),!(this.ended=!0);0!==i.avail_out&&(0!==i.avail_in||4!==n&&2!==n)||("string"===this.options.to?this.onData(h.buf2binstring(o.shrinkBuf(i.output,i.next_out))):this.onData(o.shrinkBuf(i.output,i.next_out)))}while((0<i.avail_in||0===i.avail_out)&&1!==r);return 4===n?(r=a.deflateEnd(this.strm),this.onEnd(r),this.ended=!0,r===l):2!==n||(this.onEnd(l),!(i.avail_out=0))},p.prototype.onData=function(e){this.chunks.push(e)},p.prototype.onEnd=function(e){e===l&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg},r.Deflate=p,r.deflate=n,r.deflateRaw=function(e,t){return(t=t||{}).raw=!0,n(e,t)},r.gzip=function(e,t){return(t=t||{}).gzip=!0,n(e,t)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(e,t,r){"use strict";var c=e("./zlib/inflate"),d=e("./utils/common"),p=e("./utils/strings"),m=e("./zlib/constants"),n=e("./zlib/messages"),i=e("./zlib/zstream"),s=e("./zlib/gzheader"),_=Object.prototype.toString;function a(e){if(!(this instanceof a))return new a(e);this.options=d.assign({chunkSize:16384,windowBits:0,to:""},e||{});var t=this.options;t.raw&&0<=t.windowBits&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(0<=t.windowBits&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),15<t.windowBits&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new i,this.strm.avail_out=0;var r=c.inflateInit2(this.strm,t.windowBits);if(r!==m.Z_OK)throw new Error(n[r]);this.header=new s,c.inflateGetHeader(this.strm,this.header)}function o(e,t){var r=new a(t);if(r.push(e,!0),r.err)throw r.msg||n[r.err];return r.result}a.prototype.push=function(e,t){var r,n,i,s,a,o,h=this.strm,u=this.options.chunkSize,l=this.options.dictionary,f=!1;if(this.ended)return!1;n=t===~~t?t:!0===t?m.Z_FINISH:m.Z_NO_FLUSH,"string"==typeof e?h.input=p.binstring2buf(e):"[object ArrayBuffer]"===_.call(e)?h.input=new Uint8Array(e):h.input=e,h.next_in=0,h.avail_in=h.input.length;do{if(0===h.avail_out&&(h.output=new d.Buf8(u),h.next_out=0,h.avail_out=u),(r=c.inflate(h,m.Z_NO_FLUSH))===m.Z_NEED_DICT&&l&&(o="string"==typeof l?p.string2buf(l):"[object ArrayBuffer]"===_.call(l)?new Uint8Array(l):l,r=c.inflateSetDictionary(this.strm,o)),r===m.Z_BUF_ERROR&&!0===f&&(r=m.Z_OK,f=!1),r!==m.Z_STREAM_END&&r!==m.Z_OK)return this.onEnd(r),!(this.ended=!0);h.next_out&&(0!==h.avail_out&&r!==m.Z_STREAM_END&&(0!==h.avail_in||n!==m.Z_FINISH&&n!==m.Z_SYNC_FLUSH)||("string"===this.options.to?(i=p.utf8border(h.output,h.next_out),s=h.next_out-i,a=p.buf2string(h.output,i),h.next_out=s,h.avail_out=u-s,s&&d.arraySet(h.output,h.output,i,s,0),this.onData(a)):this.onData(d.shrinkBuf(h.output,h.next_out)))),0===h.aLine truncated
|
||||
e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm)}function U(e,t){e.pending_buf[e.pending++]=t}function P(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t}function L(e,t){var r,n,i=e.max_chain_length,s=e.strstart,a=e.prev_length,o=e.nice_match,h=e.strstart>e.w_size-z?e.strstart-(e.w_size-z):0,u=e.window,l=e.w_mask,f=e.prev,c=e.strstart+S,d=u[s+a-1],p=u[s+a];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(u[(r=t)+a]===p&&u[r+a-1]===d&&u[r]===u[s]&&u[++r]===u[s+1]){s+=2,r++;do{}while(u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&s<c);if(n=S-(c-s),s=c-S,a<n){if(e.match_start=t,o<=(a=n))break;d=u[s+a-1],p=u[s+a]}}}while((t=f[t&l])>h&&0!=--i);return a<=e.lookahead?a:e.lookahead}function j(e){var t,r,n,i,s,a,o,h,u,l,f=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=f+(f-z)){for(c.arraySet(e.window,e.window,f,f,0),e.match_start-=f,e.strstart-=f,e.block_start-=f,t=r=e.hash_size;n=e.head[--t],e.head[t]=f<=n?n-f:0,--r;);for(t=r=f;n=e.prev[--t],e.prev[t]=f<=n?n-f:0,--r;);i+=f}if(0===e.strm.avail_in)break;if(a=e.strm,o=e.window,h=e.strstart+e.lookahead,u=i,l=void 0,l=a.avail_in,u<l&&(l=u),r=0===l?0:(a.avail_in-=l,c.arraySet(o,a.input,a.next_in,l,h),1===a.state.wrap?a.adler=d(a.adler,o,l,h):2===a.state.wrap&&(a.adler=p(a.adler,o,l,h)),a.next_in+=l,a.total_in+=l,l),e.lookahead+=r,e.lookahead+e.insert>=x)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=(e.ins_h<<e.hash_shift^e.window[s+1])&e.hash_mask;e.insert&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[s+x-1])&e.hash_mask,e.prev[s&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=s,s++,e.insert--,!(e.lookahead+e.insert<x)););}while(e.lookahead<z&&0!==e.strm.avail_in)}function Z(e,t){for(var r,n;;){if(e.lookahead<z){if(j(e),e.lookahead<z&&t===l)return A;if(0===e.lookahead)break}if(r=0,e.lookahead>=x&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+x-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==r&&e.strstart-r<=e.w_size-z&&(e.match_length=L(e,r)),e.match_length>=x)if(n=u._tr_tally(e,e.strstart-e.match_start,e.match_length-x),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=x){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+x-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart,0!=--e.match_length;);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+1])&e.hash_mask;else n=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=e.strstart<x-1?e.strstart:x-1,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}function W(e,t){for(var r,n,i;;){if(e.lookahead<z){if(j(e),e.lookahead<z&&t===l)return A;if(0===e.lookahead)break}if(r=0,e.lookahead>=x&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+x-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=x-1,0!==r&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-z&&(e.match_length=L(e,r),e.match_length<=5&&(1===e.strategy||e.match_length===x&&4096<e.strstart-e.match_start)&&(e.match_length=x-1)),e.prev_length>=x&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-x,n=u._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-x),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+x-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!=--e.prev_length;);if(e.match_available=0,e.match_length=x-1,e.strstart++,n&&(N(e,!1),0===e.strm.avail_out))return A}else if(e.match_available){if((n=u._tr_tally(e,0,e.window[e.strstart-1]))&&N(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return A}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=u._tr_tally(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<x-1?e.strstart:x-1,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}function M(e,t,r,n,i){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=n,this.func=i}function H(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=v,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,thisLine truncated
|
||||
i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindex<n.gzhead.comment.length?255&n.gzhead.comment.charCodeAt(n.gzindex++):0,U(n,s)}while(0!==s);n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.status=103)}else n.status=103;if(103===n.status&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&F(e),n.pending+2<=n.pending_buf_size&&(U(n,255&e.adler),U(n,e.adler>>8&255),e.adler=0,n.status=E)):n.status=E),0!==n.pending){if(F(e),0===e.avail_out)return n.last_flush=-1,m}else if(0===e.avail_in&&T(t)<=T(r)&&t!==f)return R(e,-5);if(666===n.status&&0!==e.avail_in)return R(e,-5);if(0!==e.avail_in||0!==n.lookahead||t!==l&&666!==n.status){var o=2===n.strategy?function(e,t){for(var r;;){if(0===e.lookahead&&(j(e),0===e.lookahead)){if(t===l)return A;break}if(e.match_length=0,r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):3===n.strategy?function(e,t){for(var r,n,i,s,a=e.window;;){if(e.lookahead<=S){if(j(e),e.lookahead<=S&&t===l)return A;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=x&&0<e.strstart&&(n=a[i=e.strstart-1])===a[++i]&&n===a[++i]&&n===a[++i]){s=e.strstart+S;do{}while(n===a[++i]&&n===a[++i]&&n===a[++i]&&n===a[++i]&&n===a[++i]&&n===a[++i]&&n===a[++i]&&n===a[++i]&&i<s);e.match_length=S-(s-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=x?(r=u._tr_tally(e,1,e.match_length-x),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):h[n.level].func(n,t);if(o!==O&&o!==B||(n.status=666),o===A||o===O)return 0===e.avail_out&&(n.last_flush=-1),m;if(o===I&&(1===t?u._tr_align(n):5!==t&&(u._tr_stored_block(n,0,0,!1),3===t&&(D(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),F(e),0===e.avail_out))return n.last_flush=-1,m}return t!==f?m:n.wrap<=0?1:(2===n.wrap?(U(n,255&e.adler),U(n,e.adler>>8&255),U(n,e.adler>>16&255),U(n,e.adler>>24&255),U(n,255&e.total_in),U(n,e.total_in>>8&255),U(n,e.total_in>>16&255),U(n,e.total_in>>24&255)):(P(n,e.adler>>>16),P(n,65535&e.adler)),F(e),0<n.wrap&&(n.wrap=-n.wrap),0!==n.pending?m:1)},r.deflateEnd=function(e){var t;return e&&e.state?(t=e.state.status)!==C&&69!==t&&73!==t&&91!==t&&103!==t&&t!==E&&666!==t?R(e,_):(e.state=null,t===E?R(e,-3):m):_},r.deflateSetDictionary=function(e,t){var r,n,i,s,a,o,h,u,l=t.length;if(!e||!e.state)return _;if(2===(s=(r=e.state).wrap)||1===s&&r.status!==C||r.lookahead)return _;for(1===s&&(e.adler=d(e.adler,t,l,0)),r.wrap=0,l>=r.w_size&&(0===s&&(D(r.head),r.strstart=0,r.block_start=0,r.insert=0),u=new c.Buf8(r.w_size),c.arraySet(u,t,l-r.w_size,r.w_size,0),t=u,l=r.w_size),a=e.avail_in,o=e.next_in,h=e.input,e.avail_in=l,e.next_in=0,e.input=t,j(r);r.lookahead>=x;){for(n=r.strstart,i=r.lookahead-(x-1);r.ins_h=(r.ins_h<<r.hash_shift^r.window[n+x-1])&r.hash_mask,r.prev[n&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=n,n++,--i;);r.strstart=n,r.lookahead=x-1,j(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=x-1,r.match_available=0,e.next_in=o,e.input=h,e.avail_in=a,r.wrap=s,m},r.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(e,t,r){"use strict";t.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(e,t,r){"use strict";t.exports=function(e,t){var r,n,i,s,a,o,h,u,l,f,c,d,p,m,_,g,b,v,y,w,k,x,S,z,C;r=e.state,n=e.next_in,z=e.input,i=n+(e.avail_in-5),s=e.next_out,C=e.output,a=s-(t-e.avail_out),o=s+(e.avail_out-257),h=r.dmax,u=r.wsize,l=r.whave,f=r.wnext,c=r.window,d=r.hold,p=r.bits,m=r.lencode,_=r.distcode,g=(1<<r.lenbits)-1,b=(1<<r.distbits)-1;e:do{p<15&&(d+=z[n++]<<p,p+=8,d+=z[n++]<<p,p+=8),v=m[d&g];t:for(;;){if(d>>>=y=v>>>24,p-=y,0===(y=v>>>16&255))C[s++]=65535&v;else{if(!(16&y)){if(0==(64&y)){v=m[(65535&v)+(d&(1<<y)-1)];continue t}if(32&y){r.mode=12;break e}e.msg="invalid literal/length code",r.mode=30;break e}w=65535&v,(y&=15)&&(p<y&&(d+=z[n++]<<p,p+=8),w+=d&(1<<y)-1,d>>>=y,p-=y),p<15&&(d+=z[n++]<<p,p+=8,d+=z[n++]<<p,p+=8),v=_[d&b];r:for(;;){if(d>>>=y=v>>>24,p-=y,!(16&(y=v>>>16&255))){if(0==(64&y)){v=_[(65535&v)+(d&(1<<y)-1)];continue r}e.msg="invalid distance code",r.mode=30;break e}if(k=65535&v,p<(y&=15)&&(d+=z[n++]<<p,(p+=8)<y&&(d+=z[n++]<<p,p+=8)),h<(k+=d&(1<<y)-1)){e.msg="invalid distance too far back",r.mode=30;break e}if(d>>>=y,p-=y,(y=s-a)<k){if(l<(y=k-y)&&r.sane){e.msg="invalid distance too far back",r.mode=30;break e}if(S=c,(x=0)===f){if(x+=u-y,y<w){for(w-=y;C[s++]Line truncated
|
||||
mode=7;case 7:if(2048&r.flags){if(0===o)break e;for(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k)),k&&d<o;);if(512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,k)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=8;case 8:if(4096&r.flags){if(0===o)break e;for(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.comment+=String.fromCharCode(k)),k&&d<o;);if(512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,k)break e}else r.head&&(r.head.comment=null);r.mode=9;case 9:if(512&r.flags){for(;l<16;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}if(u!==(65535&r.check)){e.msg="header crc mismatch",r.mode=30;break}l=u=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}e.adler=r.check=L(u),l=u=0,r.mode=11;case 11:if(0===r.havedict)return e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,2;e.adler=r.check=1,r.mode=12;case 12:if(5===t||6===t)break e;case 13:if(r.last){u>>>=7&l,l-=7&l,r.mode=27;break}for(;l<3;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}switch(r.last=1&u,l-=1,3&(u>>>=1)){case 0:r.mode=14;break;case 1:if(j(r),r.mode=20,6!==t)break;u>>>=2,l-=2;break e;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30}u>>>=2,l-=2;break;case 14:for(u>>>=7&l,l-=7&l;l<32;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}if((65535&u)!=(u>>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&u,l=u=0,r.mode=15,6===t)break e;case 15:r.mode=16;case 16:if(d=r.length){if(o<d&&(d=o),h<d&&(d=h),0===d)break e;I.arraySet(i,n,s,d,a),o-=d,s+=d,h-=d,a+=d,r.length-=d;break}r.mode=12;break;case 17:for(;l<14;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}if(r.nlen=257+(31&u),u>>>=5,l-=5,r.ndist=1+(31&u),u>>>=5,l-=5,r.ncode=4+(15&u),u>>>=4,l-=4,286<r.nlen||30<r.ndist){e.msg="too many length or distance symbols",r.mode=30;break}r.have=0,r.mode=18;case 18:for(;r.have<r.ncode;){for(;l<3;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}r.lens[A[r.have++]]=7&u,u>>>=3,l-=3}for(;r.have<19;)r.lens[A[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},x=T(0,r.lens,0,19,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have<r.nlen+r.ndist;){for(;g=(C=r.lencode[u&(1<<r.lenbits)-1])>>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}if(b<16)u>>>=_,l-=_,r.lens[r.have++]=b;else{if(16===b){for(z=_+2;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}if(u>>>=_,l-=_,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}k=r.lens[r.have-1],d=3+(3&u),u>>>=2,l-=2}else if(17===b){for(z=_+3;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}l-=_,k=0,d=3+(7&(u>>>=_)),u>>>=3,l-=3}else{for(z=_+7;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}l-=_,k=0,d=11+(127&(u>>>=_)),u>>>=7,l-=7}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;d--;)r.lens[r.have++]=k}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,S={bits:r.lenbits},x=T(D,r.lens,0,r.nlen,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,S={bits:r.distbits},x=T(F,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,S),r.distbits=S.bits,x){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,6===t)break e;case 20:r.mode=21;case 21:if(6<=o&&258<=h){e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,R(e,c),a=e.next_out,i=e.output,h=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,u=r.hold,l=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=(C=r.lencode[u&(1<<r.lenbits)-1])>>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}if(g&&0==(240&g)){for(v=_,y=g,w=b;g=(C=r.lencode[w+((u&(1<<v+y)-1)>>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}u>>>=v,l-=v,r.back+=v}if(u>>>=_,l-=_,r.back+=_,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=12;break}if(64&g){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(z=r.extra;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}r.length+=u&(1<<r.extra)-1,u>>>=r.extra,l-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;g=(C=r.distcode[u&(1<<r.distbits)-1])>>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}if(0==(240&g)){for(v=_,y=g,w=b;g=(C=r.distcode[w+((u&(1<<v+y)-1)>>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}u>>>=v,l-=v,r.back+=v}if(u>>>=_,l-=_,r.back+=_,64&g){e.msg="invalid distance code",r.mode=30;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(z=r.extra;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8}r.offset+=u&(1<<r.extra)-1,u>>>=r.extra,l-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===h)break e;if(d=c-h,r.offset>d){if((d=r.offset-d)Line truncated
|
||||
o=e[2*i+1];0!==o&&(e[2*i]=j(s[o]++,o))}}function W(e){var t;for(t=0;t<l;t++)e.dyn_ltree[2*t]=0;for(t=0;t<f;t++)e.dyn_dtree[2*t]=0;for(t=0;t<c;t++)e.bl_tree[2*t]=0;e.dyn_ltree[2*m]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0}function M(e){8<e.bi_valid?U(e,e.bi_buf):0<e.bi_valid&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0}function H(e,t,r,n){var i=2*t,s=2*r;return e[i]<e[s]||e[i]===e[s]&&n[t]<=n[r]}function G(e,t,r){for(var n=e.heap[r],i=r<<1;i<=e.heap_len&&(i<e.heap_len&&H(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!H(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n}function K(e,t,r){var n,i,s,a,o=0;if(0!==e.last_lit)for(;n=e.pending_buf[e.d_buf+2*o]<<8|e.pending_buf[e.d_buf+2*o+1],i=e.pending_buf[e.l_buf+o],o++,0===n?L(e,i,t):(L(e,(s=A[i])+u+1,t),0!==(a=w[s])&&P(e,i-=I[s],a),L(e,s=N(--n),r),0!==(a=k[s])&&P(e,n-=T[s],a)),o<e.last_lit;);L(e,m,t)}function Y(e,t){var r,n,i,s=t.dyn_tree,a=t.stat_desc.static_tree,o=t.stat_desc.has_stree,h=t.stat_desc.elems,u=-1;for(e.heap_len=0,e.heap_max=_,r=0;r<h;r++)0!==s[2*r]?(e.heap[++e.heap_len]=u=r,e.depth[r]=0):s[2*r+1]=0;for(;e.heap_len<2;)s[2*(i=e.heap[++e.heap_len]=u<2?++u:0)]=1,e.depth[i]=0,e.opt_len--,o&&(e.static_len-=a[2*i+1]);for(t.max_code=u,r=e.heap_len>>1;1<=r;r--)G(e,s,r);for(i=h;r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],G(e,s,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,s[2*i]=s[2*r]+s[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,s[2*r+1]=s[2*n+1]=i,e.heap[1]=i++,G(e,s,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var r,n,i,s,a,o,h=t.dyn_tree,u=t.max_code,l=t.stat_desc.static_tree,f=t.stat_desc.has_stree,c=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,m=0;for(s=0;s<=g;s++)e.bl_count[s]=0;for(h[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<_;r++)p<(s=h[2*h[2*(n=e.heap[r])+1]+1]+1)&&(s=p,m++),h[2*n+1]=s,u<n||(e.bl_count[s]++,a=0,d<=n&&(a=c[n-d]),o=h[2*n],e.opt_len+=o*(s+a),f&&(e.static_len+=o*(l[2*n+1]+a)));if(0!==m){do{for(s=p-1;0===e.bl_count[s];)s--;e.bl_count[s]--,e.bl_count[s+1]+=2,e.bl_count[p]--,m-=2}while(0<m);for(s=p;0!==s;s--)for(n=e.bl_count[s];0!==n;)u<(i=e.heap[--r])||(h[2*i+1]!==s&&(e.opt_len+=(s-h[2*i+1])*h[2*i],h[2*i+1]=s),n--)}}(e,t),Z(s,u,e.bl_count)}function X(e,t,r){var n,i,s=-1,a=t[1],o=0,h=7,u=4;for(0===a&&(h=138,u=3),t[2*(r+1)+1]=65535,n=0;n<=r;n++)i=a,a=t[2*(n+1)+1],++o<h&&i===a||(o<u?e.bl_tree[2*i]+=o:0!==i?(i!==s&&e.bl_tree[2*i]++,e.bl_tree[2*b]++):o<=10?e.bl_tree[2*v]++:e.bl_tree[2*y]++,s=i,u=(o=0)===a?(h=138,3):i===a?(h=6,3):(h=7,4))}function V(e,t,r){var n,i,s=-1,a=t[1],o=0,h=7,u=4;for(0===a&&(h=138,u=3),n=0;n<=r;n++)if(i=a,a=t[2*(n+1)+1],!(++o<h&&i===a)){if(o<u)for(;L(e,i,e.bl_tree),0!=--o;);else 0!==i?(i!==s&&(L(e,i,e.bl_tree),o--),L(e,b,e.bl_tree),P(e,o-3,2)):o<=10?(L(e,v,e.bl_tree),P(e,o-3,3)):(L(e,y,e.bl_tree),P(e,o-11,7));s=i,u=(o=0)===a?(h=138,3):i===a?(h=6,3):(h=7,4)}}n(T);var q=!1;function J(e,t,r,n){P(e,(s<<1)+(n?1:0),3),function(e,t,r,n){M(e),n&&(U(e,r),U(e,~r)),i.arraySet(e.pending_buf,e.window,t,r,e.pending),e.pending+=r}(e,t,r,!0)}r._tr_init=function(e){q||(function(){var e,t,r,n,i,s=new Array(g+1);for(n=r=0;n<a-1;n++)for(I[n]=r,e=0;e<1<<w[n];e++)A[r++]=n;for(A[r-1]=n,n=i=0;n<16;n++)for(T[n]=i,e=0;e<1<<k[n];e++)E[i++]=n;for(i>>=7;n<f;n++)for(T[n]=i<<7,e=0;e<1<<k[n]-7;e++)E[256+i++]=n;for(t=0;t<=g;t++)s[t]=0;for(e=0;e<=143;)z[2*e+1]=8,e++,s[8]++;for(;e<=255;)z[2*e+1]=9,e++,s[9]++;for(;e<=279;)z[2*e+1]=7,e++,s[7]++;for(;e<=287;)z[2*e+1]=8,e++,s[8]++;for(Z(z,l+1,s),e=0;e<f;e++)C[2*e+1]=5,C[2*e]=j(e,5);O=new D(z,w,u+1,l,g),B=new D(C,k,0,f,g),R=new D(new Array(0),x,0,c,p)}(),q=!0),e.l_desc=new F(e.dyn_ltree,O),e.d_desc=new F(e.dyn_dtree,B),e.bl_desc=new F(e.bl_tree,R),e.bi_buf=0,e.bi_valid=0,W(e)},r._tr_stored_block=J,r._tr_flush_block=function(e,t,r,n){var i,s,a=0;0<e.level?(2===e.strm.data_type&&(e.strm.data_type=function(e){var t,r=4093624447;for(t=0;t<=31;t++,r>>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return o;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return h;for(t=32;t<u;t++)if(0!==e.dyn_ltree[2*t])return h;return o}(e)),Y(e,e.l_desc),Y(e,e.d_desc),a=function(e){var t;for(X(e,e.dyn_ltree,e.l_desc.max_code),X(e,e.dyn_dtree,e.d_desc.max_code),Y(e,e.bl_desc),t=c-1;3<=t&&0===e.bl_tree[2*S[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t}(e),i=e.opt_len+3+7>>>3,(s=e.static_len+3+7>>>3)<=i&&(i=s)):i=s=r+5,r+4<=i&&-1!==t?J(e,t,r,n):4===e.strategy||s===i?(P(e,2+(n?1:0),3),K(e,z,C)):(P(e,4+(n?1:0),3),function(e,t,r,n){var i;for(P(e,t-257,5),P(e,r-1,5),P(e,n-4,4),i=0;i<n;i++)P(e,e.bl_tree[2*S[i]+1],3);V(e,e.dyn_ltree,t-1),V(e,e.dyn_dtree,r-1)}(e,e.l_desc.max_code+1,e.d_desc.max_code+1,a+1),K(e,e.dyn_ltree,e.dyn_dtree)),W(e),n&&M(e)},r._tr_tally=function(e,t,r){return e.pending_buf[e.d_buf+2*e.last_lit]=t>>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&r,e.last_lit++,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[2*(A[r]+u+1)]++,e.dyn_dtree[2*N(t)]+Line truncated
|
||||
</script>
|
||||
</html>
|
||||
@@ -1,44 +0,0 @@
|
||||
def detectType(value: str) -> str:
|
||||
val = value.strip()
|
||||
# Boolean check
|
||||
if val.lower() in {'true', 'false'}:
|
||||
return 'Boolean'
|
||||
|
||||
# Int check
|
||||
try:
|
||||
int(val)
|
||||
return 'Int'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# Float check
|
||||
try:
|
||||
float(val)
|
||||
return 'Float'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# Default to String
|
||||
return 'String'
|
||||
|
||||
def typeToCType(valType: str) -> str:
|
||||
if valType == 'Int':
|
||||
return 'int'
|
||||
elif valType == 'Float':
|
||||
return 'float'
|
||||
elif valType == 'Boolean':
|
||||
return 'bool'
|
||||
else:
|
||||
return 'char_t*'
|
||||
|
||||
def stringToCType(value: str) -> str:
|
||||
valType = detectType(value)
|
||||
if valType == 'Int':
|
||||
return str(int(value))
|
||||
elif valType == 'Float':
|
||||
return str(float(value))
|
||||
elif valType == 'Boolean':
|
||||
return 'true' if value.lower() == 'true' else 'false'
|
||||
else:
|
||||
escaped = value.replace('\\', '\\\\').replace('"', '\\"')
|
||||
return f'"{escaped}"'
|
||||
Reference in new issue
Block a user