comparison pytouhou/formats/sht.py @ 214:136d29ffe3c2

Add support for PCB’s SHT format.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 29 Nov 2011 23:18:07 +0100
parents
children 0595315d3880
comparison
equal deleted inserted replaced
213:9bdf116bb2a5 214:136d29ffe3c2
1 # -*- encoding: utf-8 -*-
2 ##
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published
7 ## by the Free Software Foundation; version 3 only.
8 ##
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
13 ##
14
15 from struct import unpack
16
17 from pytouhou.utils.helpers import get_logger
18
19 logger = get_logger(__name__)
20
21
22 class Shot(object):
23 def __init__(self):
24 self.interval = 0.
25 self.unknown1 = None
26 self.pos = (0., 0.)
27 self.hitbox = (0., 0.)
28 self.angle = 0.
29 self.speed = 0.
30 self.damage = 0
31 self.orb = 0
32 self.unknown2 = None
33 self.sprite = 0
34 self.unknown3 = None
35 self.unknown4 = None
36 self.homing = False
37 self.unknown5 = None
38 self.unknown6 = None
39
40
41 class SHT(object):
42 def __init__(self):
43 self.unknown1 = None
44 self.level_count = 9
45 self.bombs = 0.
46 self.unknown2 = None
47 self.hitbox = 0.
48 self.graze_hitbox = 0.
49 self.autocollected_item_speed = 0.
50 self.item_hitbox = 0.
51 self.percentage_of_cherry_loss_on_die = 0.
52 self.point_of_collection = 0
53 self.horizontal_vertical_speed = 0.
54 self.horizontal_vertical_focused_speed = 0.
55 self.diagonal_speed = 0.
56 self.diagonal_focused_speed = 0.
57 self.shots = {}
58
59
60 @classmethod
61 def read(cls, file):
62 (_, level_count, bombs, _, hitbox, graze_hitbox,
63 autocollected_item_speed, item_hitbox, percentage_of_cherry_loss_on_die,
64 point_of_collection, horizontal_vertical_speed,
65 horizontal_vertical_focused_speed, diagonal_speed,
66 diagonal_focused_speed) = unpack('<hhfI10f', file.read(52))
67
68 levels = []
69 for i in xrange(level_count):
70 offset, power = unpack('<II', file.read(8))
71 levels.append((power, offset))
72
73 sht = cls()
74 sht.shots = {}
75
76 for power, offset in levels:
77 sht.shots[power] = []
78 file.seek(offset)
79
80 while True:
81 interval, unknown1 = unpack('<HH', file.read(4))
82 if interval == 0xffff and unknown1 == 0xffff:
83 break
84
85 shot = Shot()
86
87 data = file.read(48)
88 (x, y, hitbox_x, hitbox_y, shot.angle, shot.speed,
89 shot.damage, shot.orb, shot.unknown2, shot.sprite,
90 shot.unknown3, unknown4, homing, unknown5,
91 unknown6) = unpack('<6fHBBhh4I', data)
92
93 shot.pos = (x, y)
94 shot.hitbox = (hitbox_x, hitbox_y)
95 shot.unknown4 = bool(unknown4)
96 shot.homing = bool(homing)
97 shot.unknown5 = bool(unknown5)
98 shot.unknown6 = bool(unknown6)
99
100 sht.shts[power].append(shot)
101
102
103 return sht
104