palantir WIP

palantir
Thibault Duplessis 2019-08-03 01:03:49 +02:00
parent f9f8e1d8da
commit d6a1b01ef2
13 changed files with 155 additions and 2 deletions

View File

@ -38,6 +38,7 @@
"ui/game",
"ui/nvui",
"ui/speech",
"ui/palantir",
"ui/insight",
"ui/learn",
"ui/lobby",

View File

@ -54,7 +54,6 @@ interface Lichess {
render(ctrl: any): any;
}
playMusic(): any;
LichessSpeech?: LichessSpeech;
spinnerHtml: string;
movetimeChart: any;
hasTouchEvents: boolean;
@ -69,6 +68,10 @@ interface LichessSpeech {
step(s: { san?: San }, cut: boolean): void;
}
interface Palantir {
button(): any;
}
interface Cookie {
name: string;
value: string;
@ -133,6 +136,10 @@ interface Window {
jump(node: Tree.Node): void
}
hopscotch: any;
LichessSpeech?: LichessSpeech;
palantir?: {
palantir(): Palantir
};
[key: string]: any; // TODO
}

View File

@ -38,4 +38,7 @@
justify-content: space-between;
align-items: center;
}
&__palantir {
padding: 0 .6em;
}
}

View File

@ -8,6 +8,9 @@ const li = window.lichess;
export default function(opts: ChatOpts, redraw: Redraw): Ctrl {
const data = opts.data;
const palantir: { instance: Palantir | undefined } = {
instance: undefined
};
const allTabs: Tab[] = ['discussion'];
if (opts.noteId) allTabs.push('note');
@ -118,6 +121,12 @@ export default function(opts: ChatOpts, redraw: Redraw): Ctrl {
const emitEnabled = () => li.pubsub.emit('chat.enabled', vm.enabled);
emitEnabled();
li.loadScript(li.compiledScript('palantir')).then(() => {
palantir.instance = window.Palantir!.palantir();
console.log(palantir.instance);
redraw();
});
return {
data,
opts,
@ -144,6 +153,7 @@ export default function(opts: ChatOpts, redraw: Redraw): Ctrl {
redraw();
},
redraw,
palantir,
destroy
};
};

View File

@ -66,6 +66,7 @@ export interface Ctrl {
setTab(tab: Tab): void
setEnabled(v: boolean): void
plugin?: ChatPlugin
palantir: { instance?: Palantir }
redraw: Redraw
destroy(): void;
}

View File

@ -22,8 +22,12 @@ export default function(ctrl: Ctrl): VNode {
function normalView(ctrl: Ctrl) {
const active = ctrl.vm.tab;
const palantir = ctrl.palantir.instance;
return [
h('div.mchat__tabs.nb_' + ctrl.allTabs.length, ctrl.allTabs.map(t => renderTab(ctrl, t, active))),
h('div.mchat__tabs.nb_' + ctrl.allTabs.length, [
...ctrl.allTabs.map(t => renderTab(ctrl, t, active)),
palantir ? palantir.button() : null
]),
h('div.mchat__content.' + active,
(active === 'note' && ctrl.note) ? [noteView(ctrl.note)] : (
ctrl.plugin && active === ctrl.plugin.tab.key ? [ctrl.plugin.view()] : discussionView(ctrl)

View File

@ -0,0 +1,3 @@
const lilaGulp = require('../gulp/tsProject.js');
lilaGulp('Palantir', 'lichess.palantir', __dirname);

View File

@ -0,0 +1,31 @@
{
"name": "palantir",
"version": "1.0.0",
"description": "lichess.org webrtc media calls",
"main": "dist/main.js",
"types": "dist/main",
"repository": {
"type": "git",
"url": "https://github.com/ornicar/lila"
},
"keywords": [
"chess",
"lichess",
"webrtc"
],
"author": "Thibault Duplessis",
"license": "AGPL-3.0",
"bugs": {
"url": "https://github.com/ornicar/lila/issues"
},
"homepage": "https://github.com/ornicar/lila",
"scripts": {
"compile": "../../node_modules/typescript/bin/tsc"
},
"devDependencies": {
"@types/lichess": "1.0.0",
"typescript": "^3"
},
"dependencies": {
}
}

View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const snabbdom_1 = require("snabbdom");
function instance() {
return {
button() {
return snabbdom_1.h('button.palantir', {
attrs: { 'data-icon': '' }
});
}
};
}
exports.instance = instance;

View File

@ -0,0 +1,21 @@
import { h } from 'snabbdom'
export function palantir() {
navigator.getUserMedia({video: true, audio: true}, function(stream) {
var call = peer.call('another-peers-id', stream);
call.on('stream', function(remoteStream) {
// Show stream in some video/canvas element.
});
}, function(err) {
console.log('Failed to get local stream' ,err);
});
return {
button() {
return h('button.mchat__palantir.fbt', {
attrs: { 'data-icon': '' }
});
}
};
}

View File

@ -0,0 +1,6 @@
{
"extends": "../tsconfig.base.json",
"include": ["src/*.ts"],
"compilerOptions": {
}
}

View File

@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const roles = { P: 'pawn', R: 'rook', N: 'knight', B: 'bishop', Q: 'queen', K: 'king' };
function renderSan(san) {
let move;
if (san.includes('O-O-O'))
move = 'long castle';
else if (san.includes('O-O'))
move = 'short castle';
else
move = san.replace(/[\+#]/, '').split('').map(c => {
if (c == 'x')
return 'takes';
if (c == '+')
return 'check';
if (c == '#')
return 'checkmate';
if (c == '=')
return 'promotion';
if (c == '@')
return 'at';
const code = c.charCodeAt(0);
if (code > 48 && code < 58)
return c; // 1-8
if (code > 96 && code < 105)
return c.toUpperCase();
return roles[c] || c;
}).join(' ');
if (san.includes('+'))
move += ' check';
if (san.includes('#'))
move += ' checkmate';
return move;
}
function hackFix(msg) {
return msg
.replace(/^A /, "A, ") // "A takes" & "A 3" are mispronounced
.replace(/(\d) E (\d)/, "$1,E $2") // Strings such as 1E5 are treated as scientific notation
.replace(/^C /, "c ") // "uppercase C is pronounced as "degrees celsius" when it comes after a number (e.g. R8c3)
.replace(/^F /, "f "); // "uppercase F is pronounced as "degrees fahrenheit" when it comes after a number (e.g. R8f3)
}
function say(text, cut) {
const msg = new SpeechSynthesisUtterance(hackFix(text));
if (cut)
speechSynthesis.cancel();
window.lichess.sound.say(msg);
}
exports.say = say;
function step(s, cut) {
say(s.san ? renderSan(s.san) : 'Game start', cut);
}
exports.step = step;

View File

@ -1,5 +1,6 @@
{
"extends": "../tsconfig.base.json",
"include": ["src/*.ts"],
"compilerOptions": {
}
}