|
@@ -1,10 +1,14 @@
|
|
|
+#!/usr/local/bin/python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
+# File: conv_lvs.py
|
|
|
# Desc: 将用到的关卡文件压缩成程序使用的protobuf格式
|
|
|
# Date: 2017-04-18
|
|
|
import os
|
|
|
import sys
|
|
|
import json
|
|
|
import levelData_pb2
|
|
|
-
|
|
|
+import time
|
|
|
|
|
|
def read_json(file_path):
|
|
|
with open(file_path, 'r') as file:
|
|
@@ -115,9 +119,29 @@ def conver_json_to_proto(tDir, tFileName, outDir):
|
|
|
if tile.y > maxY:
|
|
|
maxY = tile.y
|
|
|
cntTiles += 1
|
|
|
+ print('Tile 总数: %d' % (cntTiles,))
|
|
|
if cntTiles%3 != 0:
|
|
|
- print('Error: tile count is not a multiple of 3: %d' % (cntTiles,))
|
|
|
+ print('Error: Tile总数不是3的倍数 3: %d' % (cntTiles,))
|
|
|
exit(1)
|
|
|
+ # 检查每层的tile是否有重叠
|
|
|
+ pos_conflict = {}
|
|
|
+ for z in range(0, maxZ+1):
|
|
|
+ for x in range(0, maxX+1):
|
|
|
+ for y in range(0, maxY+1):
|
|
|
+ if (x,y,z) in tilesByPos:
|
|
|
+ adjs = [(0,1),(0,-1),(1,0),(-1,0),(1,1),(1,-1),(-1,1),(-1,-1)]
|
|
|
+ for adj in adjs:
|
|
|
+ p = (x+adj[0],y+adj[1],z)
|
|
|
+ if p in tilesByPos:
|
|
|
+ if (x,y) not in pos_conflict:
|
|
|
+ pos_conflict[(x,y,z)] = []
|
|
|
+ pos_conflict[(x,y,z)].append(p)
|
|
|
+ for p,ps in pos_conflict.items():
|
|
|
+ print("位置冲突:", p, ps)
|
|
|
+ if len(pos_conflict) > 0:
|
|
|
+ exit(1)
|
|
|
+ time.sleep(3)
|
|
|
+
|
|
|
# 根据上面的布局信息,计算每个tile的几个信息:
|
|
|
# 1. 每个tile的视觉层级(不同于上面z的信息,那是一个布局信息,相同的z可能出在不同的视觉层级)
|
|
|
# 从maxZ开始,逐层向下计算;对于每一个位置,如果该位置有tile,则计算该tile的视觉层级
|