-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inital sgf download #273
inital sgf download #273
Conversation
This is a nice start! I think the main part that is missing is the server endpoint. That will probably go in server/src/api.ts.
Disclaimer: this is just me copying code around - I haven't tested myself. Let me know if you run into any issues with this! I haven't referenced QuantumGo directly. This is because I noticed your current implementation could work reasonably well for other variants (except maybe the SGF header), so it would be a lot simpler to have the SGF implementation decoupled from the variant itself. If you foresee the implementation diverging from standard SGF/Go, we can figure out a way to let variants define their own SGF function, just let me know. |
</script> | ||
|
||
<template> | ||
<button @click="downloadData">Download Game Files</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a downloadData callback, we can probably make this an <a href="/games/${gameId}/sgf">Download Game Files</a>
(Content-Disposition: attachment
will instruct the browser to save the file)
</div> | ||
|
||
<DownloadSGF /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably belongs on the GameView
itself, not the NavButtons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
On second thought, we probably do need a per-variant implementation, esp. since some variants don't just have black and white. So the way we would do that I think is to expose the SGF via a new optional member of AbstractGame:
Then use that in the express endpoint:
|
<script setup lang="ts"> | ||
import { defineProps } from 'vue'; | ||
|
||
const props = defineProps<{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a TS error in CI:
error TS2345: Argument of type '{}' is not assignable to parameter of type 'NonNullable<(Partial<{ readonly [x: number]: string; }> & Omit<(readonly string[] | { readonly [x: string]: Prop<unknown, unknown> | null | undefined; }) & (VNodeProps & AllowedComponentProps & (ComponentCustomProps & Readonly<...>)), never> & Record<...>) | (Partial<...> & ... 1 more ... & Record<...>)> & Record<...>'.
It's not entirely obvious from the error message, but it will be resolved once you add some non-empty props here. (you could also fix the error by removing defineProps()
, but I think we'll want to pass in gameId
at least)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
Nice start, thank you for working on this! Recently we made some changes that enable graph boards for certain variants, including quantum, see e.g. #264 To distinguish between the two cases, there is the function isGridBadukConfig |
I used this implementation and created the proper API endpoints in api.ts and index.ts. Whenever the download button is clicked the link is changes to api.ts
DownloadSGF.vue
|
Ah, I forgot - we prepend There is another issue once you get that fixed. Edit: I had some "stream" stuff here before, but I found it can be much simpler:
|
Thank you for your help! The download SGF feature should be complete and is ready to be merged into the main branch. |
bd19ad0
to
d48a76a
Compare
@@ -182,6 +182,8 @@ test("Two passes ends the game", () => { | |||
|
|||
game.playMove(0, "pass"); | |||
game.playMove(1, "pass"); | |||
|
|||
expect(game.getSGF()).toBe("(;\nEV[GO Variants]\nPB[player Black]\nPW[player white]\nSZ[4:2]\nKM[6.5]\nVS[quantum]\n\n\n;B[ba];W[ca];B[bb];W[cb]\n\n)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I think I understand your comment on the other PR now
Are there any benefits to creating a more complex test?
I had written a standalone test, which has some benefits, but this is fine too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
packages/server/src/api.ts
Outdated
throw new Error(`SGF not supported for variant ${game.variant}`); | ||
} else if (game_obj.getSGF() === "non-rectangular"){ | ||
throw new Error('SGF for non rectangular boards is not possible'); | ||
} else if (!(game_obj.phase === 'gameover')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my own understanding is there something about SGF that requires the game to be finished? This is totally fine regardless, just wondering if we should consider implementing mid-game sgf download in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could definitely implement a mid-game sgf download if needed; it wouldn't require that much modification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could definitely implement a mid-game sgf download if needed; it wouldn't require that much modification.
We could definitely implement a mid-game sgf download if needed; it wouldn't require that much modification.
Now that I think about that, our current implementation relies on the game to be over before it saves the entire sgf. It is still possible but would require a different approach
Nice work, thank you Sameer! I'll test a bit then merge later tonight or tomorrow |
No problem! I'll do one more commit with the updated yarn lock! |
The yarn lock is good as is! |
When merging, I noticed lints and tests failed. Here are the commands to run them locally:
I have a precommit hook set up to run these before every commit, so I don't have to think about it. Pretty easy to set up - just add a file named
|
Changes are live! |
Currently the SGF data for a quantum game is stored in the
this.sgfContent
variable inquantum.ts
. For the user to download this, I also created a download button inDownloadSGF.vue
, in the GameView folder, however I'm not sure how to move the contents of thethis.sgfContent
string from the typescript file to the vue file.