I was having fun trying to make an RPG-maker MV tile-based map editor You can do what you want with it
ps: The way i am displaying the tiles here is still just a placeholder. In a real tile-based map editor, each tile ID would correspond to a specific tile in a tileset, and you'd use image manipulation techniques to extract and display that specific tile. The current code simply displays the entire tileset for each tile, which isn't what you'd want in a finished product
ps: The way i am displaying the tiles here is still just a placeholder. In a real tile-based map editor, each tile ID would correspond to a specific tile in a tileset, and you'd use image manipulation techniques to extract and display that specific tile. The current code simply displays the entire tileset for each tile, which isn't what you'd want in a finished product
import tkinter as tk
from tkinter import filedialog, ttk
from PIL import ImageTk, Image
import json
TILESET_WIDTH = 8
TILESET_HEIGHT = 8
TILESIZE = 48 # Assuming tiles are 48x48 by default
TILESETS = {
'Default': 'path_to_tileset_default.png',
'Forest': path_to_tileset_default.png,
'City': 'path_to_tileset_default.png',
# ... add more tilesets as needed
}
class LayeredTileEditor:
def __init__(self, master):
self.master = master
self.master.title("Layered Tile Editor")
self.map_data = None
# Tileset Selection
self.tileset_var = tk.StringVar()
self.tileset_dropdown = ttk.Combobox(self.master, textvariable=self.tileset_var)
self.tileset_dropdown['values'] = list(TILESETS.keys())
self.tileset_dropdown.set('Default') # Default tileset
self.tileset_dropdown.bind('<<ComboboxSelected>>', self.change_tileset) # Trigger when a new tileset is selected
self.tileset_dropdown.pack(pady=10)
self.change_tileset() # Load the default tileset
# Canvas to display the map
self.canvas = tk.Canvas(self.master)
self.canvas.pack(fill=tk.BOTH, expand=True)
# Add buttons
self.load_button = tk.Button(self.master, text="Load Map", command=self.load_map)
self.load_button.pack()
self.save_button = tk.Button(self.master, text="Save Map", command=self.save_map)
self.save_button.pack()
def change_tileset(self, event=None):
tileset_name = self.tileset_var.get()
self.tileset_image = ImageTk.PhotoImage(Image.open(TILESETS[tileset_name]))
if self.map_data:
self.refresh_map_display()
def load_map(self):
file_path = filedialog.askopenfilename(filetypes=[("JSON files", "*.json")])
if file_path:
with open(file_path, 'r') as f:
self.map_data = json.load(f)
self.refresh_map_display()
def save_map(self):
# Here you will implement saving functionality
pass
def refresh_map_display(self):
# Clear the canvas first
self.canvas.delete("all")
width = self.map_data['width']
height = self.map_data['height']
for index, tile_id in enumerate(self.map_data['data']):
y = index // width # Integer division to get row
x = index % width # Modulus to get column
# Placeholder line
self.canvas.create_image(x*TILESIZE, y*TILESIZE, anchor=tk.NW, image=self.tileset_image)
if __name__ == "__main__":
root = tk.Tk()
app = LayeredTileEditor(root)
root.mainloop()