Skip to content

Commit

Permalink
more than in Credits; warning clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Egner authored and Jacob Egner committed Apr 22, 2024
1 parent b3873e3 commit 07cd448
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 84 deletions.
12 changes: 6 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useEffect, useState } from 'react';
import { Col, Container, Row } from 'react-bootstrap';
import { useSearchParams } from 'react-router-dom';
import { ErrorBoundary } from 'react-error-boundary';
import { useSearchParams } from 'react-router-dom';

import * as Util from 'src/Util';
import { CalculatorViewChoice } from 'src/CalculatorViewChoice';
import { centerHoriz, } from 'src/Util';
import AppHeader from "src/components/AppHeader";
import ShootSection from 'src/components/ShootSection';
import { DeadzoneSection } from 'src/components/Deadzone/DeadzoneSection';
import FightSection from 'src/components/FightSection';
import ShootMassAnalysisSection from 'src/components/ShootMassAnalysisSection';
import ShootSection from 'src/components/ShootSection';
import WorldOfTanksSection from 'src/components/WorldOfTanks/WorldOfTanksSection';
import { DeadzoneSection } from 'src/components/Deadzone/DeadzoneSection';

const _viewToAdditionalTexts: Map<CalculatorViewChoice, string[]> = new Map([
[CalculatorViewChoice.KtShoot, ['shoot']],
Expand Down Expand Up @@ -41,7 +41,7 @@ function fallbackRender({ error, resetErrorBoundary }: { error: Error, resetErro

const App = () => {
const [currentView, setCurrentView] = useState<CalculatorViewChoice>(CalculatorViewChoice.KtShoot);
const [urlParams, setUrlParams] = useSearchParams(); // eslint-disable-line no-unused-vars
const [urlParams, /*setUrlParams*/] = useSearchParams();

useEffect( () => {
const viewText = urlParams.get('view')
Expand Down Expand Up @@ -72,7 +72,7 @@ const App = () => {
<AppHeader navCallback={setCurrentView} currentView={currentView} />
<Container>
<Row>
<Col className={Util.centerHoriz + ' p-0'} style={{fontSize: '11px'}}>
<Col className={centerHoriz + ' p-0'} style={{fontSize: '11px'}}>
Starred (*) items have explanations in hovertext and 'Notes' at bottom.
</Col>
</Row>
Expand Down
1 change: 0 additions & 1 deletion src/CalcEngineShootInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as Util from 'src/Util';
import FinalDiceProb from 'src/FinalDiceProb';
import * as Common from 'src/CalcEngineCommon';
import Ability from "src/Ability";
import { e } from "mathjs";

class DefenderFinalDiceStuff {
public finalDiceProbs: FinalDiceProb[];
Expand Down
1 change: 0 additions & 1 deletion src/Deadzone/CalcEngine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { randomInt } from "mathjs";
import { executeAndMeasureMs, } from 'src/Util';
import { DeadzoneModel, DeadzoneOptions, deadzoneCalcDmgProbs } from "src/DiceSim/pkg/dice_sim";

Expand Down
8 changes: 8 additions & 0 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ export function makePropChangeHandlers<T>(
];
}

export function makeTextChangeHandler<T>(
obj: T,
objChangeHandler: (t: T) => void,
) : (propName: keyof T) => Accepter<string>
{
return makePropChangeHandler(obj, objChangeHandler);
}

export function makeNumChangeHandler<T>(
obj: T,
objChangeHandler: (t: T) => void,
Expand Down
9 changes: 5 additions & 4 deletions src/components/AttackerControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

import IncDecSelect, {Props as IncProps, propsToRows} from 'src/components/IncDecSelect';
import {Props as IncProps, propsToRows} from 'src/components/IncDecSelect';
import {
Accepter,
boolToCheckX,
extractFromSet,
incDecPropsHasNondefaultSelectedValue,
makePropChangeHandlers,
makeNumChangeHandler,
makeSetChangeHandler,
makeSetChangeHandlerForSingle,
makeTextChangeHandler,
preX,
requiredAndOptionalItemsToTwoCols,
rollSpan,
Expand All @@ -35,8 +36,8 @@ export interface Props {

const AttackerControls: React.FC<Props> = (props: Props) => {
const atk = props.attacker;
const [textHandler, numHandler, boolHandler]
= makePropChangeHandlers(atk, props.changeHandler);
const textHandler = makeTextChangeHandler(atk, props.changeHandler);
const numHandler = makeNumChangeHandler(atk, props.changeHandler);
const [advancedCheckbox, wantShowAdvanced] = useCheckboxAndVariable('Advanced');
//const noCoverChoices = Object.values(NoCoverType);

Expand Down
8 changes: 5 additions & 3 deletions src/components/Credits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export interface Props {
const Credits: React.FC<Props> = (props: Props) => {
return (
<p>
<a href="https://github.com/jmegner/KT21Calculator">GitHub source code repository</a> <br />
Authored by <a href="https://github.com/jmegner">Jacob Egner</a>.<br />
{props.showInspiration && <>Inspired by <a href="https://github.com/ramainen">Damir Fakhrutdinov</a>'s Monte-Carlo-based <a href="http://kt2.doit-cms.ru/">Kill Team Simulator 2</a>.<br /></>}
<a href="https://github.com/jmegner/KT21Calculator">GitHub source code repository</a><br/>
Feature requests and bug reports can be <a href="https://github.com/jmegner/KT21Calculator/issues">made here</a>.<br/>
Authored by <a href="https://github.com/jmegner">Jacob Egner</a>.<br/>
My thanks for code contributions by <a href="https://github.com/veddermatic">Dave/veddermatic</a> and <a href='https://github.com/daespinozah'>Daniel Espinoza-Hernandez</a>.<br/>
{props.showInspiration && <>Inspired by <a href="https://github.com/ramainen">Damir Fakhrutdinov</a>'s Monte-Carlo-based <a href="http://kt2.doit-cms.ru/">Kill Team Simulator 2</a>.<br/></>}
</p>
);
}
Expand Down
19 changes: 11 additions & 8 deletions src/components/Deadzone/ModelControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

import IncDecSelect, {Props as IncProps} from 'src/components/IncDecSelect';
import * as Util from 'src/Util';
import {
Accepter,
makeNumChangeHandler,
span,
} from 'src/Util';
import { DeadzoneModel, } from "src/DiceSim/pkg/dice_sim";


export interface Props {
model: DeadzoneModel;
isAttacker: boolean;
changeHandler: Util.Accepter<DeadzoneModel>;
changeHandler: Accepter<DeadzoneModel>;
}

const ModelControls: React.FC<Props> = (props: Props) => {
const model = props.model;
const [textHandler, numHandler, boolHandler]
= Util.makePropChangeHandlers(model, props.changeHandler);
const diceSpan = Util.span(props.isAttacker ? 1 : 0, 9);
const intSpan = Util.span(0, 9);
const numHandler = makeNumChangeHandler(model, props.changeHandler);
const diceSpan = span(props.isAttacker ? 1 : 0, 9);
const intSpan = span(0, 9);

let params: IncProps[] = [
// id/label, selectedValue, values, valueChangeHandler
new IncProps('HP', model.hp, Util.span(1,10), numHandler('hp')),
new IncProps('HP', model.hp, span(1,10), numHandler('hp')),
new IncProps('Dice', model.numDice, diceSpan, numHandler('numDice')),
new IncProps('Stat(RA/FI/SV)', model.diceStat + "+", Util.span(1, 8, '+'), numHandler('diceStat')),
new IncProps('Stat(RA/FI/SV)', model.diceStat + "+", span(1, 8, '+'), numHandler('diceStat')),
new IncProps('Rerolls', model.numRerolls, intSpan, numHandler('numRerolls')),
new IncProps('Toxic/Dismantle', model.toxicDmg, intSpan, numHandler('toxicDmg')),
new IncProps('AP', model.ap, intSpan, numHandler('ap')),
Expand Down
18 changes: 9 additions & 9 deletions src/components/Deadzone/OptionControls.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from 'react';
import Col from 'react-bootstrap/Col';
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

import IncDecSelect, {Props as IncProps, propsToRows} from 'src/components/IncDecSelect';
import { Props as IncProps, propsToRows } from 'src/components/IncDecSelect';
import { DeadzoneOptions } from "src/DiceSim/pkg/dice_sim";
import {
Accepter,
makePropChangeHandlers,
span,
xAndCheck,
boolToCheckX,
makeBoolChangeHandler,
makeIncDecPropsFromLookup,
makeNumChangeHandler,
requiredAndOptionalItemsToTwoCols,
span,
xAndCheck,
} from 'src/Util';

export interface Props {
Expand All @@ -22,15 +23,14 @@ export interface Props {

const OptionControls: React.FC<Props> = (props: Props) => {
const opts = props.options;
// eslint-disable-next-line
const [textHandler, numHandler, boolHandler]
= makePropChangeHandlers(opts, props.changeHandler);
const numHandler = makeNumChangeHandler(opts, props.changeHandler);
const boolHandler = makeBoolChangeHandler(opts, props.changeHandler);

const simCountToDisplayTexts = new Map<number,string>([
[1, '1'],
[1e2, '100'],
[1e3, '1K'],
[1e4, '10K, recommended'],
[1e4, '10K, okay'],
[1e5, '100K, pretty accurate'],
[1e6, '1M, excessive'],
]);
Expand Down
12 changes: 5 additions & 7 deletions src/components/DefenderControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

import IncDecSelect, {Props as IncProps, propsToRows} from 'src/components/IncDecSelect';
import {Props as IncProps, propsToRows} from 'src/components/IncDecSelect';
import Model from 'src/Model';
import Ability, {rerollAbilities as rerolls} from 'src/Ability';
import * as N from 'src/Notes';
Expand All @@ -12,12 +12,11 @@ import {
Accepter,
boolToCheckX,
incDecPropsHasNondefaultSelectedValue,
makePropChangeHandlers,
makeNumChangeHandler,
makeSetChangeHandlerForSingle,
makeTextChangeHandler,
preX,
requiredAndOptionalItemsToTwoCols,
span,
thickX,
withPlus,
xAndCheck,
xrollSpan,
Expand All @@ -33,9 +32,8 @@ export interface Props {

const DefenderControls: React.FC<Props> = (props: Props) => {
const def = props.defender;
const [textHandler, numHandler, /*boolHandler*/]
= makePropChangeHandlers(def, props.changeHandler);
//const [wantShowAdvanced, setWantShowAdvanced] = React.useState(false);
const textHandler = makeTextChangeHandler(props.defender, props.changeHandler);
const numHandler = makeNumChangeHandler(props.defender, props.changeHandler);
const [advancedCheckbox, wantShowAdvanced] = useCheckboxAndVariable('Advanced');

function singleHandler(ability: Ability) {
Expand Down
19 changes: 12 additions & 7 deletions src/components/FightOptionControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ import {
Row,
} from 'react-bootstrap';

import IncDecSelect, {Props as IncProps} from 'src/components/IncDecSelect';
import * as Util from 'src/Util';
import FightStrategy from 'src/FightStrategy';
import FightOptions from 'src/FightOptions';
import FightStrategy from 'src/FightStrategy';
import {
Accepter,
makeNumChangeHandler,
makeTextChangeHandler,
span,
} from 'src/Util';
import IncDecSelect, { Props as IncProps } from 'src/components/IncDecSelect';


export interface Props {
fightOptions: FightOptions;
changeHandler: Util.Accepter<FightOptions>;
changeHandler: Accepter<FightOptions>;
}

const FightOptionControls: React.FC<Props> = (props: Props) => {
Expand All @@ -23,15 +28,15 @@ const FightOptionControls: React.FC<Props> = (props: Props) => {
const numRoundsId = 'Rounds';
const strategies = Object.values(FightStrategy);
const opts = props.fightOptions;
const [textHandler, numHandler, ]
= Util.makePropChangeHandlers(opts, props.changeHandler);
const textHandler = makeTextChangeHandler(opts, props.changeHandler);
const numHandler = makeNumChangeHandler(opts, props.changeHandler);

const params: IncProps[] = [
// id/label, selectedValue, values, valueChangeHandler
new IncProps(strategyFighterAId, opts.strategyFighterA, strategies, textHandler('strategyFighterA')),
new IncProps(strategyFighterBId, opts.strategyFighterB, strategies, textHandler('strategyFighterB')),
new IncProps(firstFighterId, opts.firstFighter, ['A', 'B'], textHandler('firstFighter')),
new IncProps(numRoundsId, opts.numRounds, Util.span(1, 3), numHandler('numRounds')),
new IncProps(numRoundsId, opts.numRounds, span(1, 3), numHandler('numRounds')),
];

const paramCols = params.map(p =>
Expand Down
25 changes: 13 additions & 12 deletions src/components/FighterControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ import {
Row,
} from 'react-bootstrap';

import {Props as IncProps, propsToRows} from 'src/components/IncDecSelect';
import Ability, {
eliteAbilities,
mutuallyExclusiveFightAbilities as nicheAbilities,
rerollAbilities as rerolls
} from 'src/Ability';
import Model from 'src/Model';
import * as N from 'src/Notes';
import {
Accepter,
boolToCheckX,
extractFromSet,
incDecPropsHasNondefaultSelectedValue,
makePropChangeHandlers,
makeNumChangeHandler,
makeSetChangeHandler,
makeSetChangeHandlerForSingle,
makeTextChangeHandler,
preX,
requiredAndOptionalItemsToTwoCols,
rollSpan,
span,
xAndCheck,
xspan,
} from 'src/Util';
import Model from 'src/Model';
import Ability, {
eliteAbilities,
mutuallyExclusiveFightAbilities as nicheAbilities,
rerollAbilities as rerolls
} from 'src/Ability';
import * as N from 'src/Notes';
import { Props as IncProps, propsToRows } from 'src/components/IncDecSelect';
import { useCheckboxAndVariable } from 'src/hooks/useCheckboxAndVariable';


Expand All @@ -40,8 +41,8 @@ export interface Props {

const FighterControls: React.FC<Props> = (props: Props) => {
const atk = props.attacker;
const [textHandler, numHandler, boolHandler]
= makePropChangeHandlers(atk, props.changeHandler);
const textHandler = makeTextChangeHandler(atk, props.changeHandler);
const numHandler = makeNumChangeHandler(atk, props.changeHandler);
const [advancedCheckbox, wantShowAdvanced] = useCheckboxAndVariable('Advanced');

function subsetHandler(subset: Iterable<Ability>) {
Expand Down Expand Up @@ -87,7 +88,7 @@ const FighterControls: React.FC<Props> = (props: Props) => {
new IncProps(N.AutoCrits, atk.autoCrits, xspan(1, 9), numHandler('autoCrits')),
new IncProps(N.NormsToCrits, atk.normsToCrits, xspan(1, 9), numHandler('normsToCrits')),
new IncProps(N.FailsToNorms, atk.failsToNorms, xspan(1, 9), numHandler('failsToNorms')),
new IncProps(N.FailToNormIfCrit, toYN(Ability.FailToNormIfCrit), xAndCheck, singleHandler(Ability.FailToNormIfCrit)),
new IncProps(N.FailToNormIfCrit, toYN(Ability.FailToNormIfCrit), xAndCheck, singleHandler(Ability.FailToNormIfCrit)),
new IncProps('ElitePoints*', eliteAbility, eliteAbilities, subsetHandler(eliteAbilities)),
new IncProps(N.Duelist, toYN(Ability.Duelist), xAndCheck, singleHandler(Ability.Duelist)),
new IncProps(N.JustAScratch, toYN(Ability.JustAScratch), xAndCheck, singleHandler(Ability.JustAScratch)),
Expand Down
18 changes: 9 additions & 9 deletions src/components/ShootOptionControls.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from 'react';
import Col from 'react-bootstrap/Col';
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

import IncDecSelect, {Props as IncProps} from 'src/components/IncDecSelect';
import ShootOptions from 'src/ShootOptions';
import * as N from 'src/Notes';
import ShootOptions from 'src/ShootOptions';
import {
Accepter,
boolToCheckX as toCheckX,
makePropChangeHandlers,
makeBoolChangeHandler,
makeNumChangeHandler,
span,
boolToCheckX as toCheckX,
xAndCheck,
} from 'src/Util';
import IncDecSelect, { Props as IncProps } from 'src/components/IncDecSelect';

export interface Props {
shootOptions: ShootOptions;
Expand All @@ -21,12 +22,11 @@ export interface Props {

const ShootOptionControls: React.FC<Props> = (props: Props) => {
const opts = props.shootOptions;
// eslint-disable-next-line
const [textHandler, numHandler, boolHandler]
= makePropChangeHandlers(opts, props.changeHandler);
const numHandler = makeNumChangeHandler(opts, props.changeHandler);
const boolHandler = makeBoolChangeHandler(opts, props.changeHandler);

const params: IncProps[] = [
// id, selectedValue,values, valueChangeHandler
// id, selectedValue, values, valueChangeHandler
new IncProps('Rounds', opts.numRounds, span(1, 9), numHandler('numRounds')),
new IncProps(N.FireTeamRules, toCheckX(opts.isFireTeamRules), xAndCheck, boolHandler('isFireTeamRules')),
];
Expand Down
7 changes: 6 additions & 1 deletion src/components/ShootResultsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import Accordion from 'react-bootstrap/Accordion';
import 'src/components/Accordion.css'

import Model from 'src/Model';
import { toAscendingMap, weightedAverage, killProb, standardDeviation, } from 'src/Util';
import {
toAscendingMap,
weightedAverage,
killProb,
standardDeviation,
} from 'src/Util';
import { range } from 'lodash';

export interface Props {
Expand Down
Loading

0 comments on commit 07cd448

Please sign in to comment.