Skip to content

Commit

Permalink
investing intel in UI now increases the amount of intel invested into…
Browse files Browse the repository at this point in the history
… the faction; improve SliderWithButton.tsx
  • Loading branch information
Konrad Jamrozik committed Jun 29, 2024
1 parent f2c5826 commit f514b31
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/game-lib/Controller/InvestIntelPlayerAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ public InvestIntelPlayerAction(ILog log, Faction faction, int intel)

protected override (List<int>? ids, int? targetId) ApplyImpl(GameState state)
{
// kja WIP InvestIntelPlayerAction

Console.Out.WriteLine($"Invest intel. Faction: '{_faction.Name}', Faction ID: {_faction.Id}, Intel: {_intel}");
Console.Out.WriteLine($"kja temp debug Invest intel. Faction: '{_faction.Name}', Faction ID: {_faction.Id}, Intel: {_intel}");
_log.Info($"Invest intel. Faction: '{_faction.Name}', Faction ID: {_faction.Id}, Intel: {_intel}");

Contract.Assert(state.Factions.Contains(_faction));
Contract.Assert(_intel > 0 && _intel <= state.Assets.Intel);

state.Assets.Intel -= _intel;
_faction.IntelInvested += _intel;

return (ids: [_faction.Id], targetId: _intel);
}
}
4 changes: 2 additions & 2 deletions src/game-lib/Model/Faction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class Faction : IIdentifiable
public int PowerAcceleration; // More derivatives: https://en.wikipedia.org/wiki/Fourth,_fifth,_and_sixth_derivatives_of_position
public int AccumulatedPowerAcceleration;
// kja implement: the more intel invested, the more faction damage missions are doing
// kja introduce "IntelRuleset", "MoneyRuleset" etc. It will make things easier to balance.
public readonly int IntelInvested;
// kja-refactor introduce "IntelRuleset", "MoneyRuleset" etc. It will make things easier to balance.
public int IntelInvested;


[JsonConstructor]
Expand Down
2 changes: 2 additions & 0 deletions src/game-lib/State/GameState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Lib.Contracts;
using Lib.Json;
using UfoGameLib.Lib;
using UfoGameLib.Model;
Expand Down Expand Up @@ -87,6 +88,7 @@ public void ToJsonFile(File file)

public void Terminate(Agent agent, bool sack = false)
{
Contract.Assert(Assets.Agents.Contains(agent));
Assets.Agents.Remove(agent);
agent.Terminate(Timeline.CurrentTurn, sack);
TerminatedAgents.Add(agent);
Expand Down
2 changes: 2 additions & 0 deletions web/src/components/FactionsDataGrid/FactionActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function FactionActions(
maxValue={props.gs.Assets.Intel}
iconName="Intel"
label="Invest $TargetID intel"
loading={props.gameSession.loading}
/>
<SliderWithButton
defaultValue={Math.floor(props.gs.Assets.Intel * 0.5)}
Expand All @@ -30,6 +31,7 @@ export function FactionActions(
maxValue={props.gs.Assets.Intel}
iconName="Intel"
label="Invest $TargetID intel"
loading={props.gameSession.loading}
/>
</Stack>
)
Expand Down
11 changes: 10 additions & 1 deletion web/src/components/utilities/SliderWithButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { Button, Stack, TextField } from '@mui/material'
import Box from '@mui/material/Box'
import Slider from '@mui/material/Slider'
import _ from 'lodash'
import { useState } from 'react'
import { formatString } from '../../lib/rendering/formatString'
import { Icon, type IconName } from './Icon'
Expand All @@ -17,12 +18,17 @@ export type SliderWithButtonProps = {
readonly maxValue: number
readonly iconName: IconName
readonly label: string
readonly loading: boolean
}

export default function SliderWithButton(
props: SliderWithButtonProps,
): React.JSX.Element {
const [value, setValue] = useState(props.defaultValue)
const clampedValue = _.clamp(value, props.minValue, props.maxValue)
if (value !== clampedValue) {
setValue(clampedValue)
}

function handleSliderChange(
_event: Event,
Expand Down Expand Up @@ -86,7 +92,10 @@ export default function SliderWithButton(
variant="contained"
id="input-slider"
disabled={
value > props.maxValue || value < props.minValue || value === 0
props.loading ||
value > props.maxValue ||
value < props.minValue ||
value === 0
}
onClick={async () => props.onClick(value)}
>
Expand Down

0 comments on commit f514b31

Please sign in to comment.