-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
188 lines (174 loc) · 7.13 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="SmmCourseViewer">
<meta name="author" content="Leonardo Mauro <[email protected]>">
<title>smm-course-viewer - Demonstration</title>
<!--[if IE]><link rel="shortcut icon" href="layout/favicon.ico"><![endif]-->
<link rel="icon" href="layout/favicon.png">
<!-- Bootstrap: https://getbootstrap.com/docs/4.2/ -->
<link rel="stylesheet" href="layout/css/bootstrap.min.css">
<link rel="stylesheet" href="layout/css/draw.css">
</head>
<body>
<!-- Head -->
<header>
<div class="collapse bg-dark" id="navbarHeader">
<div class="container">
<div class="row">
<div class="col-sm-8 col-md-7 py-4">
<h4 class="text-white">About</h4>
<p class="text-muted">A package to reading courses (*.cdt) from Super Mario Maker game.</p>
</div>
<div class="col-sm-4 offset-md-1 py-4">
<h4 class="text-white">Contact</h4>
<ul class="list-unstyled">
<li><a href="https://github.com/leomaurodesenv/smm-course-viewer" target="_blank" class="text-white">GitHub</a></li>
<li><a href="mailto:[email protected]" class="text-white">Email me</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container d-flex justify-content-between">
<a href="#" class="navbar-brand d-flex align-items-center">
<strong>smm-course-viewer</strong>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>
</header>
<!-- Main -->
<main>
<section id="selectFile" class="bg-info text-white" style="padding:15px 0 5px 0;">
<div class="container">
<p>Select the Super Mario Maker course file (*.cdt).</p>
<div class="row">
<div class="col-sm-5 btn-group" role="group">
<label class="btn btn-secondary" onclick="loadCourseExample()">Load Example</label>
<label class="btn btn-light">
Browse… <input type="file" id="inputFile" name="inputFile" accept=".cdt" style="display:none;">
</label>
</div>
<div class="col-sm-7">
<select class="form-control" id="selectSize" onchange="handleSelectSize()">
<option value="16" selected>Object size: default</option>
<option value="32">Object size: normal</option>
<option value="64">Object size: big</option>
</select>
</div>
</div>
</div>
</section>
<section id="display" class="jumbotron">
<div class="container">
<h4>Course Display</h4>
<span id="courseInfoDisplay" class="courseInfoDisplay"></span><hr>
<span id="courseDisplay"></span>
</div>
<hr>
<div class="container">
<h4>General Code</h4>
<p class="text-muted">
In this example, you can access the course data by <b>Browser Console</b> after uploading the file.<br>
Open <b>Browser Console</b>: Ctrl+Shift+K, or F12.<br>
Type:
</p>
<p>
<code>smmCourseViewer</code> <samp># global variable</samp><br>
<code>smmCourseViewer.course</code> <samp># course data</samp><br>
<code>smmCourseViewer.objects</code> <samp># course objects</samp>
</p>
</div>
</section>
</main>
<!-- Footer -->
<footer class="text-muted">
<div class="container">
<p>Copyright © <a href="https://github.com/leomaurodesenv/smm-course-viewer" target="_blank">smm-course-viewer</a> - <a href="https://github.com/leomaurodesenv/" target="_blank">Leonardo Mauro</a></p>
</div>
</footer>
<!-- Bootstrap 4 -->
<script src="layout/js/jquery.slim.min.js"></script>
<script src="layout/js/bootstrap.min.js"></script>
<!-- SmmCourseViewer -->
<script src="lib/CourseObject.js"></script>
<script src="lib/BlockObject.js"></script>
<script src="lib/MonsterObject.js"></script>
<script src="lib/Course.js"></script>
<script src="lib/SmmCourseViewer.js"></script>
<!-- SmmCourseViewer::Draw -->
<script src="draw/BlockDraw.js"></script>
<script src="draw/MonsterDraw.js"></script>
<script src="draw/Draw.js"></script>
<script>
/* -------------------------------------- */
/* Bootstrap::plot alert */
function alertShow(selector, type, msg) {
$(selector).append('<div class="alert alert-'+type+' alert-dismissible fade show" role="alert">'+msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div>');
}
/* -------------------------------------- */
/* select::get selected value */
function getSelectedSize() {
var selectElement = document.getElementById('selectSize');
var selected = selectElement.options[selectElement.selectedIndex].value;
return selected;
}
/* select::get selected value */
function handleSelectSize() {
if(smmCourseViewer)
new Draw('courseDisplay', smmCourseViewer.course, smmCourseViewer.objects, getSelectedSize());
}
/* -------------------------------------- */
/* interpreter::get defaul example */
function loadCourseExample() {
/* get file object */
var xhr = new XMLHttpRequest();
xhr.onload = function() {
interpretCourse(xhr.response); /* xhr.response is now a blob object ~ File */
}
/* force the HTTP response, response-type header to be blob */
xhr.open('GET', 'http://projects.leonardomauro.com/smm-course-viewer/course-example/course_data.cdt');
xhr.responseType = "blob";
xhr.send();
}
/* interpreter::load browse file */
function handleFileSelect(eventFile) {
/* get file object */
let file = eventFile.target.files[0];
alertShow('#selectFile > div:eq(0)', 'success', 'Success: file uploaded!');
interpretCourse(file);
}
/* interpreter::read the file */
function interpretCourse(file) {
/* instance the course viewer */
smmCourseViewer = new _SmmCourseViewer();
smmCourseViewer.read(file, function(err, course, objects) {
if(err) alertShow('#display > div:eq(0)', 'danger', 'Error: corrupted file!');
else {
console.log('smmCourseViewer: ready!');
document.getElementById('courseInfoDisplay').innerHTML = smmCourseViewer.course.getHtml();
let sizeBase = getSelectedSize();
new Draw('courseDisplay', course, objects, sizeBase);
}
});
}
/* -------------------------------------- */
/* window::check functionalities */
window.onload = function() {
/* check if browser support File Reader */
if (window.File && window.FileReader && window.FileList && window.Blob) {
console.log('File APIs is fully supported!');
document.getElementById('inputFile').addEventListener('change', handleFileSelect, false);
} else {
console.error('File APIs are not fully supported in this browser.');
}
}
</script>
</body>
</html>