Skip to content

Commit

Permalink
Add a button to refresh trade proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Oct 29, 2024
1 parent 80a339f commit cbaad0d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,11 @@ god mode should allow forcing trades after the trade deadline https://discord.co

hockey positions revamp
- make centers and wings more similar, centers are just better at faceoffs and maybe defense
- more offensive defensemen
- more offensive defensemen, especially fast ones
- defensemen need more shots, wingers need less https://discord.com/channels/@me/662077709836484618/1004952271710326794
- defensemen need more assists https://discord.com/channels/290013534023057409/816359356424912976/1010633509985063055
- point distribution discussion https://mail.google.com/mail/u/0/#inbox/FMfcgzGqQJfsRgnzBpRXKxGQkFmqCnNr
- https://discord.com/channels/@me/778760871911751700/1300282434306310187

how should scouting budget work in no ratings mode?
- disables it, but the number/expense is still there, and changes over time. i think it's from the old days where you'd want some standard value there. but now it's kind of weird because the value is not always the same, especially for AI teams
Expand Down
2 changes: 2 additions & 0 deletions src/common/defaultGameAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const gameAttributesKeysGameState: GameAttributeKey[] = [
"expansionDraft",
"autoRelocate",
"autoExpand",
"tradeProposalsSeed",
];
export const gameAttributesKeysTeams: GameAttributeKey[] = ["confs", "divs"];
export const gameAttributesCache: GameAttributeKey[] = [
Expand Down Expand Up @@ -353,6 +354,7 @@ const defaultGameAttributes: GameAttributesLeagueWithHistory = {
contactFactor: 1,

neutralSite: "never",
tradeProposalsSeed: 0,
};

// Extra condition for NODE_ENV is because we use this export only in tests, so we don't want it in the basketball bundle!
Expand Down
2 changes: 2 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ export type GameAttributesLeague = {
disabled: boolean | undefined;
}[];
tradeDeadline: number;
tradeProposalsSeed: number;
tragicDeathRate: number;
tragicDeaths?: TragicDeaths;
userTid: number;
Expand Down Expand Up @@ -1825,6 +1826,7 @@ export type UpdateEvents = (
| "firstRun"
| "g.goatFormula"
| "g.goatSeasonFormula"
| "g.tradeProposalsSeed"
| "gameAttributes"
| "gameSim"
| "leagues"
Expand Down
16 changes: 16 additions & 0 deletions src/ui/views/TradeProposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
playerScore,
} from "./TradingBlock";
import { useEffect, useState } from "react";
import { ActionButton } from "../components";

const TradeProposals = (props: View<"tradeProposals">) => {
const {
Expand Down Expand Up @@ -44,6 +45,8 @@ const TradeProposals = (props: View<"tradeProposals">) => {

const { teamInfoCache } = useLocalPartial(["teamInfoCache"]);

const [refreshing, setRefreshing] = useState(false);

if (spectator) {
return <p>You're not allowed to make trades in spectator mode.</p>;
}
Expand Down Expand Up @@ -115,6 +118,19 @@ const TradeProposals = (props: View<"tradeProposals">) => {
These are trade proposals from up to 5 AI teams. New teams will appear
here every 10 games.
</p>
<ActionButton
className="mb-3"
onClick={async () => {
setRefreshing(true);
await toWorker("main", "incrementTradeProposalsSeed", undefined);
setRefreshing(false);
}}
processing={refreshing}
processingText="Loading"
variant="secondary"
>
Refresh trade proposals
</ActionButton>
<div className="d-none d-lg-block">
<OfferTable
assetCols={[
Expand Down
9 changes: 9 additions & 0 deletions src/worker/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,14 @@ const importPlayers = async ({
await toUI("realtimeUpdate", [["playerMovement"]]);
};

const incrementTradeProposalsSeed = async () => {
await league.setGameAttributes({
tradeProposalsSeed: g.get("tradeProposalsSeed") + 1,
});

await toUI("realtimeUpdate", [["g.tradeProposalsSeed"]]);
};

const init = async (inputEnv: Env, conditions: Conditions) => {
Object.assign(env, inputEnv);

Expand Down Expand Up @@ -4521,6 +4529,7 @@ export default {
handleUploadedDraftClass,
idbCacheFlush,
importPlayers,
incrementTradeProposalsSeed,
init,
initGold,
loadRetiredPlayers,
Expand Down
6 changes: 4 additions & 2 deletions src/worker/views/tradeProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const updateTradeProposals = async (
updateEvents.includes("firstRun") ||
updateEvents.includes("playerMovement") ||
updateEvents.includes("gameSim") ||
updateEvents.includes("newPhase")
updateEvents.includes("newPhase") ||
updateEvents.includes("g.tradeProposalsSeed")
) {
const teamSeason = await idb.cache.teamSeasons.indexGet(
"teamSeasonsByTidSeason",
Expand All @@ -138,7 +139,8 @@ const updateTradeProposals = async (
const seed =
Math.floor(gp / NUM_GAMES_BEFORE_NEW_OFFERS) +
g.get("season") +
g.get("phase");
g.get("phase") +
g.get("tradeProposalsSeed");

const offers = await getOffers(seed);

Expand Down
3 changes: 3 additions & 0 deletions tools/lib/generateJSONSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,9 @@ const generateJSONSchema = (sport /*: string*/) => {
type: "string",
enum: ["never", "finals", "playoffs"],
},
tradeProposalsSeed: {
type: "integer",
},
},
},
],
Expand Down

0 comments on commit cbaad0d

Please sign in to comment.