feat: update main entry point in package.json and add turn timer functionality in TableScreen
This commit is contained in:
4
index.js
Normal file
4
index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { registerRootComponent } from 'expo';
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
registerRootComponent(App);
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "blackjack-mobile",
|
"name": "blackjack-mobile",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "node_modules/expo/AppEntry.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "expo start",
|
"start": "expo start",
|
||||||
"android": "expo run:android",
|
"android": "expo run:android",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export default function TableScreen({ token, tableId, user, onLeave }) {
|
|||||||
const [balance, setBalance] = useState(user.balance);
|
const [balance, setBalance] = useState(user.balance);
|
||||||
const [message, setMessage] = useState('');
|
const [message, setMessage] = useState('');
|
||||||
const [betAmount, setBetAmount] = useState(10);
|
const [betAmount, setBetAmount] = useState(10);
|
||||||
|
const [turnSeconds, setTurnSeconds] = useState(null);
|
||||||
const wsRef = useRef(null);
|
const wsRef = useRef(null);
|
||||||
const pulse = useRef(new Animated.Value(0)).current;
|
const pulse = useRef(new Animated.Value(0)).current;
|
||||||
|
|
||||||
@@ -62,6 +63,22 @@ export default function TableScreen({ token, tableId, user, onLeave }) {
|
|||||||
const isMyTurn = table?.phase === 'playing' && table?.currentSeatIndex === mySeat?.index;
|
const isMyTurn = table?.phase === 'playing' && table?.currentSeatIndex === mySeat?.index;
|
||||||
const bettingLocked = ['playing', 'dealer', 'payout'].includes(table?.phase);
|
const bettingLocked = ['playing', 'dealer', 'payout'].includes(table?.phase);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!table?.turnEndsAt || !isMyTurn) {
|
||||||
|
setTurnSeconds(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const update = () => {
|
||||||
|
const msLeft = Math.max(0, table.turnEndsAt - Date.now());
|
||||||
|
setTurnSeconds(Math.ceil(msLeft / 1000));
|
||||||
|
};
|
||||||
|
|
||||||
|
update();
|
||||||
|
const interval = setInterval(update, 250);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [table?.turnEndsAt, isMyTurn]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isMyTurn) {
|
if (!isMyTurn) {
|
||||||
pulse.stopAnimation();
|
pulse.stopAnimation();
|
||||||
@@ -151,6 +168,9 @@ export default function TableScreen({ token, tableId, user, onLeave }) {
|
|||||||
<CasinoButton label="Kész" onPress={() => send({ type: 'ready' })} variant="green" disabled={bettingLocked} />
|
<CasinoButton label="Kész" onPress={() => send({ type: 'ready' })} variant="green" disabled={bettingLocked} />
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{isMyTurn && turnSeconds !== null ? (
|
||||||
|
<Text style={styles.timer}>Idő: {turnSeconds} mp</Text>
|
||||||
|
) : null}
|
||||||
<Animated.View style={[styles.actionRow, isMyTurn && pulseStyle]}>
|
<Animated.View style={[styles.actionRow, isMyTurn && pulseStyle]}>
|
||||||
<CasinoButton label="Hit" onPress={() => send({ type: 'action', action: 'hit' })} variant="gold" disabled={!isMyTurn} />
|
<CasinoButton label="Hit" onPress={() => send({ type: 'action', action: 'hit' })} variant="gold" disabled={!isMyTurn} />
|
||||||
<CasinoButton label="Stand" onPress={() => send({ type: 'action', action: 'stand' })} variant="gold" disabled={!isMyTurn} />
|
<CasinoButton label="Stand" onPress={() => send({ type: 'action', action: 'stand' })} variant="gold" disabled={!isMyTurn} />
|
||||||
@@ -252,5 +272,11 @@ const styles = StyleSheet.create({
|
|||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
marginTop: 10,
|
marginTop: 10,
|
||||||
fontFamily: fonts.body
|
fontFamily: fonts.body
|
||||||
|
},
|
||||||
|
timer: {
|
||||||
|
color: colors.goldBright,
|
||||||
|
textAlign: 'center',
|
||||||
|
marginBottom: 8,
|
||||||
|
fontFamily: fonts.mono
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user