8000 Add option to show all charts by noahm · Pull Request #50 · noahm/DDRCardDraw · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"offline-plugin": "^5.0.7",
"p-queue": "^6.6.0",
"postcss-loader": "^3.0.0",
"preact": "^10.3.2",
"preact": "^10.5.0",
"preact-feather": "^4.1.0",
"prettier": "^1.19.1",
"query-string": "^6.13.1",
Expand Down
1 change: 1 addition & 0 deletions scripts/import-smx.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async function main() {
style: diff === "team" ? "team" : "solo",
lvl: score.difficulty,
diffClass: diff,
author: score.steps_author,
});
if (score.difficulty > lvlMax) {
lvlMax = score.difficulty;
Expand Down
3 changes: 3 additions & 0 deletions songs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
},
"jacket": {
"type": "string"
},
"author": {
"type": "string"
}
},
"required": ["lvl", "diffClass", "style"]
Expand Down
6 changes: 0 additions & 6 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
if (process.env.NODE_ENV === "development") {
// Must use require here as import statements are only allowed
// to exist at the top of a file.
require("preact/debug");
}

import "./firebase";
import { render } from "preact";
import { Controls } from "./controls";
Expand Down
6 changes: 4 additions & 2 deletions src/assets/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"reset": "Reset",
"cancel": "Cancel"
},
"noValidCharts": "No valid charts"
"noValidCharts": "No valid charts",
"showSongPool": "Show valid charts"
},
"ja": {
"dataSource": "ゲーム",
Expand Down Expand Up @@ -175,6 +176,7 @@
"reset": "Reset",
"cancel": "Cancel"
},
"noValidCharts": "No valid charts"
"noValidCharts": "No valid charts",
"showSongPool": "Show valid charts"
}
}
Binary file added src/assets/jackets/smx/Boomerang.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/jackets/smx/CanonD.2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/jackets/smx/CloserToHeaven.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/jackets/smx/GiveYouLove.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/jackets/smx/GrabItWhileWeCan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/jackets/smx/NeverEndingStory.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/jackets/smx/WilliamTell.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 20 additions & 18 deletions src/card-draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ export function chartIsValid(config: ConfigState, chart: Chart): boolean {
);
}

export function* filterChartsToSongs(config: ConfigState, songs: Song[]) {
for (const currentSong of songs) {
if (!songIsValid(config, currentSong)) {
continue;
}
const charts = currentSong.charts.filter((c) => c.style === config.style);

for (const chart of currentSong.charts) {
if (!chartIsValid(config, chart)) {
continue;
}

// add chart to deck
yield getDrawnChart(currentSong, chart);
}
}
}

/**
* Produces a drawn set of charts given the song data and the user
* input of the html form elements.
Expand All @@ -50,10 +68,6 @@ export function draw(gameData: GameData, configData: ConfigState): Drawing {
upperBound,
lowerBound,
style,
// requested difficulties
difficulties,
// other options: usLocked, extraExclusive, removed, unlock
flags: inclusions,
useWeights,
forceDistribution,
weights,
Expand All @@ -64,20 +78,8 @@ export function draw(gameData: GameData, configData: ConfigState): Drawing {
validCharts[n.toString()] = [];
});

for (const currentSong of gameData.songs) {
if (!songIsValid(configData, currentSong)) {
continue;
}
const charts = currentSong.charts.filter((c) => c.style === style);

for (const chart of currentSong.charts) {
if (!chartIsValid(configData, chart)) {
continue;
}

// add chart to deck
validCharts[chart.lvl].push(getDrawnChart(currentSong, chart));
}
for (const chart of filterChartsToSongs(configData, gameData.songs)) {
validCharts[chart.level].push(chart);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/config-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ConfigState {
style: string;
difficulties: ReadonlySet<string>;
flags: ReadonlySet<string>;
showPool: boolean;
update(mutator: (state: ConfigState) => ConfigState): void;
}

Expand All @@ -32,7 +33,8 @@ export class ConfigStateManager extends Component<Props, ConfigState> {
style: "",
difficulties: new Set(),
flags: new Set(),
update: this.update
showPool: false,
update: this.update,
};
}

Expand Down
25 changes: 24 additions & 1 deletion src/controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getAvailableDifficulties(gameData: GameData, selectedStyle: string) {
}

export function Controls() {
const form = useRef<HTMLFormElement>();
const form = useRef<HTMLFormElement>(null);
const [collapsed, setCollapsed] = useState(true);
const { t } = useContext(TranslateContext);
const {
Expand All @@ -51,6 +51,7 @@ export function Controls() {
flags: selectedFlags,
style: selectedStyle,
chartCount,
showPool,
} = configState;
const availableDifficulties = useMemo(() => {
if (!gameData) {
Expand Down Expand Up @@ -101,6 +102,12 @@ export function Controls() {

const handleRandomize = (e: JSXInternal.TargetedEvent<HTMLButtonElement>) => {
e.preventDefault();
if (showPool) {
updateState((state) => ({
...state,
showPool: false,
}));
}
drawSongs(configState);
};

Expand Down Expand Up @@ -292,6 +299,22 @@ export function Controls() {
))}
</div>
)}
<div className={styles.group}>
<label>
<input
type="checkbox"
name="showPool"
checked={showPool}
=>
updateState((state) => ({
...state,
showPool: !!e.currentTarget.checked,
}))
}
/>
{t("showSongPool")}
</label>
</div>
<div className={classNames(globalStyles.padded, styles.buttons)}>
<button "}
<button => setCollapsed(!collapsed)}>
Expand Down
7 changes: 7 additions & 0 deletions src/drawing-list.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
}
}

.chartList {
display: flex;
padding: 10px;
overflow: hidden;
flex-wrap: wrap;
}

.sectionLabel {
text-indent: 10px;
}
38 changes: 31 additions & 7 deletions src/drawing-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,40 @@ import styles from "./drawing-list.css";
import { DrawStateContext } from "./draw-state";
import { Drawing } from "./models/Drawing";
import { memo } from "preact/compat/src";
import { ConfigStateContext } from "./config-state";
import { filterChartsToSongs } from "./card-draw";
import { SongCard } from "./song-card";

const renderDrawing = (drawing: Drawing) => (
<DrawnSet key={drawing.id} drawing={drawing} />
);

function renderScrollableDrawings(drawings: Drawing[]) {
return <div className={styles.scrollable}>{drawings.map(renderDrawing)}</div>;
}

export const DrawingList = memo(() => {
const { drawings } = useContext(DrawStateContext);
return renderScrollableDrawings(drawings);
const ScrollableDrawings = memo((props: { drawings: Drawing[] }) => {
return (
<div className={styles.scrollable}>{props.drawings.map(renderDrawing)}</div>
);
});

export function DrawingList() {
const { drawings, gameData } = useContext(DrawStateContext);
const configState = useContext(ConfigStateContext);
if (configState.showPool && gameData) {
const charts = Array.from(filterChartsToSongs(configState, gameData.songs));
const songs = new Set<string>();
const cards = charts.map((chart, index) => {
songs.add(chart.name);
return <SongCard chart={chart} key={index} />;
});
return (
<>
<div style={{ padding: "1em" }}>
Eligible songs: {charts.length} total charts from {songs.size} songs
</div>
<div className={styles.scrollable}>
<div className={styles.chartList}>{cards}</div>
</div>
</>
);
}
return <ScrollableDrawings drawings={drawings} />;
}
10BC8 50 changes: 26 additions & 24 deletions src/drawn-set.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Drawing,
DrawnChart,
PlayerActionOnChart,
PocketPick
PocketPick,
} from "./models/Drawing";

const HUE_STEP = (255 / 8) * 3;
Expand Down Expand Up @@ -37,32 +37,34 @@ export class DrawnSet extends Component<Props> {
}

renderChart = (chart: DrawnChart, index: number) => {
const veto = this.props.drawing.bans.find(b => b.chartIndex === index);
const veto = this.props.drawing.bans.find((b) => b.chartIndex === index);
const protect = this.props.drawing.protects.find(
b => b.chartIndex === index
(b) => b.chartIndex === index
);
const pocketPick = this.props.drawing.pocketPicks.find(
b => b.chartIndex === index
(b) => b.chartIndex === index
);
return (
<SongCard
key={index}
>
this,
this.props.drawing.bans,
index
)}
>
this,
this.props.drawing.protects,
index
)}
>
this,
this.props.drawing.pocketPicks,
index
)}
index)}
iconCallbacks={{
onVeto: this.handleBanProtectReplace.bind(
this,
this.props.drawing.bans,
index
),
onProtect: this.handleBanProtectReplace.bind(
this,
this.props.drawing.protects,
index
),
onReplace: this.handleBanProtectReplace.bind(
this,
this.props.drawing.pocketPicks,
index
),
onReset: this.handleReset.bind(this, index),
}}
vetoedBy={veto && veto.player}
protectedBy={protect && protect.player}
replacedBy={pocketPick && pocketPick.player}
Expand All @@ -78,7 +80,7 @@ export class DrawnSet extends Component<Props> {
player: 1 | 2,
chart?: DrawnChart
) {
const existingBanIndex = arr.findIndex(b => b.chartIndex === chartIndex);
const existingBanIndex = arr.findIndex((b) => b.chartIndex === chartIndex);
if (existingBanIndex >= 0) {
arr.splice(existingBanIndex, 1);
} else {
Expand All @@ -89,12 +91,12 @@ export class DrawnSet extends Component<Props> {

handleReset(chartIndex: number) {
const drawing = this.props.drawing;
drawing.bans = drawing.bans.filter(p => p.chartIndex !== chartIndex);
drawing.bans = drawing.bans.filter((p) => p.chartIndex !== chartIndex);
drawing.protects = drawing.protects.filter(
p => p.chartIndex !== chartIndex
(p) => p.chartIndex !== chartIndex
);
drawing.pocketPicks = drawing.pocketPicks.filter(
p => p.chartIndex !== chartIndex
(p) => p.chartIndex !== chartIndex
);
this.forceUpdate();
}
Expand Down
9 changes: 6 additions & 3 deletions src/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TranslateContext } from "@denysvuika/preact-translate";
import { About } from "./about";

// note that month is zero-indexed for date constructor :)
const lastUpdate = new Date(2021, 1, 13);
const lastUpdate = new Date(2021, 7, 25);

export function Footer() {
const { t } = useContext(TranslateContext);
Expand All @@ -20,12 +20,15 @@ export function Footer() {
{showAbout && <About => updateShowAbout(false)} />}
<div>
{t("lastUpdate", {
date: new Intl.DateTimeFormat(detectedLanguage).format(lastUpdate)
date: new Intl.DateTimeFormat(detectedLanguage).format(lastUpdate),
})}
</div>
<div className={styles.icons}>
{/* <AuthButton />{" "} */}
<a href="#" => (e.preventDefault(), updateShowAbout(true))}>
<a
href="#"
=> (e.preventDefault(), updateShowAbout(true))}
>
{t("credits")}
</a>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/models/SongData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ export interface Chart {
shock?: number;
freeze?: number;
jacket?: string;
author?: string;
}
7 changes: 5 additions & 2 deletions src/song-card/song-card.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
text-align: center;
border: 2px solid black;
border-radius: 5px;
cursor: pointer;
display: flex;
flex-direction: column;
min-height: 200px;
Expand All @@ -19,7 +18,11 @@
overflow: hidden;
transition: transform ease 0.3s;
position: relative;
min-width: 150px;
min-width: 165px;
}

.chart.clickable {
cursor: pointer;
}

.cardCenter {
Expand Down
Loading
0