Skip to content

Commit

Permalink
Merge pull request #138 from lorderikir/master
Browse files Browse the repository at this point in the history
v0.7.15 update
  • Loading branch information
ericjiang97 authored Aug 17, 2016
2 parents 3f50408 + 2e37978 commit 77127b9
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/MARIE-js/MARIE.js.svg?branch=master)](https://travis-ci.org/MARIE-js/MARIE.js) [![devDependency Status](https://david-dm.org/marie-js/MARIE.js/dev-status.svg)](https://david-dm.org/marie-js/MARIE.js#info=devDependencies) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com/) [![npm version](https://badge.fury.io/js/npm.svg)](https://badge.fury.io/js/npm)
==============
Current version: `0.7.11`
Current version: `0.7.15`

MARIE.js is an implementation of a simulator for a 'Machine Architecture that is Really Intuitive and Easy'
from [The Essentials of Computer Organization and Architecture](https://books.google.com.au/books/about/The_Essentials_of_Computer_Organization.html?id=3kQoAwAAQBAJ&redir_esc=y) (Linda Null, Julia Lobur) in JavaScript.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MARIE.js",
"version": "0.7.11",
"version": "0.7.15",
"description": "MARIE.js is an implementation of a simulator for a 'Machine Architecture that is Really Intuitive and Easy' from The Essentials of Computer Organization and Architecture (Linda Null, Julia Lobur) in JavaScript.",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,13 @@ codeblock {
.memory-changed {
color: red;
}

.prefs-row{
padding: 3px;
width: 50%;
text-align: right;
}

.pref-table{
width: 100%;
}
50 changes: 41 additions & 9 deletions src/js/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ window.addEventListener("load", function() {
autosave: true,
minDelay: 1,
maxDelay: 3000,
minDatapathDelay: 1000
binaryStringGroupLength: 4,
defaultInputMode: 'HEX',
defaultOutputMode: 'HEX',
minDatapathDelay: 1000,
};

var prefs = $.extend(defaultPrefs);
Expand All @@ -47,14 +50,17 @@ window.addEventListener("load", function() {
saveFile();
localStorage.setItem("marie-program",null);
$("#saved-status").text("New file");
location.reload();
location.reload(); //reloads
}

function getPrefs() {
var autocomplete = localStorage.getItem("autocomplete"),
autosave = localStorage.getItem("autosave"),
minDelay = localStorage.getItem("min-delay"),
maxDelay = localStorage.getItem("max-delay"),
binaryStringGroupLength = localStorage.getItem("binaryStringGroup-Length"),
defaultInputMode = localStorage.getItem("defaultInputMode-value"),
defaultOutputMode = localStorage.getItem("defaultOutputMode-value"),
minDatapathDelay = localStorage.getItem("min-datapath-delay");

if(["false", "true"].indexOf(autocomplete) >= 0) {
Expand All @@ -73,10 +79,22 @@ window.addEventListener("load", function() {
prefs.maxDelay = parseInt(maxDelay);
}

if(!isNaN(parseInt(binaryStringGroupLength))) {
prefs.binaryStringGroupLength = parseInt(binaryStringGroupLength);
}

if(!isNaN(parseInt(minDatapathDelay))) {
prefs.minDatapathDelay = parseInt(minDatapathDelay);
}

if(!isNaN(parseInt(defaultInputMode))) {
prefs.defaultInputMode = defaultInputMode;
}

if(!isNaN(parseInt(defaultOutputMode))) {
prefs.defaultOutputMode = defaultOutputMode;
}

rangeDelay.min = prefs.minDelay;
rangeDelay.max = prefs.maxDelay;
}
Expand All @@ -87,6 +105,9 @@ window.addEventListener("load", function() {
localStorage.setItem("min-delay", prefs.minDelay);
localStorage.setItem("max-delay", prefs.maxDelay);
localStorage.setItem("min-datapath-delay", prefs.minDatapathDelay);
localStorage.setItem("binaryStringGroup-Length",prefs.binaryStringGroupLength);
localStorage.setItem("defaultOutputMode-value",prefs.defaultOutputMode);
localStorage.setItem("defaultInputMode-value",prefs.defaultInputMode);

rangeDelay.min = prefs.minDelay;
rangeDelay.max = prefs.maxDelay;
Expand Down Expand Up @@ -348,7 +369,7 @@ window.addEventListener("load", function() {
case ASCII:
return String.fromCharCode(value);
case BIN:
return Utility.uintToBinGroup(value, 16, 4);
return Utility.uintToBinGroup(value, 16, prefs.binaryStringGroupLength);
default:
return "Invalid output type.";
}
Expand Down Expand Up @@ -511,7 +532,7 @@ window.addEventListener("load", function() {
$('#input-button').off('click');
$('#input-button-pause').off('click');
$('#input-value').off('keypress');

$('#input-type').val(localStorage.getItem('defaultInputMode-value').toLowerCase());
$('#input-value').on('keypress', function(e) {
if(e.which == 13) {
finishInput(output);
Expand Down Expand Up @@ -1103,7 +1124,9 @@ window.addEventListener("load", function() {
$("#min-delay").val(prefs.minDelay);
$("#max-delay").val(prefs.maxDelay);
$("#min-datapath-delay").val(prefs.minDatapathDelay);

$("#bstringLength").val(prefs.binaryStringGroupLength);
$("#defaultInputMode").val(localStorage.getItem("defaultInputMode-value"));
$("#defaultOutputMode").val(localStorage.getItem("defaultOutputMode-value"));
$("#prefs-modal").modal("show");
});

Expand All @@ -1118,14 +1141,20 @@ window.addEventListener("load", function() {
$("#autocomplete,#autosave").on("change", function() {
$("#save-changes").prop("disabled", false);
});


$("#bstringLength,#defaultOutputMode,#defaultInputMode").change(function(){
$("#save-changes").prop("disabled", false);
});
$("#defaultOutputMode").val(prefs.defaultOutputMode);
$("#save-changes").click(function() {
var autocomplete = $("#autocomplete").prop("checked"),
autosave = $("#autosave").prop("checked");

var minDelay = parseInt($("#min-delay").val());
var maxDelay = parseInt($("#max-delay").val());

var stringLength = parseInt($("#bstringLength").val());
var defaultInputMode = $("#defaultInputMode").val();
var defaultOutputMode = $("#defaultOutputMode").val();
if(isNaN(minDelay) || isNaN(maxDelay) || minDelay >= maxDelay || minDelay < 0 || maxDelay < 0) {
$("#prefs-invalid-input-error").show();
return;
Expand All @@ -1143,12 +1172,15 @@ window.addEventListener("load", function() {
prefs.minDelay = minDelay;
prefs.maxDelay = maxDelay;
prefs.minDatapathDelay = minDatapathDelay;

prefs.binaryStringGroupLength = stringLength;
prefs.defaultInputMode = defaultInputMode;
prefs.defaultOutputMode = defaultOutputMode;
setPrefs();

$("#output-select").val(prefs.defaultOutputMode);
$("#prefs-modal").modal("hide");
});

$("#output-select").val(localStorage.getItem("defaultOutputMode-value"));
$("#set-to-defaults").click(function() {
prefs = $.extend(defaultPrefs);
setPrefs();
Expand Down
77 changes: 69 additions & 8 deletions src/templates/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,80 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">MARIE.js | <span class="fa fa-wrench"></span> Preferences</h4>
<h3 class="modal-title">MARIE.js | <span class="fa fa-wrench"></span> Preferences</h3>
</div>
<div id="prefs-invalid-input-error" class="alert alert-danger">
<span class="glyphicon glyphicon-alert"></span> <strong>Invalid input</strong> Please try again.
</div>
<div class="modal-body">
<ul class="list-unstyled">
<li><input type="checkbox" id="autocomplete" /> <label for="autocomplete">Autocomplete</label></li>
<li><input type="checkbox" id="autosave" /> <label for="autosave">Autosave</label></li>
<li><label for="min-delay">Minimum delay:</label> <input type="text" class="form-control" id="min-delay" /></li>
<li><label for="max-delay">Maximum delay:</label> <input type="text" class="form-control" id="max-delay" /></li>
<li><label for="min-datapath-delay">Minimum datapath delay:</label> <input type="text" id="min-datapath-delay" class="form-control" /></li>
</ul>
<table class="pref-table">
<tr>
<td><h4>Auto Settings</h4></td>
<td></td>
</tr>
<tr>
<td><label for="autocomplete">Autocomplete: </label></td>
<td class="prefs-row"><input type="checkbox" id="autocomplete" /></td>
</tr>
<tr>
<td><label for="autosave">Autosave: </label></td>
<td class="prefs-row"><input type="checkbox" id="autosave" /></td>
</tr>
<tr>
<td><h4>Delay Setings</h4></td>
<td></td>
</tr>
<tr>
<td><label for="min-delay">Minimum delay (ms):</label></td>
<td class="prefs-row"><input type="text" class="form-control" id="min-delay" style="text-align: right;"/></td>
</tr>
<tr>
<td><label for="max-delay">Maximum delay (ms):</label></td>
<td class="prefs-row"><input type="text" class="form-control" id="max-delay" style="text-align: right;"/></td>
</tr>
<tr>
<td><label for="min-datapath-delay">Minimum datapath delay (ms):</label></td>
<td class="prefs-row"><input type="text" id="min-datapath-delay" class="form-control" style="text-align: right;"/></td>
</tr>
<tr>
<td><h4>Input/Output Settings</h4></td>
<td></td>
</tr>
<tr>
<td>Binary String Group Length</td>
<td class="prefs-row">
<select id="bstringLength" style="width: 50%;text-align: right">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="4">4</option>
<option value="8">8</option>
</select>
</td>
</tr>
<tr>
<td>Default Input Mode:</td>
<td class="prefs-row">
<select id="defaultInputMode" style="width: 50%;text-align: right">
<option value="HEX">HEX</option>
<option value="DEC">DEC</option>
<option value="ASCII">UNICODE</option>
<option value="BIN">BINARY</option>
</select>
</td>
</tr>
<tr>
<td>Default Output Mode:</td>
<td class="prefs-row">
<select id="defaultOutputMode" style="width: 50%;text-align: right">
<option value="HEX">HEX</option>
<option value="DEC">DEC</option>
<option value="ASCII">UNICODE</option>
<option value="BIN">BINARY</option>
</select>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button id="save-changes" type="button" class="btn" disabled>Save changes</button>
Expand Down

0 comments on commit 77127b9

Please sign in to comment.