-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepo.js
183 lines (178 loc) · 5.71 KB
/
repo.js
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
'use strict';
function repo_init(){
core_repo_init({
'beforeunload': {
'todo': function(event){
if(webgl !== 0){
event.preventDefault();
}
},
},
'events': {
'character-random': {
'onclick': function(){
if(core_menu_lock
|| globalThis.confirm('Load new character?')){
core_menu_lock = false;
webgl_level_load({
'character': {
'camera-zoom': 25,
'collides': true,
'controls': 'rpg',
'gravity': 1,
'level': 0,
'lives': 1,
'randomize': true,
},
});
}
},
},
'character-load': {
'onclick': function(){
const element = document.getElementById('character-json');
if(element.files.length === 0){
return;
}
if(core_menu_lock
|| globalThis.confirm('Load new character?')){
core_menu_lock = false;
if(!webgl_level_load({
'character': 1,
'json': element.files[0] || false,
})){
element.value = null;
}
}
},
},
'level-load-file': {
'onclick': function(){
if(!webgl_characters[webgl_character_id]){
return;
}
const element = document.getElementById('level-file');
if(element.files.length === 0){
return;
}
core_file({
'file': element.files[0],
'todo': function(event){
if(webgl_level_load({
'character': 0,
'json': JSON.parse(event.target.result),
})){
document.title = (webgl_properties['title'] || element.files[0].name) + ' - ' + core_repo_title;
}else{
element.value = null;
}
},
'type': 'readAsText',
});
},
},
'level-load-textarea': {
'onclick': function(){
if(!webgl_characters[webgl_character_id]){
return;
}
const level_json = JSON.parse(document.getElementById('level-textarea').value);
webgl_level_load({
'character': 0,
'json': level_json,
});
document.title = level_json['title']
? level_json['title'] + ' - ' + core_repo_title
: core_repo_title;
},
},
'screenshot': {
'onclick': webgl_screenshot,
},
},
'info': '<table><tr><td>Level<td><span id=level></span> (<span id=level-xp></span>/<span id=level-goal></span>)'
+ '<tr><td>Life<td><span class=life></span>/<span class=life-max></span>'
+ '<tr><td>Lives<td><span id=lives></span>'
+ '<tr><td>Jump Height<td><span id=jump-height></span>'
+ '<tr><td>Speed<td><span id=speed></span>'
+ '<tr><td>Turn Speed<td><span id=turn-speed></span>'
+ '</table><button id=screenshot type=button>Screenshot</button>',
'keybinds': {
'Backquote': {
'todo': function(){
webgl_characters[webgl_character_id]['automove'] = !webgl_characters[webgl_character_id]['automove'];
},
},
},
'menu-lock': true,
'mousebinds': {
'contextmenu': {
'preventDefault': true,
},
'mousemove': {
'todo': function(){
webgl_controls_mouse(webgl_character_id);
},
},
'mouseup': {
'todo': webgl_pick_entity,
},
'wheel': {
'todo': function(event){
webgl_controls_wheel(
webgl_character_id,
event.deltaY
);
},
},
},
'tabs': {
'load': {
'content': '<button id=character-random type=button>Create Random Character</button><br>'
+ '<input id=character-json type=file><button id=character-load type=button>Load Character from File</button><hr>'
+ '<input id=level-file type=file><button id=level-load-file type=button>Load Level from File</button><br>'
+ '<button id=level-load-textarea type=button>Load Level from Textarea</button><br><textarea id=level-textarea>{}</textarea>',
'default': true,
'group': 'core-menu',
'label': 'Load Characters/Levels',
},
},
'title': 'Multiverse.htm',
'ui': 'Life: <span id=life></span>/<span id=life-max></span>',
});
}
function repo_level_load(){
update_ui();
}
function repo_stat_modify(){
update_ui();
}
function update_ui(){
const ui = {
'jump-height': 3,
'level': 0,
'level-xp': 3,
'life': 0,
'life-max': 0,
'lives': 0,
'speed': 3,
'turn-speed': 3,
};
for(const element in ui){
ui[element] = core_number_format({
'decimals-max': ui[element],
'number': webgl_characters[webgl_character_id][element],
});
}
core_ui_update({
'class': true,
'ids': {
...ui,
'level-goal': core_number_format({
'decimals-max': 0,
'number': Math.floor(webgl_characters[webgl_character_id]['level'] + 1) * 1e3,
}),
},
});
webgl_uniform_update();
}