Phase 2: Added TownSquare map scaffold and BuildingRestorationSystem.

This commit is contained in:
2025-12-27 13:41:56 +01:00
parent 70f4194826
commit 7b6a4585bc
3 changed files with 30270 additions and 0 deletions

30083
assets/maps/TownSquare.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,114 @@
import json
import os
# Configuration
WIDTH = 100
HEIGHT = 100
TILE_SIZE = 48 # Using 48px for alignment with technical standards
# Create the data array (100x100 filled with 1s for 'Ground' tile)
# 1 = Grass tile from firstgid:1
ground_data = [1] * (WIDTH * HEIGHT)
objects_data = [0] * (WIDTH * HEIGHT)
player_data = [0] * (WIDTH * HEIGHT)
# Center coordinates
cx, cy = WIDTH // 2, HEIGHT // 2
# Helper to set tile at x,y
def set_tile(layer_data, x, y, gid):
index = y * WIDTH + x
if 0 <= index < len(layer_data):
layer_data[index] = gid
# Place Player (Kai) at Town Center
set_tile(player_data, cx, cy, 1541)
map_structure = {
"compressionlevel": -1,
"height": HEIGHT,
"infinite": False,
"layers": [
{
"data": ground_data,
"height": HEIGHT,
"id": 1,
"name": "Ground",
"opacity": 1,
"type": "tilelayer",
"visible": True,
"width": WIDTH,
"x": 0,
"y": 0
},
{
"data": objects_data,
"height": HEIGHT,
"id": 2,
"name": "Objects",
"opacity": 1,
"type": "tilelayer",
"visible": True,
"width": WIDTH,
"x": 0,
"y": 0
},
{
"data": player_data,
"height": HEIGHT,
"id": 3,
"name": "Player",
"opacity": 1,
"type": "tilelayer",
"visible": True,
"width": WIDTH,
"x": 0,
"y": 0
}
],
"nextlayerid": 4,
"nextobjectid": 1,
"orientation": "orthogonal",
"renderorder": "right-down",
"tileheight": TILE_SIZE,
"tilesets": [
{
"columns": 16,
"firstgid": 1,
"image": "../narezano_in_majhno/krvava_zetev_sprites/grass_soil_tileset_1766171156780_obdelan.png",
"imageheight": 512,
"imagewidth": 512,
"margin": 0,
"name": "01_Ground",
"spacing": 0,
"tilecount": 256,
"tileheight": 32,
"tilewidth": 32
},
{
"columns": 10,
"firstgid": 1500,
"image": "../krvava_zetev_sprites/kai_character_2x2_grid_1766098341666.png",
"imageheight": 1024,
"imagewidth": 1024,
"margin": 0,
"name": "Kai_Character",
"spacing": 0,
"tilecount": 100,
"tileheight": 96,
"tilewidth": 96
}
],
"tilewidth": TILE_SIZE,
"type": "map",
"version": "1.10",
"width": WIDTH
}
output_path = "assets/maps/TownSquare.json"
with open(output_path, "w") as f:
json.dump(map_structure, f, indent=4)
print(f"✅ Generated 100x100 TownSquare scaffold: {output_path}")

View File

@@ -0,0 +1,73 @@
/**
* BuildingRestorationSystem.js
* ===========================
* Manages the repair and restoration of ruined buildings in Town Square.
*
* Mechanics:
* - Buildings start in 'ruined' state.
* - Players contribute materials (Wood, Stone, Scrap).
* - Restoration happens in stages.
* - Restored buildings unlock NPCs and Services.
*/
export default class BuildingRestorationSystem {
constructor(scene) {
this.scene = scene;
this.buildings = new Map();
this._initBuildings();
}
_initBuildings() {
// Sample restoration targets
this.buildings.set('blacksmith_shop', {
name: 'Ivan\'s Blacksmith',
state: 'ruined',
progress: 0,
requirements: { wood: 50, stone: 30, scrap: 10 },
npc: 'Ivan Kovač',
unlocked: false
});
this.buildings.set('bakery', {
name: 'Town Bakery',
state: 'ruined',
progress: 0,
requirements: { wood: 40, stone: 20, scrap: 5 },
npc: 'Marija Pekarka',
unlocked: false
});
}
contribute(buildingId, material, amount) {
const b = this.buildings.get(buildingId);
if (!b) return false;
if (b.requirements[material] && b.requirements[material] > 0) {
const used = Math.min(amount, b.requirements[material]);
b.requirements[material] -= used;
// Check if all materials are 0
const allDone = Object.values(b.requirements).every(val => val <= 0);
if (allDone) {
this.restore(buildingId);
}
return used;
}
return 0;
}
restore(buildingId) {
const b = this.buildings.get(buildingId);
if (!b) return;
b.state = 'restored';
b.unlocked = true;
b.progress = 100;
console.log(`🏰 ${b.name} has been restored!`);
this.scene.events.emit('building_restored', b);
}
getBuilding(id) {
return this.buildings.get(id);
}
}