-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
134 lines (117 loc) · 4.09 KB
/
index.ts
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
131
132
133
134
import { MazeBuilder, TerrainBuilder } from './generator'
import * as fs from 'fs';
import * as yargs from 'yargs';
import { Global } from './config';
const home_location = process.env.HOME || process.env.USERPROFILE;
const argv = yargs
.option('name', {
description: 'Map name',
type: 'string'
})
.option('type', {
description: 'single, tower, multi, terrain, custom (load from file), customTerrain (load from ./customTerrain/custom.ts file)',
type: 'string'
})
.option('width', {
description: 'Width of map',
type: 'number'
})
.option('height', {
description: 'Height of map',
type: 'number'
})
.option('holes', {
description: 'Number of holes (Type: must be "multi")',
type: 'number'
})
.option('stories', {
description: 'Tower stories',
type: 'number'
})
.option('walls', {
description: 'Number of walls stacked on each other',
type: 'number'
})
.option('storyHeight', {
description: 'Height of each story (Type: must be "tower")',
type: 'number'
})
.option('basic', {
description: 'No spawns, no flagpoles',
type: 'boolean'
})
.option('evenness', {
description: 'Evenness coefficient [1 - 1000] (Lower values means rougher terrain)',
type: 'number'
})
.option('steepness', {
description: 'Terrain will have higher slopes [0 - 5]',
type: 'number'
})
.option('traps', {
description: 'Odds of spawning a trap [0.0 - 1.0] (Doesn\'t work with type=terrain)',
type: 'number'
})
.option('water', {
description: 'Add water [0,1] (Type: must be "terrain")',
type: 'number'
})
.alias('name', 'n')
.alias('type', 't')
.alias('width', 'w')
.alias('height', 'h')
.alias('basic', 'b')
.alias('evenness', 'e')
.alias('steepness', 's')
.help().argv;
if (argv.type)
Global.type = argv.type ? argv.type : 'single';
if (argv.basic)
Global.basic = argv.basic ? true : false;
if (argv.walls !== undefined)
Global.wallStacks = argv.walls;
if (argv.storyHeight)
Global.storyHeight = argv.storyHeight;
if (argv.evenness !== undefined)
Global.evennessCoefficient = argv.evenness >= 1000 ? 1000 : argv.evenness <= 0 ? 0 : argv.evenness;
if (argv.steepness)
Global.steepness = argv.steepness;// >= 5 ? 5 : argv.steepness <= 0 ? 0 : argv.steepness;
if (argv.traps !== undefined)
Global.trapProbability = argv.traps >= 1 ? 1 : argv.traps <= 0 ? 0 : argv.traps;
if (argv.water)
Global.water = argv.water;
const mazebuilder = new MazeBuilder(argv.name, argv.width, argv.height);
const terrainbuilder = new TerrainBuilder(argv.name, argv.width, argv.height);
switch (argv.type) {
case 'single':
fs.writeFileSync('Map', mazebuilder.build()); // Single Maze
break;
case 'tower':
fs.writeFileSync('Map', mazebuilder.buildTower(argv.stories)); // Tower
break;
case 'multi':
fs.writeFileSync('Map', mazebuilder.buildMultiple(argv.holes)); // Multiple Mazes
break;
case 'terrain':
fs.writeFileSync('Map', terrainbuilder.build(argv.width, argv.height)); // Terrain
break;
case 'custom':
const custom = fs.readFileSync('CustomMap.txt', 'utf8'); // Build from file
fs.writeFileSync('Map', mazebuilder.buildFromFile(custom)); // Build from file
break;
case 'customTerrain':
fs.writeFileSync('Map', terrainbuilder.buildCustom()); // Custom Terrain
break;
default:
fs.writeFileSync('Map', mazebuilder.build());
break;
}
try {
const dir = `${home_location}/AppData/LocalLow/Team17 Digital Ltd/Golf With Your Friends/CustomLevels/${argv.name}`;
!fs.existsSync(dir) && fs.mkdirSync(dir);
fs.copyFile('Map', `${dir}/Map`, err => {
if (err) throw err;
});
} catch (err) {
console.log("\x1b[33m%s\x1b[0m", "WARNING: Unable to copy Map file to the GWYF custom levels directory");
}