-
Notifications
You must be signed in to change notification settings - Fork 0
/
Types.hs
131 lines (101 loc) · 3.08 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{-# LANGUAGE DataKinds, FlexibleContexts, FlexibleInstances, KindSignatures, ScopedTypeVariables, TemplateHaskell #-}
module Types where
import Control.Lens
import Control.Monad.Reader
import Data.Word
import System.Exit
import System.IO
import Nat
import Vector
type Offset = Integer
data ListOffset = ListOffset Integer Integer
deriving Show
data Dummy = Dummy
type FileIO = ReaderT Handle IO
type PlaceIO = ReaderT Offset FileIO
absSeek :: Offset -> FileIO ()
absSeek off = ReaderT $ \handle -> hSeek handle AbsoluteSeek off
tell :: FileIO Integer
tell = ReaderT hTell
seekAndDo :: Offset -> FileIO a -> PlaceIO a
seekAndDo off m = do
ReaderT $ \mrk -> absSeek (mrk+off)
lift m
syncThenLift :: FileIO a -> PlaceIO a
syncThenLift = seekAndDo 0
syncHandle = syncThenLift $ return ()
class MyLength a where
myLength :: a -> Integer
instance MyLength (Vector Zero Char) where
myLength _ = 0
instance forall (n::Nat) . MyLength (Vector n Char) => MyLength (Vector (Succ n) Char) where
myLength _ = 1 + myLength (undefined :: Vector n Char)
type PosRot = Vector Nat20 Char
type PosRotScale = Vector Nat32 Char
data GoalType = BlueG | GreenG | RedG | UnknownG
deriving Show
type StartPos = PosRot
type Bumper = PosRotScale
type Jamabar = PosRotScale
type Banana = Vector Nat16 Char
type Cone = Vector Nat32 Char
type Sphere = Vector Nat20 Char
type Cylinder = Vector Nat28 Char
data Goal = Goal (Vector Nat18 Char) GoalType
deriving Show
type LevelModel = String
type ReflectiveModel = String
type Triangle = Vector Nat64 Char
type CollisionParameters = Vector Nat24 Char
data AnimFrame = AnimFrame {
_easing :: Vector Nat4 Char ,
_time :: Float ,
_value :: Float ,
_animFrameUnknown :: Vector Nat8 Char
} deriving Show
makeLenses ''AnimFrame
data AnimData = AnimData {
_rotXFrames :: [AnimFrame] ,
_rotYFrames :: [AnimFrame] ,
_rotZFrames :: [AnimFrame] ,
_posXFrames :: [AnimFrame] ,
_posYFrames :: [AnimFrame] ,
_posZFrames :: [AnimFrame]
}
makeLenses ''AnimData
data CollisionHeader = CollisionHeader {
_rotCenter :: (Float,Float,Float) ,
_initRot :: (Word16,Word16,Word16) ,
_animType :: Word16 ,
_animData :: AnimData ,
_animLoopTime :: Float ,
-- Apparently redundant model reference stuff?
_triangles :: [Triangle] ,
_triangleIndexLists :: [[Word16]] ,
_collisionParameters :: CollisionParameters ,
_goalListOffset :: ListOffset ,
_bumperListOffset :: ListOffset ,
_jamabarListOffset :: ListOffset ,
_bananaListOffset :: ListOffset ,
_coneListOffset :: ListOffset ,
_sphereListOffset :: ListOffset ,
_cylinderListOffset :: ListOffset ,
_levelModelListOffset :: ListOffset ,
_reflectiveModelListOffset :: ListOffset
}
makeLenses ''CollisionHeader
data LZData = LZData {
_collisionHeaders :: [CollisionHeader] ,
_startPos :: StartPos ,
_falloutY :: Vector Nat4 Char ,
_goals :: [Goal] ,
_bumpers :: [Bumper] ,
_jamabars :: [Jamabar] ,
_bananas :: [Banana] ,
_cones :: [Cone] ,
_spheres :: [Sphere] ,
_cylinders :: [Cylinder] ,
_levelModels :: [LevelModel] ,
_reflectiveModels :: [ReflectiveModel]
}
makeLenses ''LZData