修改地图生成模板,墙体与水体回复正常
This commit is contained in:
@@ -2,22 +2,30 @@ import os
|
||||
import pandas as pd
|
||||
from openpyxl import load_workbook
|
||||
|
||||
columns_to_preview = 3 # 保留你原来的配置
|
||||
|
||||
def _merge_read_config(config):
|
||||
defaults = {
|
||||
"columns_to_preview": 3,
|
||||
"green_colors": {"FF92D050", "FF00B050"},
|
||||
"blue_colors": {"FF00B0F0", "FF0070C0"},
|
||||
"orange_colors": {"FFC55B11", "FFC55C10", "FFB45F06"},
|
||||
"pink_colors": {"FFEF949F", "FFFF99FF"},
|
||||
"log_file": "w.log",
|
||||
}
|
||||
if not config:
|
||||
return defaults
|
||||
for key, value in config.items():
|
||||
if value is not None:
|
||||
defaults[key] = value
|
||||
return defaults
|
||||
# 绿色填充的颜色值(先按常见 Excel 绿填充写一个,你可以打印确认后再调整)
|
||||
GREEN_COLORS = {
|
||||
"FF92D050", # 常见的浅绿色
|
||||
"FF00B050", # 另一种绿色,必要时可以删掉/增加
|
||||
}
|
||||
|
||||
BLUE_COLORS = {
|
||||
"FF00B0F0", # 常见的浅蓝色
|
||||
"FF0070C0", # 另一种蓝色,必要时可以删掉/增加
|
||||
}
|
||||
|
||||
# c55c10
|
||||
ORANGE_COLORS = {
|
||||
"FFC55B11",
|
||||
"FFC55C10", # 常见的橙色
|
||||
"FFB45F06", # 另一种橙色,必要时可以删掉/增加
|
||||
}
|
||||
|
||||
PINK_COLORS = {
|
||||
"FFEF949F", # 常见的粉色
|
||||
"FFFF99FF", # 另一种粉色,必要时可以删掉/增加
|
||||
}
|
||||
|
||||
|
||||
def _load_map_dataframe(file_path, sheet_name, start_i):
|
||||
@@ -61,7 +69,7 @@ def _write_color_output(filename, rows, columns, success_msg, empty_msg):
|
||||
print(empty_msg)
|
||||
|
||||
|
||||
def find_cells_with_currency_xlsx(file_path, sheet_name="Sheet1", start_i=90091, search_term="币", config=None):
|
||||
def find_cells_with_currency_xlsx(file_path, sheet_name="Sheet1", start_i=90091, search_term="币"):
|
||||
"""
|
||||
读取 XLSX 文件,查找包含指定词语(默认为“币”)的单元格,
|
||||
并返回这些单元格的 (地图号, X, Y[, 方向]),结果同时保存为 found_xxx.xlsx。
|
||||
@@ -72,8 +80,6 @@ def find_cells_with_currency_xlsx(file_path, sheet_name="Sheet1", start_i=90091,
|
||||
if df_info is None:
|
||||
return []
|
||||
|
||||
cfg = _merge_read_config(config)
|
||||
|
||||
df, map_col, y_col, grid_columns = df_info
|
||||
results = []
|
||||
|
||||
@@ -97,6 +103,11 @@ def find_cells_with_currency_xlsx(file_path, sheet_name="Sheet1", start_i=90091,
|
||||
if not matching_indices:
|
||||
continue
|
||||
|
||||
# 为了打印调试信息,预览前几列(至少包含 A、B 两列)
|
||||
current_col_index = df.columns.get_loc(column)
|
||||
end_preview_index = max(2, min(current_col_index, columns_to_preview))
|
||||
preview_cols = df.columns[:end_preview_index].tolist()
|
||||
|
||||
for idx in matching_indices:
|
||||
# 地图号和坐标:直接从 A、B 列取值
|
||||
map_no = df.at[idx, map_col] # A 列 = 地图编号
|
||||
@@ -133,7 +144,7 @@ def find_cells_with_currency_xlsx(file_path, sheet_name="Sheet1", start_i=90091,
|
||||
return results
|
||||
|
||||
|
||||
def scan_color_blocks(file_path, sheet_name="Sheet1", start_i=90091, config=None):
|
||||
def scan_color_blocks(file_path, sheet_name="Sheet1", start_i=90091):
|
||||
"""扫描地图区域内的颜色格子,并把结果写入对应的 Excel 文件。"""
|
||||
|
||||
print("\n开始扫描颜色图案格子…")
|
||||
@@ -142,8 +153,6 @@ def scan_color_blocks(file_path, sheet_name="Sheet1", start_i=90091, config=None
|
||||
if df_info is None:
|
||||
return {}
|
||||
|
||||
cfg = _merge_read_config(config)
|
||||
|
||||
df, map_col, y_col, grid_columns = df_info
|
||||
|
||||
try:
|
||||
@@ -166,10 +175,6 @@ def scan_color_blocks(file_path, sheet_name="Sheet1", start_i=90091, config=None
|
||||
|
||||
excel_row_offset = 2 # DataFrame 行索引 0 对应 Excel 的第 2 行
|
||||
|
||||
import logging
|
||||
|
||||
logging.basicConfig(filename=cfg["log_file"], level=logging.INFO)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
for idx in df.index:
|
||||
map_no = df.at[idx, map_col]
|
||||
@@ -202,16 +207,13 @@ def scan_color_blocks(file_path, sheet_name="Sheet1", start_i=90091, config=None
|
||||
continue
|
||||
|
||||
c = str(color_code).upper()
|
||||
if c.startswith("FF"):
|
||||
log.info("Cell at Row %s, Column %s has color code: %s", excel_row, col_idx, c)
|
||||
|
||||
if c in cfg["green_colors"]:
|
||||
if c in GREEN_COLORS:
|
||||
block_results.append((map_no, col, y_val))
|
||||
if c in cfg["blue_colors"]:
|
||||
if c in BLUE_COLORS:
|
||||
water_results.append((map_no, col, y_val))
|
||||
if c in cfg["orange_colors"]:
|
||||
if c in ORANGE_COLORS:
|
||||
wall_results.append((map_no, col, y_val))
|
||||
if c in cfg["pink_colors"]:
|
||||
if c in PINK_COLORS:
|
||||
jump_results.append((map_no, col, y_val))
|
||||
|
||||
columns = ["地图号 (Map No)", "X坐标 (X No)", "Y坐标 (Y No)"]
|
||||
|
||||
Reference in New Issue
Block a user