Skip to content

Commit

Permalink
Merge pull request #14 from probablyraging/feat(skip-hidden-achieveme…
Browse files Browse the repository at this point in the history
…nts)

feat(skip hidden achievements)
  • Loading branch information
zevnda authored Aug 25, 2024
2 parents bb8d7e7 + b8a407f commit 92839ff
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 16 deletions.
1 change: 1 addition & 0 deletions components/Window.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function Window() {
},
achievementUnlocker: {
idle: true,
hidden: false,
interval: [30, 130],
}
};
Expand Down
33 changes: 25 additions & 8 deletions components/automation/AchievementUnlocker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ export default function AchievementUnlocker({ setActivePage }) {
const startAchievementUnlocker = async () => {
try {
const achievementUnlocker = JSON.parse(localStorage.getItem('achievementUnlocker')) || [];
const settings = JSON.parse(localStorage.getItem('settings')) || {};

if (achievementUnlocker.length < 1) {
logEvent('[Achievement Unlocker - Auto] No games left - stopping');
stopIdler(currentGame.appId);
if (currentGame) {
stopIdler(currentGame.appId);
}
setGamesWithAchievements(0);
setIsComplete(true);
return;
}

const { achievements, game } = await fetchAchievements(achievementUnlocker[0]);
const { achievements, game } = await fetchAchievements(achievementUnlocker[0], settings);

if (achievements.length > 0) {
await unlockAchievements(achievements, game);
await unlockAchievements(achievements, settings);
}

removeGameFromUnlockerList(game.game.id);
Expand All @@ -54,13 +57,13 @@ export default function AchievementUnlocker({ setActivePage }) {
};
}, []);

const fetchAchievements = async (gameData) => {
const fetchAchievements = async (gameData, settings) => {
const game = JSON.parse(gameData);
const userSummary = JSON.parse(localStorage.getItem('userSummary')) || {};

setCurrentGame({ appId: game.game.id, name: game.game.name });

const [userAchievementsResponse, gameAchievementsResponse] = await Promise.all([
const [userAchievementsResponse, gameAchievementsResponse, gameSchemaResponse] = await Promise.all([
fetch('https://apibase.vercel.app/api/route', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
Expand All @@ -70,6 +73,11 @@ export default function AchievementUnlocker({ setActivePage }) {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ route: 'game-achievement-percentage', appId: game.game.id }),
}),
fetch('https://apibase.vercel.app/api/route', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ route: 'game-schema', appId: game.game.id }),
})
]);

Expand All @@ -80,9 +88,19 @@ export default function AchievementUnlocker({ setActivePage }) {

const userAchievements = await userAchievementsResponse.json();
const gameAchievements = await gameAchievementsResponse.json();
const gameSchema = await gameSchemaResponse.json();

const achievements = userAchievements.achievements
.filter(achievement => !achievement.unlocked)
.filter(achievement => {
const schemaAchievement = gameSchema.availableGameStats.achievements.find(
a => a.name === achievement.name
);
if (settings.achievementUnlocker.hidden) {
return !achievement.unlocked && schemaAchievement.hidden === 0;
} else {
return !achievement.unlocked;
}
})
.map(achievement => {
const percentageData = gameAchievements.find(a => a.name === achievement.name);
return {
Expand All @@ -100,8 +118,7 @@ export default function AchievementUnlocker({ setActivePage }) {
return { achievements, game };
};

const unlockAchievements = async (achievements) => {
const settings = JSON.parse(localStorage.getItem('settings')) || {};
const unlockAchievements = async (achievements, settings) => {
const { interval, idle } = settings.achievementUnlocker;

if (idle) {
Expand Down
3 changes: 3 additions & 0 deletions components/gameslist/Automate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default function Automate({ setActivePage }) {
key='idle'
startContent={<IoGameController />}
onClick={startCardFarming}
textValue='Start achievement unlocker'
>
<p className='text-xs'>Start card farming</p>
</DropdownItem>
Expand All @@ -80,6 +81,7 @@ export default function Automate({ setActivePage }) {
key='achiements'
startContent={<FaAward />}
onClick={startAchievementUnlocker}
textValue='Start achievement unlocker'
>
<p className='text-xs'>Start achievement unlocker</p>
</DropdownItem>
Expand All @@ -88,6 +90,7 @@ export default function Automate({ setActivePage }) {
key='settings'
startContent={<IoSettings />}
onClick={() => setActivePage('settings')}
textValue='Change settings'
>
<p className='text-xs'>Change settings</p>
</DropdownItem>
Expand Down
8 changes: 8 additions & 0 deletions components/gameslist/CardMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function CardMenu({ item, favorites, cardFarming, achievementUnlo
key='idle'
startContent={<IoPlay />}
onClick={() => handleIdle(item.game.id, item.game.name)}
textValue='Idle game'
>
<p className='text-xs'>Idle game</p>
</DropdownItem>
Expand All @@ -28,6 +29,7 @@ export default function CardMenu({ item, favorites, cardFarming, achievementUnlo
key='achievements'
startContent={<FaAward />}
onClick={() => viewAchievments(item)}
textValue='View achievements'
>
<p className='text-xs'>View achievements</p>
</DropdownItem>
Expand All @@ -37,6 +39,7 @@ export default function CardMenu({ item, favorites, cardFarming, achievementUnlo
key='fav-rem'
startContent={<TiHeartFullOutline />}
onClick={(e) => removeFromFavorites(e, item)}
textValue='Remove from favorites'
>
<p className='text-xs'>Remove from favorites</p>
</DropdownItem>
Expand All @@ -46,6 +49,7 @@ export default function CardMenu({ item, favorites, cardFarming, achievementUnlo
key='fav-add'
startContent={<TiHeartFullOutline />}
onClick={(e) => addToFavorites(e, item)}
textValue='Add to favorites'
>
<p className='text-xs'>Add to favorites</p>
</DropdownItem>
Expand All @@ -56,6 +60,7 @@ export default function CardMenu({ item, favorites, cardFarming, achievementUnlo
key='cf-rem'
startContent={<TiMinus />}
onClick={(e) => removeFromCardFarming(e, item)}
textValue='Remove from card farming'
>
<p className='text-xs'>Remove from card farming</p>
</DropdownItem>
Expand All @@ -65,6 +70,7 @@ export default function CardMenu({ item, favorites, cardFarming, achievementUnlo
key='cf-add'
startContent={<TiPlus />}
onClick={(e) => addToCardFarming(e, item)}
textValue='Add to card farming'
>
<p className='text-xs'>Add to card farming</p>
</DropdownItem>
Expand All @@ -75,6 +81,7 @@ export default function CardMenu({ item, favorites, cardFarming, achievementUnlo
key='au-rem'
startContent={<TiMinus />}
onClick={(e) => removeFromAchievementUnlocker(e, item)}
textValue='Remove from achievement unlocker'
>
<p className='text-xs'>Remove from achievement unlocker</p>
</DropdownItem>
Expand All @@ -84,6 +91,7 @@ export default function CardMenu({ item, favorites, cardFarming, achievementUnlo
key='au-add'
startContent={<TiPlus />}
onClick={(e) => addToAchievementUnlocker(e, item)}
textValue='Add to achievement unlocker'
>
<p className='text-xs'>Add to achievement unlocker</p>
</DropdownItem>
Expand Down
4 changes: 2 additions & 2 deletions components/gameslist/GameAchievementList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export default function GameAchievementList({ gameList, favorites, cardFarming,
>
<Image
src={`https://cdn.cloudflare.steamstatic.com/steam/apps/${item.game.id}/header.jpg`}
layout='fill'
objectFit='cover'
width={460}
height={215}
alt={`${item.game.name} image`}
priority={true}
/>
Expand Down
4 changes: 2 additions & 2 deletions components/gameslist/GameIdleList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export default function GameIdleList({ gameList, favorites, cardFarming, achieve
>
<Image
src={`https://cdn.cloudflare.steamstatic.com/steam/apps/${item.game.id}/header.jpg`}
layout='fill'
objectFit='cover'
width={460}
height={215}
alt={`${item.game.name} image`}
priority={true}
/>
Expand Down
12 changes: 12 additions & 0 deletions components/settings/AchievementSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ export default function AchievementSettings({ settings, setSettings }) {
</div>
</Checkbox>

<Checkbox
name='hidden'
isSelected={localSettings.achievementUnlocker.hidden}
onChange={handleCheckboxChange}
>
<div className='flex items-center gap-1'>
<p className='text-xs'>
Skip hidden achievements
</p>
</div>
</Checkbox>

<Slider
label={
<div className='flex justify-between items-center gap-1 min-w-[350px]'>
Expand Down
1 change: 1 addition & 0 deletions components/settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function Settings() {
},
achievementUnlocker: {
idle: true,
hidden: false,
interval: [30, 130],
}
};
Expand Down
8 changes: 4 additions & 4 deletions components/settings/SettingsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ export default function SettingsMenu() {
</Button>
</DropdownTrigger>
<DropdownMenu aria-label='Settings actions'>
<DropdownItem key='help' className='rounded p-0 m-0'>
<DropdownItem key='help' className='rounded p-0 m-0' textValue='Help'>
<ExtLink href={'https://github.com/probablyraging/steam-game-idler/wiki'} className={'flex text-xs w-full px-2 py-1'}>
Help
</ExtLink>
</DropdownItem>
<DropdownItem key='changelog' className='rounded p-0 m-0'>
<DropdownItem key='changelog' className='rounded p-0 m-0' textValue='Changelog'>
<ExtLink href={'https://github.com/probablyraging/steam-game-idler/releases'} className={'flex text-xs w-full px-2 py-1'}>
Changelog
</ExtLink>
</DropdownItem>
<DropdownItem key='report' className='rounded p-0 m-0'>
<DropdownItem key='report' className='rounded p-0 m-0' textValue='Report an issue'>
<ExtLink href={'https://github.com/probablyraging/steam-game-idler/issues/new?assignees=ProbablyRaging&labels=bug%2Cinvestigating&projects=&template=issue_report.yml&title=Title'} className={'flex text-xs w-full px-2 py-1'}>
Report an issue
</ExtLink>
</DropdownItem>
<DropdownItem key='coffee' className='rounded p-0 m-0'>
<DropdownItem key='coffee' className='rounded p-0 m-0' textValue='Buy me a coffee'>
<ExtLink href={'https://buymeacoffee.com/probablyraging'} className={'flex text-xs w-full px-2 py-1'}>
Buy me a coffee
</ExtLink>
Expand Down

0 comments on commit 92839ff

Please sign in to comment.