Skip to content
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

Random game chooser #145

Open
cronyakatsuki opened this issue Jul 15, 2023 · 2 comments
Open

Random game chooser #145

cronyakatsuki opened this issue Jul 15, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@cronyakatsuki
Copy link

So I'm the kind of gamer that can't decide what to play and just keeps on either not playing anything or downloads yet another game to play.

One way that I used to do to beat this is to use the random game picker like the one that playnite has built in.

So is there a way for there to be implemented a feature for cartridges to randomly choose a game, doesnt need to start it but just to choose.

@cronyakatsuki cronyakatsuki added the enhancement New feature or request label Jul 15, 2023
@kra-mo kra-mo self-assigned this Jul 17, 2023
@kra-mo kra-mo moved this to Todo in Cartridges Roadmap Jul 17, 2023
@michaelneverwins
Copy link

michaelneverwins commented Aug 23, 2023

You've inspired me to implement a random game chooser myself... not in the Cartridges code, but as a "game" I've added to Cartridges. This isn't exactly what you want, because it goes right ahead and launches the game rather than just showing what it chose, but...

random

The command it runs:

eval $(grep -EL '"name": "!!! RANDOM !!!"|"(hidden|removed)": true' ~/.var/app/hu.kramo.Cartridges/data/cartridges/games/*.json | sort -R | head -n 1 | xargs grep -oP '"executable": "\K.+(?=",$)' | sed s/'\\"'/'"'/g)

Well, I thought it was funny. Use it at your own risk, of course. It's probably wise to assume eval $(some command that returns a string) can be dangerous. This particular command is meant to be only as dangerous as commands already added to Cartridges, but I never guarantee that code I write is bug-free.

@cronyakatsuki
Copy link
Author

@michaelneverwins I have went ahead and reddid your command into a simple script that just shows a dmenu prompt saying which game it choose and whether you wan't to play it or not.

I'm also using jq instead of grep since it does better job than regex and can easily output for games that have executable set as an array.

#!/bin/sh

random=$(jq 'select(.hidden != true) | select(.removed != true) | select(.name | contains("Proton") | not) | select(.name | contains("Steam") | not) | input_filename' -r $HOME/.local/share/cartridges/games/*.json | sort -R | head -n 1)
name=$(jq '.name' -r "$random")
exec=$(jq '.executable | if type == "array" then .[] end' -r "$random")
echo $name
echo $exec

answer=$(printf "yes\nno" | dmenu -p "Want to play $name?")

[ "$answer" = "yes" ] && eval $exec || exit

You can replace dmenu with any other program, like zenity probably for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

3 participants