mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-04-11 00:30:19 +02:00
Filter anormal positions and add position with scan
This commit is contained in:
@@ -15,6 +15,7 @@ import { GameZone, StartZone } from '@/components/game/MapLayers';
|
|||||||
// Contexts
|
// Contexts
|
||||||
import { useTeam } from '@/contexts/teamContext';
|
import { useTeam } from '@/contexts/teamContext';
|
||||||
// Hooks
|
// Hooks
|
||||||
|
import { useLocation } from '@/hooks/useLocation';
|
||||||
import { useUserState } from '@/hooks/useUserState';
|
import { useUserState } from '@/hooks/useUserState';
|
||||||
// Services
|
// Services
|
||||||
import { emitSendPosition } from '@/services/socket/emitters';
|
import { emitSendPosition } from '@/services/socket/emitters';
|
||||||
@@ -25,6 +26,7 @@ const Play = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { teamInfos, nextZoneDate } = useTeam();
|
const { teamInfos, nextZoneDate } = useTeam();
|
||||||
const { locationSendDeadline, hasHandicap, enemyLocation, lastSentLocation } = teamInfos;
|
const { locationSendDeadline, hasHandicap, enemyLocation, lastSentLocation } = teamInfos;
|
||||||
|
const { location } = useLocation();
|
||||||
const userState = useUserState();
|
const userState = useUserState();
|
||||||
const [bottomContainerHeight, setBottomContainerHeight] = useState(0);
|
const [bottomContainerHeight, setBottomContainerHeight] = useState(0);
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ const Play = () => {
|
|||||||
</View>
|
</View>
|
||||||
</Show>
|
</Show>
|
||||||
<View style={styles.mapContainer} onLayout={(event) => setBottomContainerHeight(event.nativeEvent.layout.height)}>
|
<View style={styles.mapContainer} onLayout={(event) => setBottomContainerHeight(event.nativeEvent.layout.height)}>
|
||||||
<Map>
|
<Map location={location}>
|
||||||
<Show when={userState == USER_STATE.PLACEMENT}>
|
<Show when={userState == USER_STATE.PLACEMENT}>
|
||||||
<StartZone/>
|
<StartZone/>
|
||||||
</Show>
|
</Show>
|
||||||
@@ -54,7 +56,7 @@ const Play = () => {
|
|||||||
</Map>
|
</Map>
|
||||||
<LinearGradient colors={['rgba(0,0,0,0.3)', 'rgba(0,0,0,0)']} style={styles.gradient}/>
|
<LinearGradient colors={['rgba(0,0,0,0.3)', 'rgba(0,0,0,0)']} style={styles.gradient}/>
|
||||||
<Show when={userState == USER_STATE.PLAYING && !hasHandicap}>
|
<Show when={userState == USER_STATE.PLAYING && !hasHandicap}>
|
||||||
<IconButton style={styles.updatePosition} source={require("@/assets/images/update_position.png")} onPress={emitSendPosition} />
|
<IconButton style={styles.updatePosition} source={require("@/assets/images/update_position.png")} onPress={() => location && emitSendPosition(location)} />
|
||||||
</Show>
|
</Show>
|
||||||
<Toasts/>
|
<Toasts/>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
27655
mobile/traque-app/package-lock.json
generated
27655
mobile/traque-app/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,6 @@
|
|||||||
"@react-native-async-storage/async-storage": "1.23.1",
|
"@react-native-async-storage/async-storage": "1.23.1",
|
||||||
"@react-navigation/native": "^7.0.14",
|
"@react-navigation/native": "^7.0.14",
|
||||||
"@react-navigation/stack": "^7.1.1",
|
"@react-navigation/stack": "^7.1.1",
|
||||||
"axxios": "^0.1.0",
|
|
||||||
"babel-plugin-module-resolver": "^5.0.2",
|
"babel-plugin-module-resolver": "^5.0.2",
|
||||||
"expo": "~52.0.46",
|
"expo": "~52.0.46",
|
||||||
"expo-build-properties": "~0.13.3",
|
"expo-build-properties": "~0.13.3",
|
||||||
|
|||||||
@@ -6,13 +6,10 @@ import MapView from 'react-native-maps';
|
|||||||
import { PositionMarker } from '@/components/common/Layers';
|
import { PositionMarker } from '@/components/common/Layers';
|
||||||
import { IconButton } from '@/components/common/IconButton';
|
import { IconButton } from '@/components/common/IconButton';
|
||||||
import { Show } from '@/components/common/Show';
|
import { Show } from '@/components/common/Show';
|
||||||
// Hook
|
|
||||||
import { useLocation } from '@/hooks/useLocation';
|
|
||||||
// Util
|
// Util
|
||||||
import { INITIAL_REGIONS } from '@/constants';
|
import { INITIAL_REGIONS } from '@/constants';
|
||||||
|
|
||||||
export const Map = ({ children }) => {
|
export const Map = ({ location, children }) => {
|
||||||
const { location } = useLocation();
|
|
||||||
const [centerMap, setCenterMap] = useState(true);
|
const [centerMap, setCenterMap] = useState(true);
|
||||||
const mapRef = useRef(null);
|
const mapRef = useRef(null);
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ export const emitLogout = () => {
|
|||||||
return customEmit("logout");
|
return customEmit("logout");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const emitSendPosition = () => {
|
export const emitSendPosition = (location) => {
|
||||||
return customEmit("send_position");
|
return customEmit("send_position", location);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const emitUpdatePosition = (location) => {
|
export const emitUpdatePosition = (location) => {
|
||||||
|
|||||||
@@ -402,9 +402,12 @@ export default {
|
|||||||
const team = this.getTeam(teamId);
|
const team = this.getTeam(teamId);
|
||||||
const enemyTeam = this.getTeam(team.chasing);
|
const enemyTeam = this.getTeam(team.chasing);
|
||||||
const dateNow = Date.now();
|
const dateNow = Date.now();
|
||||||
// Update distance
|
// Verify coherence of the new location and update the distance
|
||||||
if (this.state == GameState.PLAYING && team.currentLocation) {
|
if (this.state == GameState.PLAYING && team.currentLocation) {
|
||||||
team.distance += Math.floor(getDistanceFromLatLon({lat: location[0], lng: location[1]}, {lat: team.currentLocation[0], lng: team.currentLocation[1]}));
|
const traveledDistance = Math.floor(getDistanceFromLatLon({lat: location[0], lng: location[1]}, {lat: team.currentLocation[0], lng: team.currentLocation[1]}));
|
||||||
|
const timeSinceLastCurrentLocation = (dateNow - team.lastCurrentLocationDate) / 1000;
|
||||||
|
if (traveledDistance / timeSinceLastCurrentLocation > 8) return false; // Reject the location if it implies a speed > 8m/s (28km/h)
|
||||||
|
team.distance += traveledDistance;
|
||||||
}
|
}
|
||||||
// Update of currentLocation
|
// Update of currentLocation
|
||||||
team.currentLocation = location;
|
team.currentLocation = location;
|
||||||
|
|||||||
@@ -116,8 +116,9 @@ export function initTeamSocket() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("send_position", () => {
|
socket.on("send_position", (position) => {
|
||||||
if (!teamId) return;
|
if (!teamId) return;
|
||||||
|
game.updateLocation(teamId, position);
|
||||||
game.sendLocation(teamId);
|
game.sendLocation(teamId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user