chanind / hanzi-writer

Chinese character stroke order animations and practice quizzes
https://hanziwriter.org
MIT License
3.47k stars 539 forks source link

feat: allow checking backwards strokes #252

Closed matt-tingen closed 2 years ago

matt-tingen commented 2 years ago

The use case for this is to allow applications to notify a user when they make a backwards stroke (one which is correct except for the direction in which in which it's made) on a quiz. In such a case, the application will likely want to show some messaging to the user indicating the stroke was made in the wrong direction. The application may want to treat backwards strokes as correct or incorrect.

This change includes two API changes to fulfill the above use case:

checkBackwardsStrokes is ternary to allow avoiding the perf hit of checking backwards strokes if the application does not care about them.

If checkBackwardsStrokes is false, the handlers will always receive isBackwards: false since the backwards check is skipped. The alternative here is to return e.g. null if the check was skipped. I opted against this to keep the API a bit simpler with a consistent type for isBackwards.

codecov-commenter commented 2 years ago

Codecov Report

Merging #252 (755a3c6) into master (f1a810c) will increase coverage by 0.10%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #252      +/-   ##
==========================================
+ Coverage   96.16%   96.26%   +0.10%     
==========================================
  Files          32       32              
  Lines        1121     1126       +5     
  Branches      202      205       +3     
==========================================
+ Hits         1078     1084       +6     
+ Misses         39       38       -1     
  Partials        4        4              
Impacted Files Coverage Δ
src/defaultOptions.ts 100.00% <ø> (ø)
src/Quiz.ts 95.83% <100.00%> (+0.05%) :arrow_up:
src/strokeMatches.ts 100.00% <100.00%> (+1.26%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f1a810c...755a3c6. Read the comment docs.

chanind commented 2 years ago

:tada: This PR is included in version 3.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: