Skip to content

Commit

Permalink
basic fix send fleet and debris collection
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Jan 27, 2024
1 parent 0e1c3fc commit 43f3b26
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 62 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"packages/backend"
],
"scripts": {
"dev": "concurrently \"cd packages/backend && npm run dev\" \"cd packages/frontend && npm run dev\"",
"dev": "concurrently --kill-others \"cd packages/backend && npm run dev\" \"cd packages/frontend && npm run dev\"",
"build": "concurrently \"cd packages/backend && npm run build\" \"cd packages/frontend && npm run build\"",
"start": "concurrently \"cd packages/backend && npm start\" \"cd packages/frontend && npm run preview\"",
"prepare": "husky install",
Expand All @@ -17,9 +17,9 @@
},
"devDependencies": {
"concurrently": "^8.2.2",
"husky": "^8.0.3",
"lint-staged": "^15.2.0",
"lerna": "^8.0.2"
"husky": "^9.0.6",
"lerna": "^8.0.2",
"lint-staged": "^15.2.0"
},
"husky": {
"hooks": {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// backend/src/server.ts
import app from "./app";
import app from './app';

const PORT = process.env.PORT ? +process.env.PORT : 3001;

app.listen(PORT, "0.0.0.0", () => {
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server running on http://localhost:${PORT}`);
});
3 changes: 1 addition & 2 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"eslint-plugin-react": "^7.33.2",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vite-plugin-checker": "^0.6.2"
"vite": "^5.0.12"
}
}
3 changes: 3 additions & 0 deletions packages/frontend/src/components/boxes/UniverseViewBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const UniverseViewBox = ({
isNoobProtected,
lastActive,
winLoss,
colonyId,
}: Props) => {
const boxStyle = highlighted ? { border: '1px solid #23CE6B' } : {};

Expand Down Expand Up @@ -130,6 +131,7 @@ const UniverseViewBox = ({
ownFleet={ownFleet}
techs={ownTechs}
ownPosition={ownPositionNumberised}
colonyId={colonyId}
/>
<Styled.ButtonContainer>
<ButtonAttackPlanet
Expand All @@ -140,6 +142,7 @@ const UniverseViewBox = ({
techs={ownTechs}
ownPosition={ownPositionNumberised}
planetId={planetId}
colonyId={colonyId}
/>
</Styled.ButtonContainer>
</Styled.SubBox>
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/components/boxes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export interface UniverseBoxProps {
isNoobProtected?: boolean;
lastActive: number;
winLoss: [number, number];
colonyId: number;
}

export type ButtonState = 'valid' | 'noResource' | 'noRequirements';
11 changes: 10 additions & 1 deletion packages/frontend/src/components/buttons/ButtonAttackPlanet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type ShipsLevels,
type TechLevels,
type Position,
MissionCategory,
} from '../../shared/types';
import useSendFleet from '../../hooks/writeHooks/useSendFleet';
import { useGetActiveMissions } from '../../hooks/FleetHooks';
Expand Down Expand Up @@ -158,6 +159,7 @@ interface Props {
techs?: TechLevels;
ownPosition?: Position;
planetId: number;
colonyId: number;
}

function ButtonAttackPlanet({
Expand All @@ -169,6 +171,7 @@ function ButtonAttackPlanet({
techs,
ownPosition,
planetId,
colonyId,
}: Props) {
const [quantities, setQuantities] = useState<Record<string, number>>({});
const [travelTime, setTravelTime] = useState(0);
Expand Down Expand Up @@ -226,7 +229,13 @@ function ButtonAttackPlanet({
setCargoCapacity(calculateTotalCargoCapacity(fleet));
}, [distance, fleet, ownPosition, speed, techs]);

const { writeAsync, data } = useSendFleet(fleet, position, false, speed);
const { writeAsync, data } = useSendFleet(
fleet,
position,
MissionCategory.Attack,
speed,
colonyId
);

const ships = ['carrier', 'scraper', 'sparrow', 'frigate', 'armade'];

Expand Down
11 changes: 10 additions & 1 deletion packages/frontend/src/components/buttons/ButtonCollectDebris.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import scraperImg from '../../assets/gameElements/ships/scraper4.webp';
import { StyledButton } from '../../shared/styled/Button';
import useSendFleet from '../../hooks/writeHooks/useSendFleet';
import {
MissionCategory,
type DebrisField,
type Position,
type ShipsLevels,
Expand Down Expand Up @@ -158,6 +159,7 @@ interface Props {
techs: TechLevels;
ownPosition: Position;
debrisField: DebrisField;
colonyId: number;
}

export function ButtonCollectDebris({
Expand All @@ -167,6 +169,7 @@ export function ButtonCollectDebris({
techs,
ownPosition,
debrisField,
colonyId,
}: Props) {
const [quantities, setQuantities] = useState<Record<string, number>>({});
const [travelTime, setTravelTime] = useState(0);
Expand Down Expand Up @@ -211,7 +214,13 @@ export function ButtonCollectDebris({
setFuelConsumption(getFuelConsumption(fleet, distance, speedFactor));
}, [distance, fleet, speed, techs]);

const { writeAsync, data } = useSendFleet(fleet, position, true, speed);
const { writeAsync, data } = useSendFleet(
fleet,
position,
MissionCategory.Debris,
speed,
colonyId
);

const isShipOverLimit = totalShips > ownFleet.scraper;

Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/components/ui/DebrisFieldView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Props {
ownFleet?: ShipsLevels;
techs?: TechLevels;
ownPosition?: Position;
colonyId: number;
}

function DebrisFieldView({
Expand All @@ -26,6 +27,7 @@ function DebrisFieldView({
ownFleet,
techs,
ownPosition,
colonyId,
}: Props) {
const [modalOpen, setModalOpen] = React.useState(false);

Expand Down Expand Up @@ -106,6 +108,7 @@ function DebrisFieldView({
techs={techs!}
ownPosition={ownPosition!}
debrisField={debris}
colonyId={colonyId}
/>
</div>
</Modal>
Expand Down
64 changes: 27 additions & 37 deletions packages/frontend/src/constants/nogame.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@
"type": "nogame::libraries::types::Fleet"
},
{
"name": "is_debris",
"type": "core::bool"
"name": "category",
"type": "core::integer::u8"
}
]
},
{
"type": "struct",
"name": "nogame::libraries::types::HostileMission",
"name": "nogame::libraries::types::IncomingMission",
"members": [
{
"name": "origin",
Expand Down Expand Up @@ -461,32 +461,6 @@
}
]
},
{
"type": "struct",
"name": "nogame::libraries::types::ShipsLevels",
"members": [
{
"name": "carrier",
"type": "core::integer::u32"
},
{
"name": "scraper",
"type": "core::integer::u32"
},
{
"name": "sparrow",
"type": "core::integer::u32"
},
{
"name": "frigate",
"type": "core::integer::u32"
},
{
"name": "armade",
"type": "core::integer::u32"
}
]
},
{
"type": "struct",
"name": "nogame::libraries::types::SimulationResult",
Expand Down Expand Up @@ -732,12 +706,16 @@
"type": "nogame::libraries::types::PlanetPosition"
},
{
"name": "is_debris_collection",
"type": "core::bool"
"name": "mission_type",
"type": "core::integer::u8"
},
{
"name": "speed_modifier",
"type": "core::integer::u32"
},
{
"name": "colony_id",
"type": "core::integer::u8"
}
],
"outputs": [],
Expand Down Expand Up @@ -767,6 +745,18 @@
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "dock_fleet",
"inputs": [
{
"name": "mission_id",
"type": "core::integer::u32"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "collect_debris",
Expand Down Expand Up @@ -1019,7 +1009,7 @@
},
{
"type": "function",
"name": "get_hostile_missions",
"name": "get_incoming_missions",
"inputs": [
{
"name": "planet_id",
Expand All @@ -1028,7 +1018,7 @@
],
"outputs": [
{
"type": "core::array::Array::<nogame::libraries::types::HostileMission>"
"type": "core::array::Array::<nogame::libraries::types::IncomingMission>"
}
],
"state_mutability": "view"
Expand Down Expand Up @@ -1211,7 +1201,7 @@
],
"outputs": [
{
"type": "nogame::libraries::types::ShipsLevels"
"type": "nogame::libraries::types::Fleet"
}
],
"state_mutability": "view"
Expand Down Expand Up @@ -1363,7 +1353,7 @@
],
"outputs": [
{
"type": "nogame::libraries::types::ShipsLevels"
"type": "nogame::libraries::types::Fleet"
}
],
"state_mutability": "view"
Expand Down Expand Up @@ -1522,7 +1512,7 @@
},
{
"name": "mission_type",
"type": "core::felt252",
"type": "core::integer::u8",
"kind": "data"
},
{
Expand All @@ -1544,7 +1534,7 @@
},
{
"name": "mission_type",
"type": "core::felt252",
"type": "core::integer::u8",
"kind": "data"
},
{
Expand Down
10 changes: 6 additions & 4 deletions packages/frontend/src/hooks/writeHooks/useSendFleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { type Fleet, type Position } from '../../shared/types';
export default function useSendFleet(
fleet: Fleet,
position: Position,
isDebris: boolean,
speedModifier: number
missioCategory: number,
speedModifier: number,
colonyId: number
): {
writeAsync: (
args?: ContractWriteVariables | undefined
Expand All @@ -28,8 +29,9 @@ export default function useSendFleet(
contract?.populateTransaction.send_fleet!(
fleet,
position,
isDebris,
speedModifier
missioCategory,
speedModifier,
colonyId
),
],
});
Expand Down
16 changes: 13 additions & 3 deletions packages/frontend/src/panels/MainTabPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const ResourcesSection = ({
techLevels,
colonyId
)}
{activeTab === 5 && renderUniversePanel(planetId, techLevels)}
{activeTab === 5 && renderUniversePanel(planetId, techLevels, colonyId)}
</ResourcesTabs>
);
};
Expand Down Expand Up @@ -248,6 +248,16 @@ function renderDefencesPanel(
);
}

function renderUniversePanel(planetId: number, techLevels: TechLevels) {
return <UniverseViewTabPanel ownPlanetId={planetId} ownTechs={techLevels} />;
function renderUniversePanel(
planetId: number,
techLevels: TechLevels,
colonyId: number
) {
return (
<UniverseViewTabPanel
ownPlanetId={planetId}
ownTechs={techLevels}
colonyId={colonyId}
/>
);
}
Loading

0 comments on commit 43f3b26

Please sign in to comment.