Skip to content

Commit

Permalink
recreate source branch for voice merge
Browse files Browse the repository at this point in the history
  • Loading branch information
schlawg committed May 10, 2023
1 parent b801d0b commit 2c50a8d
Show file tree
Hide file tree
Showing 103 changed files with 9,492 additions and 172 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ on:
- 'ui/**'
- 'package.json'
- 'pnpm-lock.yaml'
- 'bin/download-lifat'
pull_request:
paths:
- '.github/workflows/assets.yml'
- 'public/**'
- 'ui/**'
- 'package.json'
- 'pnpm-lock.yaml'
- 'bin/download-lifat'

jobs:
assets:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ public/vendor/stockfish.wasm
public/vendor/stockfish-nnue.wasm
public/vendor/stockfish-mv.wasm
public/vendor/stockfish.js
public/vendor/vosk
public/css/
target
data/
dist/
node_modules/
local/
lifat/
ui/common/**/*.js
ui/common/**/*.d.ts
ui/chess/**/*.js
Expand All @@ -35,6 +37,7 @@ ui/nvui/**/*.js
ui/nvui/**/*.d.ts
ui/puz/**/*.js
ui/puz/**/*.d.ts
ui/voice/@build/crowdv
ui/*/npm-debug.log
ui/*/tsconfig.tsbuildinfo
hs_*.log
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/ui/common/**/*.d.ts
/ui/game/**/*.js
/ui/game/**/*.d.ts
/ui/voice/@build/**/*.json
/ui/nvui/**/*.js
/ui/nvui/**/*.d.ts
/ui/puz/**/*.js
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ Allow: /
NotImplemented(html.site.message.temporarilyDisabled).toFuccess

def keyboardMoveHelp = Open:
Ok(html.site.keyboardHelpModal.keyboardMove).toFuccess
Ok(html.site.helpModal.keyboardMove).toFuccess

def voiceMoveHelp = Open:
Ok(html.site.helpModal.voiceMove).toFuccess

def movedPermanently(to: String) = Anon:
MovedPermanently(to).toFuccess
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/Pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ final class Pref(env: Env) extends LilaController(env):
"bg" -> (forms.bg -> save("bg")),
"bgImg" -> (forms.bgImg -> save("bgImg")),
"is3d" -> (forms.is3d -> save("is3d")),
"zen" -> (forms.zen -> save("zen"))
"zen" -> (forms.zen -> save("zen")),
"voice" -> (forms.voice -> save("voice"))
)

private def save(name: String)(value: String, ctx: Context): Fu[Cookie] =
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Puzzle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ final class Puzzle(env: Env, apiC: => Api) extends LilaController(env):
}

def help = Open:
Ok(html.site.keyboardHelpModal.puzzle).toFuccess
Ok(html.site.helpModal.puzzle).toFuccess

private def DashboardPage(username: Option[UserStr])(f: Context ?=> UserModel => Fu[Result]) =
Auth { ctx ?=> me =>
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,4 @@ final class Round(
}

def help = Open:
Ok(html.site.keyboardHelpModal.round).toFuccess
Ok(html.site.helpModal.round).toFuccess
2 changes: 1 addition & 1 deletion app/controllers/UserAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ final class UserAnalysis(
}

def help = Open:
Ok(html.site.keyboardHelpModal.analyse(getBool("study"))).toFuccess
Ok(html.site.helpModal.analyse(getBool("study"))).toFuccess
4 changes: 2 additions & 2 deletions app/templating/AssetHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ if (window.matchMedia('(prefers-color-scheme: dark)').media === 'not all')
ContentSecurityPolicy(
defaultSrc = List("'self'", assetDomain.value),
connectSrc =
"'self'" :: assetDomain.value :: sockets ::: env.explorerEndpoint :: env.tablebaseEndpoint :: localDev,
"'self'" :: "data:" :: assetDomain.value :: sockets ::: env.explorerEndpoint :: env.tablebaseEndpoint :: localDev,
styleSrc = List("'self'", "'unsafe-inline'", assetDomain.value),
frameSrc = List("'self'", assetDomain.value, "www.youtube.com", "player.twitch.tv"),
workerSrc = List("'self'", assetDomain.value),
workerSrc = List("'self'", assetDomain.value, "blob:"),
imgSrc = List("data:", "*"),
scriptSrc = List("'self'", assetDomain.value),
fontSrc = List("'self'", assetDomain.value),
Expand Down
4 changes: 4 additions & 0 deletions app/views/account/pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ object pref:
inputMovesWithTheKeyboard(),
radios(form("behavior.keyboardMove"), booleanChoices)
),
setting(
"Input moves with your voice",
radios(form("behavior.voice"), booleanChoices)
),
setting(
snapArrowsToValidMoves(),
radios(form("behavior.arrowSnap"), booleanChoices)
Expand Down
1 change: 1 addition & 0 deletions app/views/puzzle/show.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object show:
moreCss = frag(
cssTag("puzzle"),
ctx.pref.hasKeyboardMove option cssTag("keyboardMove"),
ctx.pref.hasVoice option cssTag("voice"),
ctx.blind option cssTag("round.nvui")
),
moreJs = frag(
Expand Down
3 changes: 2 additions & 1 deletion app/views/round/bits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object bits:
moreCss = frag(
cssTag(if (variant == Crazyhouse) "round.zh" else "round"),
ctx.pref.hasKeyboardMove option cssTag("keyboardMove"),
ctx.pref.hasVoice option cssTag("voice"),
ctx.blind option cssTag("round.nvui"),
moreCss
),
Expand All @@ -41,7 +42,7 @@ object bits:
zenable = zenable,
robots = robots,
zoomable = true,
csp = defaultCsp.withPeer.some,
csp = defaultCsp.withPeer.withWebAssembly.some,
withHrefLangs = withHrefLangs
)(body)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import play.api.i18n.Lang
import lila.app.templating.Environment.given
import lila.app.ui.ScalatagsTemplate.*

object keyboardHelpModal:
object helpModal:

private def header(text: Frag) = tr(th(colspan := 2)(p(text)))
private def row(keys: Frag, desc: Frag) = tr(td(cls := "keys")(keys), td(cls := "desc")(desc))
private val or = tag("or")
private val kbd = tag("kbd")
private def voice(text: String) = strong(cls := "val-to-word", text)
private def phonetic(text: String) = strong(cls := "val-to-word phonetic", text)

private def navigateMoves(using Lang) = frag(
header(trans.navigateMoveTree()),
Expand Down Expand Up @@ -143,3 +145,95 @@ object keyboardHelpModal:
)
)
)
def voiceMove(using Lang) =
import trans.keyboardMove.*
frag(
h2("Voice commands"),
table(
tbody(
tr(th(p("Instructions"))),
tr(
td(cls := "tips")(
ul(
li(
"Click the microphone to enable voice moves. It glows red when listening."
),
li(
"Your voice audio never leaves your device. Moves are sent as plain text just like those made by mouse or touch."
),
li(
"You may speak UCI, SAN, piece names, board squares, or phrases like ",
voice("P,x,R"),
" and ",
voice("x"),
". Click ",
strong("Show me everything"),
" for a full list."
),
li(
"We show colored or numbered arrows for up to 8 available moves when we're not sure. " +
"If an arrow shows a growing pie, that move will be played when the pie becomes a full circle."
),
li(
"During this countdown, you may only say ",
voice("yes"),
" to play the move immediately, ",
voice("no"),
" to cancel, ",
voice("stop"),
" to stop the clock, or the color/number of an arrow. No other command will be recognized."
),
li(
"Higher clarity values will decrease arrows & countdowns but increase the chance of misplays."
),
li(
"Clarity, countdown, and arrow display settings are in the hamburger menu by the microphone."
),
li(
"The phonetic alphabet is ",
phonetic("a,b,c,d,e,f,g,h")
)
)
)
)
)
),
div(cls := "commands")(
table(
tbody(
header(performAMove()),
row(frag(voice("e,4"), br, phonetic("e,4")), "Move to e4 or select a piece there"),
row(voice("N"), "Move my knight or capture a knight"),
row(frag(voice("B,h,6"), br, phonetic("B,h,6")), "Move bishop to h6"),
row(voice("Q,x,R"), "Take rook with queen"),
row(
frag(voice("c,8,=,N"), br, phonetic("c,8,N")),
"Move c8 promote to knight"
),
row(voice("castle"), "castle (either side)"),
row(voice("O-O-O"), "Queenside castle"),
row(frag(voice("a,7,g,1"), br, phonetic("a,7,g,1")), "Full UCI works too"),
row(voice("draw"), offerOrAcceptDraw())
)
),
table(
tbody(
header(otherCommands()),
row(voice("resign"), trans.resignTheGame()),
row(voice("takeback"), "Request a takeback"),
row(voice("no"), "Cancel timer or deny a request"),
row(voice("yes"), "Play preferred move or confirm something"),
row(voice("stop"), "Stop the timer but keep the arrows"),
row(voice("mic-off"), "Turn off your microphone"),
row(voice("next"), trans.puzzle.nextPuzzle()),
row(voice("upvote"), trans.puzzle.upVote()),
row(voice("solve"), "Show puzzle solution"),
row(voice("help"), trans.showHelpDialog()),
tr(
td,
td(button(cls := "button", id := "all-phrases-button")("Show me everything"))
)
)
)
)
)
6 changes: 6 additions & 0 deletions bin/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ASSETS_FILES = [
"ui",
"package.json",
"pnpm-lock.yaml",
"bin/download-lifat",
]

SERVER_FILES = [
Expand All @@ -61,6 +62,8 @@ SERVER_BUILD_URL = "https://api.github.com/repos/lichess-org/lila/actions/workfl

ARTIFACT_DIR = "/home/lichess-artifacts"

LIFAT_DIR = "/home/lifat"


def curl_cli(command, *, url="https://lichess.org/cli"):
return f"curl --fail -X POST --data {shlex.quote(command)} {shlex.quote(url)} -H @.lila-cli"
Expand Down Expand Up @@ -263,6 +266,9 @@ def deploy_script(profile, session, run, url):
f"mkdir -p {artifact_unzipped}/d",
f"tar -xf {artifact_unzipped}/*.tar.xz -C {artifact_unzipped}/d",
f"cat {artifact_unzipped}/d/commit.txt",
"echo",
"echo \\# Preparing lifat ...",
f"(cd {artifact_unzipped} && if [ -x .bin/download-lifat ]; then LIFAT_DIR={LIFAT_DIR} ./bin/download-lifat; chown -R lichess:lichess {LIFAT_DIR}; fi)",
f"chown -R lichess:lichess {ARTIFACT_DIR}",
"echo",
"echo \\# Installing ...",
Expand Down
21 changes: 21 additions & 0 deletions bin/download-lifat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh -e

commit=445b5cafda38995d330fe8978c620db314c9a7ef

lifat_dir="${LIFAT_DIR:-lifat}"
lifat_commit_dir=$(realpath "$lifat_dir/lifat-$commit")

mkdir -p "$lifat_dir"

if [ ! -d "$lifat_commit_dir" ]; then
git init "$lifat_commit_dir"
pushd "$lifat_commit_dir"
git remote add origin https://github.com/lichess-org/lifat
git fetch --depth 1 --no-write-fetch-head origin "$commit"
git checkout --detach "$commit"
popd
fi

ln -sfn "$lifat_commit_dir" "public/lifat"

(cd "$lifat_commit_dir" && git log --oneline)
2 changes: 1 addition & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ GET /variant/:key controllers.Page.variant(key)
GET /help/contribute controllers.Page.help
GET /help/master controllers.Page.master
GET /help/keyboard-move controllers.Main.keyboardMoveHelp

GET /help/voice-move controllers.Main.voiceMoveHelp
# DGT
GET /dgt controllers.DgtCtrl.index
GET /dgt/play controllers.DgtCtrl.play
Expand Down
10 changes: 8 additions & 2 deletions modules/pref/src/main/Pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ case class Pref(
confirmResign: Int,
insightShare: Int,
keyboardMove: Int,
voice: Int,
zen: Int,
ratings: Int,
rookCastle: Int,
Expand Down Expand Up @@ -89,8 +90,9 @@ case class Pref(
SoundSet.allByKey get value map { s =>
copy(soundSet = s.key)
}
case "zen" => copy(zen = if (value == "1") 1 else 0).some
case _ => none
case "zen" => copy(zen = if (value == "1") 1 else 0).some
case "voice" => copy(voice = if (value == "1") 1 else 0).some
case _ => none

def animationMillis: Int =
animation match
Expand Down Expand Up @@ -125,6 +127,8 @@ case class Pref(

def hasKeyboardMove = keyboardMove == KeyboardMove.YES

def hasVoice = voice == Voice.YES

// atob("aHR0cDovL2NoZXNzLWNoZWF0LmNvbS9ob3dfdG9fY2hlYXRfYXRfbGljaGVzcy5odG1s")
def botCompatible =
theme == "brown" &&
Expand Down Expand Up @@ -223,6 +227,7 @@ object Pref:
)

object KeyboardMove extends BooleanPref
object Voice extends BooleanPref

object RookCastle:
val NO = 0
Expand Down Expand Up @@ -449,6 +454,7 @@ object Pref:
confirmResign = ConfirmResign.YES,
insightShare = InsightShare.FRIENDS,
keyboardMove = KeyboardMove.NO,
voice = Voice.NO,
zen = Zen.NO,
ratings = Ratings.YES,
rookCastle = RookCastle.YES,
Expand Down
10 changes: 10 additions & 0 deletions modules/pref/src/main/PrefForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ object PrefForm:
"submitMove" -> checkedNumber(Pref.SubmitMove.choices),
"confirmResign" -> checkedNumber(Pref.ConfirmResign.choices),
"keyboardMove" -> optional(booleanNumber),
"voice" -> optional(booleanNumber),
"rookCastle" -> optional(booleanNumber)
)(BehaviorData.apply)(unapply),
"clock" -> mapping(
Expand Down Expand Up @@ -78,6 +79,7 @@ object PrefForm:
submitMove: Int,
confirmResign: Int,
keyboardMove: Option[Int],
voice: Option[Int],
rookCastle: Option[Int]
)

Expand Down Expand Up @@ -125,6 +127,7 @@ object PrefForm:
confirmResign = behavior.confirmResign,
captured = display.captured == 1,
keyboardMove = behavior.keyboardMove | pref.keyboardMove,
voice = behavior.voice | pref.voice,
zen = display.zen | pref.zen,
ratings = ratings | pref.ratings,
resizeHandle = display.resizeHandle | pref.resizeHandle,
Expand Down Expand Up @@ -157,6 +160,7 @@ object PrefForm:
submitMove = pref.submitMove,
confirmResign = pref.confirmResign,
keyboardMove = pref.keyboardMove.some,
voice = pref.voice.some,
rookCastle = pref.rookCastle.some
),
clock = ClockData(
Expand Down Expand Up @@ -231,3 +235,9 @@ object PrefForm:
"zen" -> text.verifying(Set("0", "1") contains _)
)
)

val voice = Form(
single(
"voice" -> text.verifying(Set("0", "1") contains _)
)
)
Loading

0 comments on commit 2c50a8d

Please sign in to comment.