-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tilesets.fs
65 lines (57 loc) · 1.74 KB
/
Tilesets.fs
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
module Tilesets
open Types
type private CombatActorParser = CombatActorTile -> char
type private CombatMapParser = CombatMapTile -> char
type CombatTilesetParser = {
CombatActorParser: CombatActorParser
CombatMapParser: CombatMapParser
}
let (defaultTilesetParser: CombatTilesetParser) = {
CombatActorParser = fun tile ->
match tile with
| PlayerTile -> '@'
| OrcTile -> 'o'
| TrollTile -> 't'
| OgreTile -> 'O'
| UnknownActorTile -> failwith "actor tile not found in tileset"
CombatMapParser = fun tile ->
match tile with
| EmptyTile -> ' '
| OpenDoorTile -> '-'
| ClosedDoorTile -> '+'
| WallTile -> '#'
| UnknownMapTile -> failwith "map tile not found in tileset"
}
let (dottedTilesetParser: CombatTilesetParser) = {
CombatActorParser = fun tile ->
match tile with
| PlayerTile -> '@'
| OrcTile -> 'o'
| TrollTile -> 't'
| OgreTile -> 'O'
| UnknownActorTile -> failwith "actor tile not found in tileset"
CombatMapParser = fun tile ->
match tile with
| EmptyTile -> '.'
| OpenDoorTile -> '-'
| ClosedDoorTile -> '+'
| WallTile -> '#'
| UnknownMapTile -> failwith "map tile not found in tileset"
}
let convertMapTilesToString (parser: CombatMapParser) (tiles: CombatMapTile list) =
tiles
|> List.map (parser >> string)
|> List.toSeq
|> String.concat ""
let getActorTile char =
match char with
| '@' -> PlayerTile
| 'o' -> OrcTile
| _ -> UnknownActorTile
let getMapTile char =
match char with
| ' ' -> EmptyTile
| '-' -> OpenDoorTile
| '+' -> ClosedDoorTile
| '#' -> WallTile
| _ -> UnknownMapTile