Skip to content

Commit

Permalink
beta v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LuiCat committed Jul 25, 2017
1 parent 41f6a42 commit 49c53dd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
12 changes: 9 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
<input type="button" name="load" class="btn" value="Load" onclick="onUrl()" />
<span>or select local file:</span>
<input type="file" name="fileField" class="file" id="form-file" accept=".mc" onchange="onFile()" size="28" />
<input type="button" name="convert" class="btn" id="btn-convert" value="Convert!" onclick="onConvert()" disabled />
<input type="button" name="save" class="btn" id="btn-save" hidden value="Save" />
<input type="button" name="convert" class="btn" id="btn-convert" value="Convert!" onclick="onConvert()" disabled />
</form>

<div class="details">
Expand All @@ -67,6 +66,7 @@
</div>
<div class="converted">
<span>Converted (TJA Chart)</span>
<span><a id="btn-save" hidden>Save this file</a></span>
<div class="scroll bordered">
<pre class="converted-text code" id="converted-text"></pre>
</div>
Expand All @@ -89,6 +89,7 @@
} else {
mc.readLocal(url, function() {
$('#origin-text').html(mc.text);
$('#btn-convert').removeAttr('disabled');
});
}
}
Expand All @@ -101,14 +102,19 @@
mc.read(url, function() {
$('#origin-text').html(mc.text);
// TODO: mc syntax check
$('#btn-convert').removeAttr("disabled");
$('#btn-convert').removeAttr('disabled');
});
}
}

function onConvert() {
conv.convert(mc, function() {
$('#converted-text').html(conv.generated);
var url = 'data:text/plain;charset=gbk,' + encodeURIComponent(conv.generated);
var filename = mc.filename.replace(/.mc$/i, '.tja');
$('#btn-save').attr('download', filename);
$('#btn-save').attr('href', url);
$('#btn-save').removeAttr('hidden');
});
}

Expand Down
3 changes: 2 additions & 1 deletion js/mc2tja.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var mc2tja = function() {
// First: fill out all necessary properties

tja.prop('TITLE', mc.meta.song.title);
tja.prop('SUBTITLE', mc.meta.song.artist);
tja.prop('SUBTITLE', '--'+mc.meta.song.artist);
if (!this.standardTja) {
tja.prop('ARTIST', mc.meta.song.artist);
tja.prop('AUTHOR', mc.meta.creator);
Expand All @@ -126,6 +126,7 @@ var mc2tja = function() {
tja.prop('WAVE', mc.mainSample.sound);
// TODO: calculate the real offset
tja.prop('OFFSET', (-0.001 * mc.mainSample.offset).toFixed(3));
// TODO: fix preview time
tja.prop('DEMOSTART', mc.meta.preview ? mc.meta.preview : mc.mainSample.offset);
}
if (mc.initTime) {
Expand Down
13 changes: 13 additions & 0 deletions js/mcreader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var MCReader = function() {
this.filename = '';
this.text = null;
this.content = {};
this.meta = null;
Expand Down Expand Up @@ -83,8 +84,19 @@ var MCReader = function() {

},

parseFilename: function(url) {
if (url instanceof File) {
this.filename = url.name;
return;
}
var res = url.match(/(?:.*\/)*([^\/]*\.mc)/i);
if (res)
this.filename = res[1];
},

read: function(url, onload) {
var self = this;
this.parseFilename(url);
$.ajax({
url : url,
success : function(result) {
Expand All @@ -97,6 +109,7 @@ var MCReader = function() {
readLocal: function(url, onload) {
var f = new FileReader();
var self = this;
this.parseFilename(url);
f.onload = function() {
self.parse(f.result);
onload.apply(self);
Expand Down
18 changes: 9 additions & 9 deletions js/tjawriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ var TJASegment = function(initSize) {
while (event && event.index <= index) {
if (!(event.keepLine || (eventAtBegin && index == 0))) {
eventAtBegin = false;
res += '\n';
res += '\r\n';
}
res += event;
++i_event;
event = i_event < this.events.length ? this.events[i_event] : null;
needBreakLine = true;
}
if (needBreakLine) {
res += '\n';
res += '\r\n';
needBreakLine = false;
}
res += note;
Expand All @@ -79,7 +79,7 @@ var TJASegment = function(initSize) {
for (i_event in this.endEvents) {
event = this.endEvents[i_event];
if (!event.keepLine)
res += '\n';
res += '\r\n';
res += event;
needBreakLine = true;
}
Expand Down Expand Up @@ -118,16 +118,16 @@ var TJASegment = function(initSize) {
var res = '';
for (var prop in this.properties) {
var value = this.properties[prop];
res += prop + ':' + value + '\n';
res += prop + ':' + value + '\r\n';
}
res += '\n';
res += this.startEvent + '\n';
res += '\r\n';
res += this.startEvent + '\r\n';
for (var i_seg in this.segments) {
var segment = this.segments[i_seg];
res += segment + '\n';
res += segment + '\r\n';
}
res += this.endEvent + '\n';
res += '\n';
res += this.endEvent + '\r\n';
res += '\r\n';
return res;
},

Expand Down

0 comments on commit 49c53dd

Please sign in to comment.