Skip to content

Commit

Permalink
Uhm. Got the tests passing. JavaScript is stupid.
Browse files Browse the repository at this point in the history
1. "use strict" is a fucking liar. Language to appease with competence bordering on gaslighting.
2. Aside from the new function syntax, everything is so fucking verbose, and its stdlib is reminiscent of C.
3. What's with this compilation thing? Didn't "dynamic" languages emerge as a response to this shit?
4. I drew an adorable comic to appease my frustrations, but the iPhone cant get it sent.
5. Fuck the iPhone -.-
6. Not in the mood.
7. Srsly.
  • Loading branch information
JoshCheek committed Dec 16, 2015
1 parent fd85717 commit 08437ed
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 40 deletions.
1 change: 1 addition & 0 deletions Readme.md
Expand Up @@ -46,6 +46,7 @@ Assume most decisions are incidental, not intentional (I'm figuring it out as I

## Todo

* Rename DefaultKeymap -> DefaultKeybindings
* Add an about page
```
English names
Expand Down
14 changes: 7 additions & 7 deletions js/synseer/browser/keymap_status.js
Expand Up @@ -4,14 +4,14 @@ function KeymapStatus(domElement) {
}

KeymapStatus.prototype = {
update: function(input, possibilities) {
update: function(input, keybindings) {
let newEntries = "";
for(let key in possibilities) {
newEntries +=
`<tr class="potential_entry">
<td class="keybinding">${key}</td>
<td class="syntax_node">${possibilities[key]}</td>
</tr>`
for(let index in keybindings) {
let kb = keybindings[index];
newEntries += `<tr class="potential_entry">
<td class="keybinding">${kb.keysequence}</td>
<td class="syntax_node">${kb.english}</td>
</tr>`
}
this.domElement.innerHTML = `<div class="user_entry">${input}</div>`+
`<table class="potential_entries">${newEntries}</table>`
Expand Down
2 changes: 1 addition & 1 deletion js/synseer/default_keymap.js
Expand Up @@ -79,8 +79,8 @@ const sm = [
keybindingFor("mlhs", "mlhs", '?? maybe "multiple left-hand setting" or something'),
keybindingFor("p", "pair", '?? part of a hash'),
keybindingFor("b", "begin", 'implicit grouping of expressions'),
keybindingFor("sp", "splat", '?? guessing this is the complement to restarg'),
keybindingFor("ms", "send", 'message send'),
keybindingFor("sp", "splat", '?? guessing this is the complement to restarg'),
]

module.exports = sm;
47 changes: 21 additions & 26 deletions js/synseer/game.js
Expand Up @@ -8,7 +8,7 @@ var Game = function(attrs) {
this._ast = attrs.ast;
this._statsView = attrs.statsView;
this._codeMirror = attrs.codeMirror;
this._keyMap = new KeyMapper(attrs.keyMap);
this._keyMap = attrs.keyMap;
this._onFinished = attrs.onFinished;
this._isFinished = false;
this._stats = {numCorrect: 0, numIncorrect: 0, duration: 0};
Expand Down Expand Up @@ -51,43 +51,38 @@ Game.prototype.isFinished = function() {
Game.prototype.pressKey = function(key) {
if(this.isFinished()) return;

var pre = key;
key = KeyMapper.fromCodemirror(key);
var post = key;
if(pre !== post) {
console.log(JSON.stringify({pre: pre, post: post}));
}

var possibilities = this._keyMap.keyPressed(key);
var entry = Object.keys(possibilities)[0];
var selectedType = possibilities[entry];
var selected = possibilities[0];

// *sigh* not sure if this is a consequence of not knowing js
// or if this is really how to do things like this
if(Object.keys(possibilities).length != 1) {
if(1 < possibilities.length) {
this._onPossibilities(this._keyMap.input(), possibilities);
return;
} else {
var possibilities = this._keyMap.accept();
this._onPossibilities(this._keyMap.input(), possibilities);
}
var type = this._traverse.ast.type

if(selectedType == type) {
let accepted = this._keyMap.accept()
// stupid: we have to do this first, b/c it changes the input
// command/query violation, I guess -.^
this._onPossibilities(this._keyMap.input(), accepted);
var targetAst = this._traverse.ast.type;

if(selected.data == targetAst) {
if(this.isFirstTraversal())
this._statsView.setNumCorrect(++this._stats.numCorrect);
this._traverse = this._traverse.successor();
this._setMessage(`Correct: ${entry}, ${type}`, 'positive');
if(this._traverse) {
this.advanceTraversal();
} else {
this.finish();
}
this._setMessage(`Correct: ${selected.keysequence}, ${selected.english}`, 'positive');
if(this._traverse) this.advanceTraversal();
else this.finish();
} else {
this._statsView.setNumIncorrect(++this._stats.numIncorrect);
var expectedEntry = null;
for(var k in this._keyMap.map) {
if(this._keyMap.map[k] === type) {
expectedEntry = k;
break;
}
}
// type expectedEntry selectedType entry
this._setMessage(`Incorrect: ${expectedEntry}, ${type}`, 'negative');
var expected = this._keyMap.findData(targetAst);
this._setMessage(`Incorrect: ${expected.keysequence}, ${expected.english}`, 'negative');
}
}

Expand Down
7 changes: 5 additions & 2 deletions js/synseer/key_mapper.js
Expand Up @@ -81,8 +81,11 @@ KeyMapper.prototype = {
},

findData: function(data) {
const found = this.keymap.find(kb => kb.hasData(data));
if(found) return found;
for(let i in this.keymap) {
if(this.keymap[i].data === data) return this.keymap[i];
}
// const found = this.keymap.find(kb => kb.hasData(data));
// if(found) return found;
throw `DID NOT HAVE ${data}`
},

Expand Down
10 changes: 7 additions & 3 deletions spec/app_spec.rb
Expand Up @@ -319,31 +319,34 @@ def lol
lol.assert_current_game_task '1+2'
end

it 'filters my keys to the available options as I type, accepts my entry once unique, clears when I press esc, deletes when I press backspace' do
it 'filters my keys to the available options as I type, accepts my entry once unique, clears when I press esc, deletes when I press backspace', t:true do
capybara.visit '/'
capybara.click_link 'integer addition'

get_potentials = -> { capybara.all('.potential_entries .syntax_node').map(&:text) }
get_user_input = -> { capybara.find('.user_entry').text }

# filters
lol.assert_current_game_task '1+2'
expect(get_user_input.call).to eq ''
expect(get_potentials.call.length).to be > 10

browser.send_keys("s")
expect(get_user_input.call).to eq 's'
expect(get_potentials.call).to eq ["casgn", "masgn", "ivasgn", "lvasgn", "op_asgn", "or_asgn", "splat"]
expect(get_potentials.call).to eq ["set constant", "set constant... uhm, idk", "set instance variable", "set local variable", "set with an operator", "set with ||", "?? guessing this is the complement to restarg"]

browser.send_keys("o")
expect(get_user_input.call).to eq 'so'
expect(get_potentials.call).to eq ["op_asgn", "or_asgn"]
expect(get_potentials.call).to eq ["set with an operator", "set with ||"]

# clears
lol.assert_current_game_task '1+2'
browser.send_keys(:Escape)
expect(get_user_input.call).to eq ''
expect(get_potentials.call.length).to be > 10

# deletes
lol.assert_current_game_task '1+2'
browser.send_keys("s")
browser.send_keys("o")
expect(get_user_input.call).to eq 'so'
Expand All @@ -353,6 +356,7 @@ def lol
expect(get_user_input.call).to eq ''

# accepts
lol.assert_current_game_task '1+2'
browser.send_keys("m")
browser.send_keys("s")
expect(get_user_input.call).to eq ''
Expand Down
2 changes: 1 addition & 1 deletion views/game.erb
Expand Up @@ -252,7 +252,7 @@
codeMirror: cm,
statsView: statsView,
ast: <%= @game.fetch :json_ast %>,
keyMap: Synseer.DefaultKeymap,
keyMap: new Synseer.KeyMapper(Synseer.DefaultKeymap),
onPossibilities: function(input, possibilities) {
keymapStatus.update(input, possibilities);
},
Expand Down

0 comments on commit 08437ed

Please sign in to comment.