Skip to content

Commit

Permalink
fix civ navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
denniske committed Oct 21, 2023
1 parent e287e0b commit 80b6b8b
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 115 deletions.
6 changes: 4 additions & 2 deletions app/src/api/helper/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@



export const GAME_VARIANT_AOE2DE = 2;
export const GAME_VARIANT_AOE2ROR = 1;



Expand Down Expand Up @@ -175,7 +177,7 @@ export interface IStatNew {
}

export interface IStatCiv {
civ: number
civ: string
civName: string
civImageUrl: string
games: number
Expand Down Expand Up @@ -300,7 +302,7 @@ export interface IPlayerNew {
rating?: number
ratingDiff: number
civFix: number
civ: number
civ: string
civName: string
civImageUrl: string
color: number
Expand Down
10 changes: 10 additions & 0 deletions app/src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const changelog4: IChangelog = {
type: 'feature',
title: 'Lobbies page (Three dots > Lobbies)',
},
{
type: 'bugfix',
title: 'Fix navigation to civ page from matches/stats',
},
],
'12.0.0': [
{
Expand Down Expand Up @@ -128,6 +132,12 @@ export const changelog4: IChangelog = {
};

export const changelog: IChangelog = {
'68.0.4': [
{
type: 'bugfix',
title: 'Fix navigation to civ page from matches/stats',
},
],
'68.0.3': [
{
type: 'bugfix',
Expand Down
13 changes: 10 additions & 3 deletions app/src/view/components/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {Platform, StyleSheet, TextStyle, TouchableOpacity, View} from 'react-native';
import {Image} from 'expo-image';
import {useNavigation} from '@react-navigation/native';
import {civsAoeNet, isBirthday, isVerifiedPlayer, moProfileId} from '@nex/data';
import {civsAoeNet, getCivIdByEnum, isBirthday, isVerifiedPlayer, moProfileId} from '@nex/data';
import {RootStackProp} from '../../../App2';
import {TextLoader} from "./loader/text-loader";
import {FontAwesome5} from "@expo/vector-icons";
Expand All @@ -11,7 +11,7 @@ import {getCivIcon} from "../../helper/civs";
import {createStylesheet} from '../../theming-new';
import {openLink} from "../../helper/url";
import {appConfig} from "@nex/dataset";
import {IMatchNew, IPlayerNew} from "../../api/helper/api.types";
import {GAME_VARIANT_AOE2ROR, IMatchNew, IPlayerNew} from "../../api/helper/api.types";


interface IPlayerProps {
Expand Down Expand Up @@ -62,6 +62,13 @@ export function Player({match, player, highlight, freeForALl, canDownloadRec}: I
});
};

const gotoCiv = () => {
if (match.gameVariant === GAME_VARIANT_AOE2ROR) return;
navigation.push('Civ', {
civ: getCivIdByEnum(player.civ),
});
};

const downloadRec = async () => {
const url = `https://aoe.ms/replay/?gameId=${match.matchId}&profileId=${player.profileId}`;
await openLink(url);
Expand Down Expand Up @@ -127,7 +134,7 @@ export function Player({match, player, highlight, freeForALl, canDownloadRec}: I
</>
}

<TouchableOpacity style={styles.civCol} onPress={() => player.civ < 10000 && navigation.push('Civ', {civ: civsAoeNet[player.civ]})}>
<TouchableOpacity style={styles.civCol} onPress={gotoCiv}>
<View style={appConfig.game === 'aoe2de' ? styles.row : styles.row4}>
<Image fadeDuration={0} style={styles.countryIcon} source={getCivIcon(player) as any}/>
<MyText numberOfLines={1} style={styles.text}>{player.civName}</MyText>
Expand Down
184 changes: 75 additions & 109 deletions app/src/view/components/stats-rows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {StyleSheet, TouchableOpacity, View} from 'react-native';
import {Image} from 'expo-image';
import React from 'react';
import {TextLoader} from "./loader/text-loader";
import {Civ, LeaderboardId} from "@nex/data";
import {Civ, getCivIdByEnum, LeaderboardId} from "@nex/data";
import {useNavigation} from "@react-navigation/native";
import {RootStackProp} from "../../../App2";
import {MyText} from "./my-text";
Expand All @@ -16,46 +16,6 @@ import {appConfig} from "@nex/dataset";
import {IStatAlly, IStatCiv, IStatMap, IStatOpponent} from "../../api/helper/api.types";


// export interface IStatCiv {
// civ: number
// civName: string
// civImageUrl: string
// games: number
// wins: number
// }
//
// export interface IStatMap {
// map: string
// mapName: string
// mapImageUrl: string
// location?: number
// games: number
// wins: number
// losses: number
// }
//
// export interface IStatAlly {
// verified: boolean
// countryIcon?: string
// profileId: number
// name: string
// country?: string
// games: number
// wins: number
// losses: number
// }
//
// export interface IStatOpponent {
// verified: boolean
// countryIcon: string
// profileId: number
// name: string
// country: string
// games: number
// wins: number
// losses: number
// }

interface IRowPropsCiv {
data: IStatCiv;
type: 'civ';
Expand All @@ -76,77 +36,13 @@ interface IRowPropsOpponent {
type: 'opponent';
}

// interface IRowProps {
// data: IStatCiv | IStatMap | IStatAlly | IStatOpponent;
// type: 'civ' | 'map' | 'ally' | 'opponent';
// }

// Stats Position
//
// function Row({data}: IRowProps) {
// const theme = useAppTheme();
// const styles = useStyles();
// return (
// <View style={styles.row}>
// <View style={styles.cellLeaderboard}>
// <View style={styles.icon}>
// <FontAwesome5 name={data.position == 'flank' ? 'fist-raised' : 'first-aid'} size={14} color={theme.textNoteColor} />
// </View>
// <MyText>{getPositionName(data.position)}</MyText>
// </View>
// <MyText style={styles.cellGames}>
// {data.games}
// </MyText>
// <MyText style={styles.cellWon}>
// {isNaN(data.won) ? '-' : data.won.toFixed(0) + ' %'}
// </MyText>
// </View>
// )
// }

// Stats Duration
//
// function Row({data}: IRowProps) {
// const theme = useAppTheme();
// const styles = useStyles();
// let marginLeft = 0;
// if (data.duration == 'lessThan5Minutes') {
// marginLeft = 0;
// }
// if (data.duration == 'lessThan30Minutes') {
// marginLeft = 12.0;
// }
// if (data.duration == 'lessThan60Minutes') {
// marginLeft = 3.0;
// }
// if (data.duration == 'greaterThan60Minutes') {
// marginLeft = 21.5;
// }
// return (
// <View style={styles.row}>
// <View style={styles.cellLeaderboard}>
// <View style={styles.icon}>
// <FontAwesome5 name="clock" size={14} color={theme.textNoteColor}/>
// </View>
// <MyText style={{marginLeft}}>{getTranslation(`main.stats.duration.${data.duration}` as any)}</MyText>
// </View>
// <MyText style={styles.cellGames}>
// {data.games}
// </MyText>
// <MyText style={styles.cellWon}>
// {isNaN(data.won) ? '-' : data.won.toFixed(0) + ' %'}
// </MyText>
// </View>
// )
// }

function Row({type, data}: IRowPropsCiv | IRowPropsMap | IRowPropsAlly | IRowPropsOpponent) {
const styles = useStyles();
const navigation = useNavigation<RootStackProp>();

const gotoEntity = () => {
if (type === 'civ') {
navigation.push('Civ', { civ: data.civ });
navigation.push('Civ', { civ: getCivIdByEnum(data.civ) });
}
if ((type === 'ally' || type === 'opponent') && data.profileId) {
navigation.push('User', {
Expand Down Expand Up @@ -187,8 +83,12 @@ function Row({type, data}: IRowPropsCiv | IRowPropsMap | IRowPropsAlly | IRowPro
<CountryImage country={data.country} />
}
{
(type === 'civ' || type === 'map') &&
<Image fadeDuration={0} style={data.civ ? styles.civIcon : styles.icon} source={getIcon()}/>
(type === 'civ') &&
<Image fadeDuration={0} style={styles.civIcon} source={getIcon()}/>
}
{
(type === 'map') &&
<Image fadeDuration={0} style={styles.icon} source={getIcon()}/>
}
<MyText>{getName()}</MyText>
</View>
Expand Down Expand Up @@ -231,7 +131,7 @@ export default function StatsRows(props: IProps) {

{
data && data.map((row, i) =>
<Row key={i} type={type} data={row}/>
<Row key={i} type={type} data={row as any}/>
)
}

Expand Down Expand Up @@ -328,3 +228,69 @@ const useStyles = createStylesheet(theme => StyleSheet.create({
marginRight: 5,
},
}));



// interface IRowProps {
// data: IStatCiv | IStatMap | IStatAlly | IStatOpponent;
// type: 'civ' | 'map' | 'ally' | 'opponent';
// }

// Stats Position
//
// function Row({data}: IRowProps) {
// const theme = useAppTheme();
// const styles = useStyles();
// return (
// <View style={styles.row}>
// <View style={styles.cellLeaderboard}>
// <View style={styles.icon}>
// <FontAwesome5 name={data.position == 'flank' ? 'fist-raised' : 'first-aid'} size={14} color={theme.textNoteColor} />
// </View>
// <MyText>{getPositionName(data.position)}</MyText>
// </View>
// <MyText style={styles.cellGames}>
// {data.games}
// </MyText>
// <MyText style={styles.cellWon}>
// {isNaN(data.won) ? '-' : data.won.toFixed(0) + ' %'}
// </MyText>
// </View>
// )
// }

// Stats Duration
//
// function Row({data}: IRowProps) {
// const theme = useAppTheme();
// const styles = useStyles();
// let marginLeft = 0;
// if (data.duration == 'lessThan5Minutes') {
// marginLeft = 0;
// }
// if (data.duration == 'lessThan30Minutes') {
// marginLeft = 12.0;
// }
// if (data.duration == 'lessThan60Minutes') {
// marginLeft = 3.0;
// }
// if (data.duration == 'greaterThan60Minutes') {
// marginLeft = 21.5;
// }
// return (
// <View style={styles.row}>
// <View style={styles.cellLeaderboard}>
// <View style={styles.icon}>
// <FontAwesome5 name="clock" size={14} color={theme.textNoteColor}/>
// </View>
// <MyText style={{marginLeft}}>{getTranslation(`main.stats.duration.${data.duration}` as any)}</MyText>
// </View>
// <MyText style={styles.cellGames}>
// {data.games}
// </MyText>
// <MyText style={styles.cellWon}>
// {isNaN(data.won) ? '-' : data.won.toFixed(0) + ' %'}
// </MyText>
// </View>
// )
// }
11 changes: 10 additions & 1 deletion data/src/helper/civs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {aoeData} from "../data/data";
import {removeAccentsAndCase, sanitizeGameDescription, unwrap} from "../lib/util";
import {getAoeString} from '../lib/aoe-data';
import {orderBy} from 'lodash';
import {appConfig, civsAoeNetData, civsData} from "@nex/dataset";
import {appConfig, civsAoeNetData, civsData, civEnumListData} from "@nex/dataset";

export const civs = civsData;
export const civsAoeNet = civsAoeNetData;
export const civEnumList = civEnumListData;

export interface ICivEntry {
name: Civ;
Expand Down Expand Up @@ -287,6 +288,14 @@ export function getCivNameById(civ: Civ) {
return aoe4CivNameDict[civs.indexOf(civ)];
}

// export function getCivEnumById(civ: Civ) {
// return civEnumList[civ];
// }

export function getCivIdByEnum(civEnum: string): Civ {
return civEnumList[civEnum];
}

export function getCivDescription(civ: Civ) {
const civStringKey = aoeData.civ_helptexts[civ];
return sanitizeGameDescription(getAoeString(civStringKey));
Expand Down
Loading

0 comments on commit 80b6b8b

Please sign in to comment.