do some p3k optimizations
This commit is contained in:
parent
e057d588c0
commit
486f7e6029
4 changed files with 101 additions and 102 deletions
2
hr.py
2
hr.py
|
@ -51,7 +51,7 @@ if __name__ == '__main__':
|
|||
|
||||
pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA,
|
||||
pyglet.gl.GL_ONE_MINUS_SRC_ALPHA)
|
||||
window = Window()
|
||||
window = Window(width=1024, height=768)
|
||||
window.push_handlers(LoadScreen(window, sys.argv[1]))
|
||||
img = pyglet.resource.image("data/cursors/cradvntr.def/0.png")
|
||||
window.set_mouse_cursor(pyglet.window.ImageMouseCursor(img, 0, 40))
|
||||
|
|
80
lib/h3m.py
80
lib/h3m.py
|
@ -61,7 +61,7 @@ def extract(filename):
|
|||
(map_data[color]["heroes_count"], ) = struct.unpack("<I", h3m_data.read(4))
|
||||
if map_data[color]["heroes_count"] > 0:
|
||||
map_data[color]["heroes"] = {}
|
||||
for i in xrange(map_data[color]["heroes_count"]):
|
||||
for i in range(map_data[color]["heroes_count"]):
|
||||
(map_data[color]["heroes"]["portrait"], ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(name_length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
map_data[color]["heroes"]["name"] = h3m_data.read(name_length)
|
||||
|
@ -121,7 +121,7 @@ def extract(filename):
|
|||
(map_data["heroes_count"], ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if map_data["heroes_count"] > 0:
|
||||
map_data["free_heroes"] = []
|
||||
for i in xrange(map_data["heroes_count"]):
|
||||
for i in range(map_data["heroes_count"]):
|
||||
(hero_id, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(hero_portrait, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(name_length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
|
@ -143,7 +143,7 @@ def extract(filename):
|
|||
(map_data["rumor_count"], ) = struct.unpack("<I", h3m_data.read(4))
|
||||
if map_data["rumor_count"] > 0:
|
||||
map_data["rumors"] = []
|
||||
for i in xrange(map_data["rumor_count"]):
|
||||
for i in range(map_data["rumor_count"]):
|
||||
(name_length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
rumor_name = h3m_data.read(name_length)
|
||||
(text_length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
|
@ -151,7 +151,7 @@ def extract(filename):
|
|||
map_data["rumors"].append({"name":rumor_name, "text":rumor_text})
|
||||
|
||||
#hero options
|
||||
for i in xrange(156):
|
||||
for i in range(156):
|
||||
(hero_enable, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if hero_enable == 1:
|
||||
(isExp, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
|
@ -160,7 +160,7 @@ def extract(filename):
|
|||
(isSecSkill, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isSecSkill == 0x01:
|
||||
(skills_count) = struct.unpack("<I", h3m_data.read(4))
|
||||
for i in xrange(skills_count):
|
||||
for i in range(skills_count):
|
||||
(skill_id, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(skill_lvl, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(isArtifact, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
|
@ -178,24 +178,24 @@ def extract(filename):
|
|||
if isPrimarySkills == 0x01:
|
||||
(attack, defense, power, knowledge) = struct.unpack("<4B", h3m_data.read(4))
|
||||
|
||||
map_data["upper_terrain"] = [[] for i in xrange(map_data["map_size"])]
|
||||
map_data["upper_terrain"] = [[] for i in range(map_data["map_size"])]
|
||||
#read upper world
|
||||
for i in xrange(map_data["map_size"]**2):
|
||||
for i in range(map_data["map_size"]**2):
|
||||
x = i%map_data["map_size"]
|
||||
y = (i-x)/map_data["map_size"]
|
||||
map_data["upper_terrain"][y].append(struct.unpack("<7B", h3m_data.read(7)))
|
||||
|
||||
#read underworld
|
||||
if map_data["underworld"]:
|
||||
map_data["lower_terrain"] = [[] for i in xrange(map_data["map_size"])]
|
||||
for i in xrange(map_data["map_size"]**2):
|
||||
map_data["lower_terrain"] = [[] for i in range(map_data["map_size"])]
|
||||
for i in range(map_data["map_size"]**2):
|
||||
x = i%map_data["map_size"]
|
||||
y = (i-x)/map_data["map_size"]
|
||||
map_data["lower_terrain"][y].append(struct.unpack("<7B", h3m_data.read(7)))
|
||||
|
||||
(map_data["object_count"], ) = struct.unpack("<I", h3m_data.read(4))
|
||||
map_data["objects"] = []
|
||||
for i in xrange(map_data["object_count"]):
|
||||
for i in range(map_data["object_count"]):
|
||||
(length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
filename = h3m_data.read(length)
|
||||
h3m_data.read(6) #passability
|
||||
|
@ -213,15 +213,15 @@ def extract(filename):
|
|||
(map_data["tunedobj_count"], ) = struct.unpack("<I", h3m_data.read(4))
|
||||
|
||||
map_data["tunedobj"] = []
|
||||
for i in xrange(map_data["tunedobj_count"]):
|
||||
for i in range(map_data["tunedobj_count"]):
|
||||
(x, y, z) = struct.unpack("<3B", h3m_data.read(3))
|
||||
(object_id, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
#print x,y,z,object_id,
|
||||
junk = h3m_data.read(5) #junk
|
||||
if junk != "\x00\x00\x00\x00\x00":
|
||||
for c in junk:
|
||||
print "%02d"%ord(c),
|
||||
break
|
||||
#if junk != "\x00\x00\x00\x00\x00":
|
||||
# for c in junk:
|
||||
# print("%02d"%ord(c), end=' ')
|
||||
# break
|
||||
#print i, map_data["objects"][object_id]["filename"],
|
||||
#print map_data["objects"][object_id]["class"]
|
||||
|
||||
|
@ -241,7 +241,7 @@ def extract(filename):
|
|||
text = h3m_data.read(length)
|
||||
(isGuards, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isGuards == 0x01:
|
||||
for i in xrange(7):
|
||||
for i in range(7):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
h3m_data.read(4) #junk
|
||||
(quantity, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
|
@ -261,12 +261,12 @@ def extract(filename):
|
|||
(isSecSkill, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isSecSkill == 0x01:
|
||||
(skills_count, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
for i in xrange(skills_count):
|
||||
for i in range(skills_count):
|
||||
(skill_id, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(skill_lvl, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(isCreature, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isCreature == 0x01:
|
||||
for i in xrange(7):
|
||||
for i in range(7):
|
||||
(guard_id, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
(guard_count, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
(creaturesFormation, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
|
@ -279,7 +279,7 @@ def extract(filename):
|
|||
= struct.unpack("<19H", h3m_data.read(38))
|
||||
(knapsack_count, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
if knapsack_count > 0:
|
||||
for i in xrange(knapsack_count):
|
||||
for i in range(knapsack_count):
|
||||
(knapsackID, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
(zoneRadius, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(isBiography, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
|
@ -303,7 +303,7 @@ def extract(filename):
|
|||
text = h3m_data.read(length)
|
||||
(isGuards, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isGuards == 0x01:
|
||||
for i in xrange(7):
|
||||
for i in range(7):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
h3m_data.read(4) #junk
|
||||
(spell_id, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
|
@ -335,7 +335,7 @@ def extract(filename):
|
|||
name = h3m_data.read(length)
|
||||
(isGuard, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isGuard == 0x01:
|
||||
for i in xrange(7):
|
||||
for i in range(7):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
(formation, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(isBuildings, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
|
@ -348,7 +348,7 @@ def extract(filename):
|
|||
canSpells = struct.unpack("<9B", h3m_data.read(9))
|
||||
(eventQuantity, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
if eventQuantity > 0:
|
||||
for i in xrange(eventQuantity):
|
||||
for i in range(eventQuantity):
|
||||
(length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
event_name = h3m_data.read(length)
|
||||
(length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
|
@ -369,12 +369,12 @@ def extract(filename):
|
|||
text = h3m_data.read(length)
|
||||
(isGuards, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isGuards == 0x01:
|
||||
for i in xrange(7):
|
||||
for i in range(7):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
h3m_data.read(4) #junk
|
||||
elif map_data["objects"][object_id]["class"] in (33, 219):
|
||||
(color, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
for i in xrange(7):
|
||||
for i in range(7):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
(undeleteSoldiers, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
h3m_data.read(8)
|
||||
|
@ -395,11 +395,11 @@ def extract(filename):
|
|||
(monster_id, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
elif quest == 0x05:
|
||||
(art_quantity, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
for i in xrange(art_quantity):
|
||||
for i in range(art_quantity):
|
||||
(art, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
elif quest == 0x06:
|
||||
(creatures_quantity, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
for i in xrange(creatures_quantity):
|
||||
for i in range(creatures_quantity):
|
||||
(guard_id, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
(guard_count, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
elif quest == 0x07:
|
||||
|
@ -473,11 +473,11 @@ def extract(filename):
|
|||
(monster_id, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
elif quest == 0x05:
|
||||
(art_quantity, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
for i in xrange(art_quantity):
|
||||
for i in range(art_quantity):
|
||||
(art, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
elif quest == 0x06:
|
||||
(creatures_quantity, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
for i in xrange(creatures_quantity):
|
||||
for i in range(creatures_quantity):
|
||||
(guard_id, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
(guard_count, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
elif quest == 0x07:
|
||||
|
@ -518,7 +518,7 @@ def extract(filename):
|
|||
text = h3m_data.read(length)
|
||||
(isGuards, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isGuards == 0x01:
|
||||
for i in xrange(7):
|
||||
for i in range(7):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
h3m_data.read(4) #junk
|
||||
(exp, spell_points, morals, luck, wood, mercury, ore, sulfur,
|
||||
|
@ -526,19 +526,19 @@ def extract(filename):
|
|||
struct.unpack("<IIBBIIIIIIIBBBB", h3m_data.read(42))
|
||||
(secSkills, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if secSkills > 0:
|
||||
for i in xrange(secSkills):
|
||||
for i in range(secSkills):
|
||||
(skill_id, skill_lvl) = struct.unpack("<BB", h3m_data.read(2))
|
||||
(artefacts, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if artefacts > 0:
|
||||
for i in xrange(artefacts):
|
||||
for i in range(artefacts):
|
||||
(artID, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
(spells, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if spells > 0:
|
||||
for i in xrange(spells):
|
||||
for i in range(spells):
|
||||
(spellID, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(monsters, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if monsters > 0:
|
||||
for i in xrange(monsters):
|
||||
for i in range(monsters):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
h3m_data.read(8) #junk
|
||||
elif map_data["objects"][object_id]["class"] == 26:
|
||||
|
@ -548,7 +548,7 @@ def extract(filename):
|
|||
text = h3m_data.read(length)
|
||||
(isGuards, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if isGuards == 0x01:
|
||||
for i in xrange(7):
|
||||
for i in range(7):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
h3m_data.read(4) #junk
|
||||
(exp, spell_points, morals, luck, wood, mercury, ore, sulfur,
|
||||
|
@ -556,19 +556,19 @@ def extract(filename):
|
|||
struct.unpack("<IIBBIIIIIIIBBBB", h3m_data.read(42))
|
||||
(secSkills, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if secSkills > 0:
|
||||
for i in xrange(secSkills):
|
||||
for i in range(secSkills):
|
||||
(skill_id, skill_lvl) = struct.unpack("<BB", h3m_data.read(2))
|
||||
(artefacts, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if artefacts > 0:
|
||||
for i in xrange(artefacts):
|
||||
for i in range(artefacts):
|
||||
(artID, ) = struct.unpack("<H", h3m_data.read(2))
|
||||
(spells, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if spells > 0:
|
||||
for i in xrange(spells):
|
||||
for i in range(spells):
|
||||
(spellID, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
(monsters, ) = struct.unpack("<B", h3m_data.read(1))
|
||||
if monsters > 0:
|
||||
for i in xrange(monsters):
|
||||
for i in range(monsters):
|
||||
(guard_id, guard_count) = struct.unpack("<HH", h3m_data.read(4))
|
||||
h3m_data.read(8) #junk
|
||||
(players, isAICan, disableAfterFirstDay) = struct.unpack("<BBB", h3m_data.read(3))
|
||||
|
@ -576,7 +576,7 @@ def extract(filename):
|
|||
|
||||
try:
|
||||
(gevents_count, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
for i in xrange(gevents_count):
|
||||
for i in range(gevents_count):
|
||||
(length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
name = h3m_data.read(length)
|
||||
(length, ) = struct.unpack("<I", h3m_data.read(4))
|
||||
|
@ -589,7 +589,7 @@ def extract(filename):
|
|||
(event_iteration,) = struct.unpack("<H", h3m_data.read(2))
|
||||
h3m_data.read(16) #junk
|
||||
except:
|
||||
print "d'ough...'"
|
||||
print("d'ough...'")
|
||||
|
||||
h3m_data.read(124) #junk
|
||||
|
||||
|
|
110
lib/mapset.py
110
lib/mapset.py
|
@ -69,7 +69,7 @@ class Animation(object):
|
|||
memmove(buf, img._current_data, len(img._current_data))
|
||||
data = buf.raw
|
||||
rows = [data[i:i + abs(data_pitch)] for i in
|
||||
xrange(len(img._current_data)-abs(data_pitch),
|
||||
range(len(img._current_data)-abs(data_pitch),
|
||||
-1, -abs(data_pitch))]
|
||||
self.__frames.append(''.join(rows))
|
||||
self.__animation = 0
|
||||
|
@ -113,32 +113,32 @@ class MapSet(object):
|
|||
|
||||
def __init__(self, map_name):
|
||||
h3m_data = h3m.extract(os.path.join(pyglet.resource._default_loader._script_home,"maps","%s.h3m" % map_name))
|
||||
edge_map = [[] for i in xrange(len(h3m_data["upper_terrain"])+16)]
|
||||
for num in xrange(len(edge_map)):
|
||||
edge_map = [[] for i in range(len(h3m_data["upper_terrain"])+16)]
|
||||
for num in range(len(edge_map)):
|
||||
if num < 7 or num > len(edge_map)-8:
|
||||
line = []
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in xrange(len(h3m_data["upper_terrain"][0])+18)])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in range(len(h3m_data["upper_terrain"][0])+18)])
|
||||
elif num == 7:
|
||||
line = []
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in xrange(8)])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in range(8)])
|
||||
line.append([-1, 16, 0, 0, 0, 0, 0])
|
||||
line.extend([[-1, 20+i%4, 0, 0, 0, 0, 0] for i in xrange(len(h3m_data["upper_terrain"][0]))])
|
||||
line.extend([[-1, 20+i%4, 0, 0, 0, 0, 0] for i in range(len(h3m_data["upper_terrain"][0]))])
|
||||
line.append([-1, 17, 0, 0, 0, 0, 0])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in xrange(8)])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in range(8)])
|
||||
elif num == len(edge_map)-8:
|
||||
line = []
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in xrange(8)])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in range(8)])
|
||||
line.append([-1, 19, 0, 0, 0, 0, 0])
|
||||
line.extend([[-1, 28+i%4, 0, 0, 0, 0, 0] for i in xrange(len(h3m_data["upper_terrain"][0]))])
|
||||
line.extend([[-1, 28+i%4, 0, 0, 0, 0, 0] for i in range(len(h3m_data["upper_terrain"][0]))])
|
||||
line.append([-1, 18, 0, 0, 0, 0, 0])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in xrange(8)])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in range(8)])
|
||||
else:
|
||||
line = []
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in xrange(8)])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in range(8)])
|
||||
line.append([-1, 32+num%4, 0, 0, 0, 0, 0])
|
||||
line.extend(h3m_data["upper_terrain"][num-8])
|
||||
line.append([-1, 24+num%4, 0, 0, 0, 0, 0])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in xrange(8)])
|
||||
line.extend([[-1, 0+(i-1)%4+4*(num%4), 0, 0, 0, 0, 0] for i in range(8)])
|
||||
edge_map[num] = line
|
||||
h3m_data["upper_terrain"] = edge_map
|
||||
|
||||
|
@ -154,12 +154,12 @@ class MapSet(object):
|
|||
for y, line in enumerate(h3m_data["upper_terrain"]):
|
||||
for x, tile in enumerate(line):
|
||||
if tile[0] == -1: #edge
|
||||
if "edg" not in tile_textures.keys():
|
||||
tile_textures["edg"] = [self.load_map_object('data/advmap_tiles/edg.def/%d.png'%i, 100) for i in xrange(36)]
|
||||
if "edg" not in list(tile_textures.keys()):
|
||||
tile_textures["edg"] = [self.load_map_object('data/advmap_tiles/edg.def/%d.png'%i, 100) for i in range(36)]
|
||||
self.__tiles[x,y] = [tile_textures["edg"][tile[1]]]
|
||||
elif tile[0] == 0: #dirt
|
||||
if "dirttl" not in tile_textures.keys():
|
||||
tile_textures["dirttl"] = [self.load_map_object('data/advmap_tiles/dirttl.def/%d.png'%i, 0) for i in xrange(46)]
|
||||
if "dirttl" not in list(tile_textures.keys()):
|
||||
tile_textures["dirttl"] = [self.load_map_object('data/advmap_tiles/dirttl.def/%d.png'%i, 0) for i in range(46)]
|
||||
flip_x = bool(tile[6] & 1)
|
||||
flip_y = bool(tile[6] & 2)
|
||||
if flip_x or flip_y:
|
||||
|
@ -169,12 +169,12 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x,y] = [tile_textures["dirttl"][tile[1]]]
|
||||
elif tile[0] == 1: #sand
|
||||
if "sandtl" not in tile_textures.keys():
|
||||
tile_textures["sandtl"] = [self.load_map_object('data/advmap_tiles/sandtl.def/%d.png'%i, 0) for i in xrange(24)]
|
||||
if "sandtl" not in list(tile_textures.keys()):
|
||||
tile_textures["sandtl"] = [self.load_map_object('data/advmap_tiles/sandtl.def/%d.png'%i, 0) for i in range(24)]
|
||||
self.__tiles[x,y] = [tile_textures["sandtl"][tile[1]]]
|
||||
elif tile[0] == 2: #grass
|
||||
if "grastl" not in tile_textures.keys():
|
||||
tile_textures["grastl"] = [self.load_map_object('data/advmap_tiles/grastl.def/%d.png'%i, 0) for i in xrange(79)]
|
||||
if "grastl" not in list(tile_textures.keys()):
|
||||
tile_textures["grastl"] = [self.load_map_object('data/advmap_tiles/grastl.def/%d.png'%i, 0) for i in range(79)]
|
||||
flip_x = bool(tile[6] & 1)
|
||||
flip_y = bool(tile[6] & 2)
|
||||
if flip_x or flip_y:
|
||||
|
@ -184,8 +184,8 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x,y] = [tile_textures["grastl"][tile[1]]]
|
||||
elif tile[0] == 3: #snow
|
||||
if "snowtl" not in tile_textures.keys():
|
||||
tile_textures["snowtl"] = [self.load_map_object('data/advmap_tiles/snowtl.def/%d.png'%i, 0) for i in xrange(79)]
|
||||
if "snowtl" not in list(tile_textures.keys()):
|
||||
tile_textures["snowtl"] = [self.load_map_object('data/advmap_tiles/snowtl.def/%d.png'%i, 0) for i in range(79)]
|
||||
flip_x = bool(tile[6] & 1)
|
||||
flip_y = bool(tile[6] & 2)
|
||||
if flip_x or flip_y:
|
||||
|
@ -195,8 +195,8 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x,y] = [tile_textures["snowtl"][tile[1]]]
|
||||
elif tile[0] == 4: #swamp
|
||||
if "swmptl" not in tile_textures.keys():
|
||||
tile_textures["swmptl"] = [self.load_map_object('data/advmap_tiles/swmptl.def/%d.png'%i, 0) for i in xrange(79)]
|
||||
if "swmptl" not in list(tile_textures.keys()):
|
||||
tile_textures["swmptl"] = [self.load_map_object('data/advmap_tiles/swmptl.def/%d.png'%i, 0) for i in range(79)]
|
||||
flip_x = bool(tile[6] & 1)
|
||||
flip_y = bool(tile[6] & 2)
|
||||
if flip_x or flip_y:
|
||||
|
@ -206,8 +206,8 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x,y] = [tile_textures["swmptl"][tile[1]]]
|
||||
elif tile[0] == 5: #rough
|
||||
if "rougtl" not in tile_textures.keys():
|
||||
tile_textures["rougtl"] = [self.load_map_object('data/advmap_tiles/rougtl.def/%d.png'%i, 0) for i in xrange(79)]
|
||||
if "rougtl" not in list(tile_textures.keys()):
|
||||
tile_textures["rougtl"] = [self.load_map_object('data/advmap_tiles/rougtl.def/%d.png'%i, 0) for i in range(79)]
|
||||
flip_x = bool(tile[6] & 1)
|
||||
flip_y = bool(tile[6] & 2)
|
||||
if flip_x or flip_y:
|
||||
|
@ -217,8 +217,8 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x,y] = [tile_textures["rougtl"][tile[1]]]
|
||||
elif tile[0] == 7: #lava
|
||||
if "lavatl" not in tile_textures.keys():
|
||||
tile_textures["lavatl"] = [self.load_map_object('data/advmap_tiles/lavatl.def/%d.png'%i, 0) for i in xrange(79)]
|
||||
if "lavatl" not in list(tile_textures.keys()):
|
||||
tile_textures["lavatl"] = [self.load_map_object('data/advmap_tiles/lavatl.def/%d.png'%i, 0) for i in range(79)]
|
||||
flip_x = bool(tile[6] & 1)
|
||||
flip_y = bool(tile[6] & 2)
|
||||
if flip_x or flip_y:
|
||||
|
@ -228,9 +228,9 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x,y] = [tile_textures["lavatl"][tile[1]]]
|
||||
elif tile[0] == 8: #water 12 anims
|
||||
if "watrtl" not in tile_textures.keys():
|
||||
textures = [self.load_map_object('data/advmap_tiles/watrtl.def/%d/0.png'%i, 0) for i in xrange(33)]
|
||||
images = [[pyglet.image.load(None, file=pyglet.resource.file('data/advmap_tiles/watrtl.def/%d/%d.png'%(i,j))) for j in xrange(12)] for i in xrange(33)]
|
||||
if "watrtl" not in list(tile_textures.keys()):
|
||||
textures = [self.load_map_object('data/advmap_tiles/watrtl.def/%d/0.png'%i, 0) for i in range(33)]
|
||||
images = [[pyglet.image.load(None, file=pyglet.resource.file('data/advmap_tiles/watrtl.def/%d/%d.png'%(i,j))) for j in range(12)] for i in range(33)]
|
||||
tile_textures["watrtl"] = {
|
||||
(0,0):[Animation(texture, images[i]) for i, texture in enumerate(textures)],
|
||||
(1,0):[Animation(texture, images[i], flip_x=True) for i, texture in enumerate(textures)],
|
||||
|
@ -241,8 +241,8 @@ class MapSet(object):
|
|||
flip_y = (tile[6]>>1)&1
|
||||
self.__tiles[x,y] = [tile_textures["watrtl"][flip_x, flip_y][tile[1]]]
|
||||
elif tile[0] == 9: #rock
|
||||
if "rocktl" not in tile_textures.keys():
|
||||
tile_textures["rocktl"] = [self.load_map_object('data/advmap_tiles/rocktl.def/%d.png'%i, 0) for i in xrange(48)]
|
||||
if "rocktl" not in list(tile_textures.keys()):
|
||||
tile_textures["rocktl"] = [self.load_map_object('data/advmap_tiles/rocktl.def/%d.png'%i, 0) for i in range(48)]
|
||||
self.__tiles[x,y] = [tile_textures["rocktl"][tile[1]]]
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
@ -250,9 +250,9 @@ class MapSet(object):
|
|||
if tile[2] == 0: #no river
|
||||
pass
|
||||
elif tile[2] == 1: #clrrvr 12 anims
|
||||
if "clrrvr" not in tile_textures.keys():
|
||||
textures = [self.load_map_object('data/advmap_tiles/clrrvr.def/%d/0.png'%i, 1) for i in xrange(13)]
|
||||
images = [[pyglet.image.load(None, file=pyglet.resource.file('data/advmap_tiles/clrrvr.def/%d/%d.png'%(i,j))) for j in xrange(12)] for i in xrange(13)]
|
||||
if "clrrvr" not in list(tile_textures.keys()):
|
||||
textures = [self.load_map_object('data/advmap_tiles/clrrvr.def/%d/0.png'%i, 1) for i in range(13)]
|
||||
images = [[pyglet.image.load(None, file=pyglet.resource.file('data/advmap_tiles/clrrvr.def/%d/%d.png'%(i,j))) for j in range(12)] for i in range(13)]
|
||||
tile_textures["clrrvr"] = {
|
||||
(0,0):[Animation(texture, images[i]) for i, texture in enumerate(textures)],
|
||||
(1,0):[Animation(texture, images[i], flip_x=True) for i, texture in enumerate(textures)],
|
||||
|
@ -263,8 +263,8 @@ class MapSet(object):
|
|||
flip_y = (tile[6]>>3)&1
|
||||
self.__tiles[x,y].append(tile_textures["clrrvr"][flip_x, flip_y][tile[3]])
|
||||
elif tile[2] == 2: #icyrvr
|
||||
if "icyrvr" not in tile_textures.keys():
|
||||
tile_textures["icyrvr"] = [self.load_map_object('data/advmap_tiles/icyrvr.def/%d.png'%i, 1) for i in xrange(13)]
|
||||
if "icyrvr" not in list(tile_textures.keys()):
|
||||
tile_textures["icyrvr"] = [self.load_map_object('data/advmap_tiles/icyrvr.def/%d.png'%i, 1) for i in range(13)]
|
||||
flip_x = bool(tile[6] & 4)
|
||||
flip_y = bool(tile[6] & 8)
|
||||
if flip_x or flip_y:
|
||||
|
@ -274,9 +274,9 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x, y].append(tile_textures["icyrvr"][tile[3]])
|
||||
elif tile[2] == 3: #mudrvr
|
||||
if "mudrvr" not in tile_textures.keys():
|
||||
textures = [self.load_map_object('data/advmap_tiles/mudrvr.def/%d/0.png'%i, 1) for i in xrange(13)]
|
||||
images = [[pyglet.image.load(None, file=pyglet.resource.file('data/advmap_tiles/clrrvr.def/%d/%d.png'%(i,j))) for j in xrange(12)] for i in xrange(13)]
|
||||
if "mudrvr" not in list(tile_textures.keys()):
|
||||
textures = [self.load_map_object('data/advmap_tiles/mudrvr.def/%d/0.png'%i, 1) for i in range(13)]
|
||||
images = [[pyglet.image.load(None, file=pyglet.resource.file('data/advmap_tiles/clrrvr.def/%d/%d.png'%(i,j))) for j in range(12)] for i in range(13)]
|
||||
tile_textures["mudrvr"] = {
|
||||
(0,0):[Animation(texture, images[i]) for i, texture in enumerate(textures)],
|
||||
(1,0):[Animation(texture, images[i], flip_x=True) for i, texture in enumerate(textures)],
|
||||
|
@ -287,9 +287,9 @@ class MapSet(object):
|
|||
flip_y = (tile[6]>>3)&1
|
||||
self.__tiles[x,y].append(tile_textures["mudrvr"][flip_x, flip_y][tile[3]])
|
||||
elif tile[2] == 4: #lavrvr
|
||||
if "lavrvr" not in tile_textures.keys():
|
||||
textures = [self.load_map_object('data/advmap_tiles/lavrvr.def/%d/0.png'%i, 1) for i in xrange(13)]
|
||||
images = [[pyglet.image.load(None, file=pyglet.resource.file('data/advmap_tiles/clrrvr.def/%d/%d.png'%(i,j))) for j in xrange(9)] for i in xrange(13)]
|
||||
if "lavrvr" not in list(tile_textures.keys()):
|
||||
textures = [self.load_map_object('data/advmap_tiles/lavrvr.def/%d/0.png'%i, 1) for i in range(13)]
|
||||
images = [[pyglet.image.load(None, file=pyglet.resource.file('data/advmap_tiles/clrrvr.def/%d/%d.png'%(i,j))) for j in range(9)] for i in range(13)]
|
||||
tile_textures["lavrvr"] = {
|
||||
(0,0):[Animation(texture, images[i]) for i, texture in enumerate(textures)],
|
||||
(1,0):[Animation(texture, images[i], flip_x=True) for i, texture in enumerate(textures)],
|
||||
|
@ -300,13 +300,13 @@ class MapSet(object):
|
|||
flip_y = (tile[6]>>3)&1
|
||||
self.__tiles[x,y].append(tile_textures["lavrvr"][flip_x, flip_y][tile[3]])
|
||||
else:
|
||||
raise NotImplementedError, tile[2]
|
||||
raise NotImplementedError(tile[2])
|
||||
|
||||
if tile[4] == 0: #no road
|
||||
pass
|
||||
elif tile[4] == 1: #dirtrd
|
||||
if "dirtrd" not in tile_textures.keys():
|
||||
tile_textures["dirtrd"] = [self.load_map_object('data/advmap_tiles/dirtrd.def/%d.png'%i, 1) for i in xrange(17)]
|
||||
if "dirtrd" not in list(tile_textures.keys()):
|
||||
tile_textures["dirtrd"] = [self.load_map_object('data/advmap_tiles/dirtrd.def/%d.png'%i, 1) for i in range(17)]
|
||||
flip_x = bool(tile[6] & 16)
|
||||
flip_y = bool(tile[6] & 32)
|
||||
if flip_x or flip_y:
|
||||
|
@ -316,8 +316,8 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x, y].append(tile_textures["dirtrd"][tile[5]])
|
||||
elif tile[4] == 2: #gravrd
|
||||
if "gravrd" not in tile_textures.keys():
|
||||
tile_textures["gravrd"] = [self.load_map_object('data/advmap_tiles/gravrd.def/%d.png'%i, 1) for i in xrange(17)]
|
||||
if "gravrd" not in list(tile_textures.keys()):
|
||||
tile_textures["gravrd"] = [self.load_map_object('data/advmap_tiles/gravrd.def/%d.png'%i, 1) for i in range(17)]
|
||||
flip_x = bool(tile[6] & 16)
|
||||
flip_y = bool(tile[6] & 32)
|
||||
if flip_x or flip_y:
|
||||
|
@ -327,8 +327,8 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x, y].append(tile_textures["gravrd"][tile[5]])
|
||||
elif tile[4] == 3: #cobbrd
|
||||
if "cobbrd" not in tile_textures.keys():
|
||||
tile_textures["cobbrd"] = [self.load_map_object('data/advmap_tiles/cobbrd.def/%d.png'%i, 1) for i in xrange(17)]
|
||||
if "cobbrd" not in list(tile_textures.keys()):
|
||||
tile_textures["cobbrd"] = [self.load_map_object('data/advmap_tiles/cobbrd.def/%d.png'%i, 1) for i in range(17)]
|
||||
flip_x = bool(tile[6] & 16)
|
||||
flip_y = bool(tile[6] & 32)
|
||||
if flip_x or flip_y:
|
||||
|
@ -338,7 +338,7 @@ class MapSet(object):
|
|||
else:
|
||||
self.__tiles[x, y].append(tile_textures["cobbrd"][tile[5]])
|
||||
else:
|
||||
raise NotImplementedError, tile[4]
|
||||
raise NotImplementedError(tile[4])
|
||||
|
||||
images = []
|
||||
for order, obj in enumerate(h3m_data["objects"]):
|
||||
|
@ -347,7 +347,7 @@ class MapSet(object):
|
|||
while 1:
|
||||
imgs.append(pyglet.image.load(None, file=pyglet.resource.file("data/advmap_objects/" + obj["filename"] + "/%d.png"%i)))
|
||||
i += 1
|
||||
if "data/advmap_objects/" + obj["filename"] + "/%d.png" % i not in pyglet.resource._default_loader._index.keys():
|
||||
if "data/advmap_objects/" + obj["filename"] + "/%d.png" % i not in list(pyglet.resource._default_loader._index.keys()):
|
||||
break;
|
||||
images.append((imgs, order))
|
||||
|
||||
|
@ -372,9 +372,9 @@ class MapSet(object):
|
|||
self.__tiles[obj["x"] + 9,obj["y"] + 8].append(self.objects[obj["id"]])
|
||||
|
||||
def get_tiles(self, tiles_x, tiles_y, div_x, div_y):
|
||||
for y in xrange(tiles_y - 1, -6, -1):
|
||||
for y in range(tiles_y - 1, -6, -1):
|
||||
y1 = y * 32
|
||||
for x in xrange(tiles_x + 5 - 1, -1, -1):
|
||||
for x in range(tiles_x + 5 - 1, -1, -1):
|
||||
for obj in self.__tiles.get((x - div_x, div_y - y), []):
|
||||
x1 = x * 32 - obj.width + 32
|
||||
x2 = x1 + obj.width
|
||||
|
|
|
@ -21,7 +21,9 @@ import pyglet
|
|||
|
||||
class Window(pyglet.window.Window):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Window, self).__init__(1280, 1024, resizable=True, vsync=False)
|
||||
width = kwargs.get("width", 1024)
|
||||
height = kwargs.get("height", 768)
|
||||
super(Window, self).__init__(width, height, resizable=True, vsync=False)
|
||||
self.keys = pyglet.window.key.KeyStateHandler()
|
||||
self.push_handlers(self.keys)
|
||||
self.fps = pyglet.clock.ClockDisplay()
|
||||
|
@ -45,8 +47,5 @@ class PNGRGBEncoder(pyglet.image.codecs.ImageEncoder):
|
|||
pitch = -(image.width * len(format))
|
||||
pil_image = Image.fromstring(
|
||||
format, (image.width, image.height), image.get_data(format, pitch))
|
||||
try:
|
||||
#.convert('P', palette=Image.WEB)
|
||||
pil_image.convert("RGB").save(file)
|
||||
except Exception, e:
|
||||
raise ImageEncodeException(e)
|
||||
#.convert('P', palette=Image.WEB)
|
||||
pil_image.convert("RGB").save(file)
|
||||
|
|
Loading…
Reference in a new issue