-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug.ts
199 lines (159 loc) · 4.72 KB
/
Debug.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { Dict } from './lib/juego/util.js'
import { Entity } from './lib/juego/Entity.js'
import { Material } from './lib/juego/Material.js'
import { Debug as juegoDebug } from './lib/juego/Debug.js'
import { store } from './store.js'
export let flags: Dict<boolean> = {
DEBUG_MODE: false,
DRAW_NORMAL: false,
DRAW_FROM_EYE: true,
DRAW_SPHERICAL: false,
DRAW_RAYS: false,
LOG_ANIM: false,
SUPER_SHOT: false,
FORCE_BOSS_ATK: false,
HIGHLIGHT_CORNERS: true,
HIGHLIGHT_INTERIOR_CORNERS: true,
AUTO_BRIGHT_ADJUST: false,
LEVEL_ALT_MAT: true,
LOG_PANEL_UPDATES: true,
LOG_STATE_SAVELOAD: false,
MOUSE_SELECT: true,
SHOW_DEATH: false,
DRAW_ROOMS: false,
SEND_SERVER_FRAME: false,
ALLOW_CRUSH: false,
RANGING_VIEW: true,
THERMAL_CAMERA: false,
}
export type DebugField = {
value: string;
default?: string;
isValid?: boolean;
}
export function arrayOfStrings( list: Array<string> ): ( x: DebugField ) => boolean {
return function( x: DebugField ) {
let entries = x.value.split( ',' );
for ( let entry of entries ) {
if ( !list.includes( entry ) ) {
return false;
}
}
return true;
}
}
export let validators: Dict<( x: DebugField ) => boolean> = {};
export let fields: Dict<DebugField> = {
ROLL_ATK: { value: '', default: 'default' },
LOCK_ATK: { value: '', default: 'default' },
SHELL_ATK: { value: '', default: 'default' },
SWITCH_ATK: { value: '', default: 'default' },
SNAKE_ATK: { value: '', default: 'default' },
CARRIER_ATK: { value: '', default: 'default' },
SLICE_COUNT: { value: '', default: '180' },
SLICE_OFFSET: { value: '', default: '0' },
LEVEL_INDEX_OFFSET: { value: '', default: '0' },
}
export function getFloat( fieldName: string ): number {
if ( !( fieldName in fields ) ) {
console.error( 'No debug field ' + fieldName );
return 0.0;
}
let float = parseFloat( fields[fieldName].value );
if ( isNaN( float ) ) {
console.error( 'Invalid value for debug field ' + fieldName + ': ' + fields[fieldName].value );
return 0.0;
}
return float;
}
validators['SLICE_COUNT'] = ( x: DebugField ) => !isNaN( parseInt( x.value ) );
for ( let flagName in juegoDebug ) {
flags[flagName] = juegoDebug[flagName];
}
export function toggleFlag( flagName: string ) {
if ( flagName in flags ) {
let obj: Dict<boolean> = {};
if ( flags[flagName] ) {
obj[flagName] = false;
} else {
obj[flagName] = true;
}
setFlags( obj );
} else {
throw new Error( 'Debug.toggleFlag: No flag named ' + flagName );
}
}
export function setFlags( newFlags: Dict<boolean | DebugField> ) {
for ( let flagName in newFlags ) {
let value;
if ( flagName in flags ) {
value = newFlags[flagName];
if ( typeof value == 'boolean' ) {
flags[flagName] = value;
if ( flagName in juegoDebug ) {
juegoDebug[flagName] = flags[flagName];
}
}
if ( typeof document !== 'undefined' ) {
document.dispatchEvent(
new CustomEvent( 'var_' + flagName, { detail: flags[flagName] } ) );
}
} else if ( flagName in fields ) {
value = ( newFlags[flagName] as DebugField ).value;
if ( typeof value == 'string' ) {
value = value.trim();
if ( value.length > 0 ) {
fields[flagName].value = value;
} else {
fields[flagName].value = fields[flagName].default;
}
if ( flagName in validators ) {
fields[flagName].isValid = validators[flagName]( fields[flagName] );
}
if ( typeof document !== 'undefined' ) {
document.dispatchEvent(
new CustomEvent( 'var_' + flagName, { detail: fields[flagName] } ) );
}
}
}
}
}
export function init() {
// get flag data
let debugConfig: Dict<boolean | DebugField> = {};
try {
debugConfig = JSON.parse( store['config'] );
} catch {
store['config'] = JSON.stringify( {} );
}
setFlags( debugConfig );
// set listeners to save debug values
for ( let flagName in flags ) {
document.addEventListener( 'var_' + flagName, ( e: Event ) => {
let config = JSON.parse( store['config'] );
config[flagName] = ( e as CustomEvent ).detail;
store['config'] = JSON.stringify( config );
} );
}
for ( let flagName in fields ) {
document.addEventListener( 'var_' + flagName, ( e: Event ) => {
let config = JSON.parse( store['config'] );
config[flagName] = ( e as CustomEvent ).detail;
store['config'] = JSON.stringify( config );
} );
}
}
export function strokeAll( entities: Array<Entity> ) {
if ( typeof document === 'undefined' ) return;
let canvas = ( window as any ).canvas;
let context = ( window as any ).context;
context.clearRect( 0, 0, canvas.width, canvas.height );
for ( let entity of entities ) {
let shapes = entity.getShapes( 0.0 );
context.strokeStyle = 'gray';
context.lineWidth = 1;
for ( let shape of shapes ) {
shape.stroke( context, { setStyle: false } );
}
}
}