Improve tile exchange to retain player order

This commit is contained in:
Joel Therrien 2023-08-23 20:37:22 -07:00
parent e8cff060b0
commit de2605af67

View file

@ -266,7 +266,10 @@ export function Game(props: {wasm: GameWasm, settings: Settings}) {
}}>{confirmedScorePoints > -1 ? `Score ${confirmedScorePoints} points ✅` : "Check"}</button> }}>{confirmedScorePoints > -1 ? `Score ${confirmedScorePoints} points ✅` : "Check"}</button>
<button <button
onClick={(e) => {setIsTileExchangeOpen(true);}} onClick={(e) => {
trayDispatch({action: TileDispatchActionType.RETURN}); // want all tiles back on tray for tile exchange
setIsTileExchangeOpen(true);
}}
>Open Tile Exchange</button> >Open Tile Exchange</button>
<button onClick={(e) => { <button onClick={(e) => {
trayDispatch({action: TileDispatchActionType.RETURN}); trayDispatch({action: TileDispatchActionType.RETURN});
@ -538,6 +541,10 @@ function TilesExchangedTray(props: {
}){ }){
const divContent = []; const divContent = [];
for(let i=0; i<props.trayLength; i++) {
divContent.push(<span key={i} />); // empty tile elements
}
for(let i = 0; i<props.trayLength; i++){ for(let i = 0; i<props.trayLength; i++){
const tileData = props.tray[i]; const tileData = props.tray[i];
@ -547,11 +554,9 @@ function TilesExchangedTray(props: {
} }
if(tileData != null){ if(tileData != null){
divContent.push( divContent[tileData.index] =
<DummyExchangeTile key={i} letter={tileData} isSelected={props.selectedArray[i]} onClick={toggleFunction}/> <DummyExchangeTile key={tileData.index} letter={tileData} isSelected={props.selectedArray[i]} onClick={toggleFunction}/>;
);
} else{
divContent.push(<span key={i} />);
} }
} }