annotate pytouhou/formats/sht.py @ 605:d6ead6f0ba80

Mention Python 3 in the README…
author Thibaut Girka <thib@sitedethib.com>
date Tue, 11 Nov 2014 17:06:50 +0100
parents e15672733c93
children d1f0bb0b7a17
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 ##
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 ##
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 ##
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ## GNU General Public License for more details.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ##
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 from struct import unpack
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 from pytouhou.utils.helpers import get_logger
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 logger = get_logger(__name__)
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 class Shot(object):
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 def __init__(self):
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
24 self.interval = 0
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
25 self.delay = 0
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 self.pos = (0., 0.)
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 self.hitbox = (0., 0.)
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 self.angle = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 self.speed = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 self.damage = 0
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 self.orb = 0
235
e59bd7979ddc Do a little cleanup, and fix PCB SHT usage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 229
diff changeset
32 self.type = 0
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
33 self.sprite = 0
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
34 self.unknown1 = None
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 self.unknown2 = None
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 self.unknown3 = None
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 self.unknown4 = None
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 self.unknown5 = None
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 class SHT(object):
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 def __init__(self):
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 self.unknown1 = None
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 self.bombs = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 self.unknown2 = None
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 self.hitbox = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 self.graze_hitbox = 0.
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
48 self.autocollection_speed = 0.
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 self.item_hitbox = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 self.percentage_of_cherry_loss_on_die = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 self.point_of_collection = 0
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 self.horizontal_vertical_speed = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 self.horizontal_vertical_focused_speed = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 self.diagonal_speed = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 self.diagonal_focused_speed = 0.
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 self.shots = {}
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 @classmethod
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 def read(cls, file):
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
61 sht = cls()
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
62
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
63 data = unpack('<hhfI10f', file.read(52))
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
64 (sht.unknown1, level_count, sht.bombs, sht.unknown2, sht.hitbox,
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
65 sht.graze_hitbox, sht.autocollection_speed, sht.item_hitbox,
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
66 sht.percentage_of_cherry_loss_on_die, sht.point_of_collection,
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
67 sht.horizontal_vertical_speed, sht.horizontal_vertical_focused_speed,
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
68 sht.diagonal_speed, sht.diagonal_focused_speed) = data
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 levels = []
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 235
diff changeset
71 for i in range(level_count):
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 offset, power = unpack('<II', file.read(8))
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 levels.append((power, offset))
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 sht.shots = {}
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 for power, offset in levels:
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 sht.shots[power] = []
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 file.seek(offset)
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 while True:
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
82 interval, delay = unpack('<HH', file.read(4))
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
83 if interval == 0xffff and delay == 0xffff:
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 break
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 shot = Shot()
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
88 shot.interval = interval
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
89 shot.delay = delay
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
90
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
91 data = unpack('<6fHBBhh4I', file.read(48))
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 (x, y, hitbox_x, hitbox_y, shot.angle, shot.speed,
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
93 shot.damage, shot.orb, shot.shot_type, shot.sprite,
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
94 shot.unknown1, shot.unknown2, shot.unknown3, shot.unknown4,
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
95 shot.unknown5) = data
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 shot.pos = (x, y)
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 shot.hitbox = (hitbox_x, hitbox_y)
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 214
diff changeset
100 sht.shots[power].append(shot)
214
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 return sht
136d29ffe3c2 Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104