Skip to content

Commit fcbaade

Browse files
committed
global background
1 parent e48eb77 commit fcbaade

File tree

10 files changed

+89
-31
lines changed

10 files changed

+89
-31
lines changed

src/components/molecules/System/System.jsx

+44-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useState, useContext } from 'react';
22
import { PropTypes } from 'prop-types';
33
import { useFocusable, init, FocusContext, setKeyMap } from 'spatial';
44
import { useNavigate, Link } from 'react-router-dom';
5+
import { GlobalContext } from 'context/globalContext';
56

67
function System({ data, onEnterPress, onFocus }) {
78
const { ref, focused } = useFocusable({
89
onEnterPress,
910
onFocus,
1011
});
12+
const { state, setState } = useContext(GlobalContext);
1113

14+
const { themeName, currentSystem } = state;
1215
const item = data;
16+
17+
const saveSystem = (id) => {
18+
console.log({ id });
19+
setState({ ...state, currentSystem: id });
20+
};
21+
22+
const devnull = (id) => {
23+
// setState({ ...state, currentSystem: id });
24+
};
25+
26+
useEffect(() => {
27+
if (focused) {
28+
if (item.id !== currentSystem) {
29+
saveSystem(item.id);
30+
}
31+
}
32+
// Opcionalmente, incluir devnull o lógica similar si necesitas manejar la pérdida de foco.
33+
}, [focused, item.id, saveSystem]);
34+
1335
return (
1436
<div ref={ref}>
1537
<Link
@@ -19,18 +41,31 @@ function System({ data, onEnterPress, onFocus }) {
1941
focused ? 'systems__system--focused' : ''
2042
}`}
2143
>
22-
<img className="systems__bg" src={item.poster} alt="" />
44+
<img
45+
className="systems__bg"
46+
src={`file:///Users/rsedano/emudeck/launcher/themes/${themeName}/posters/${item.id}.jpg`}
47+
alt=""
48+
/>
2349
<div className="systems__excerpt">{item.excerpt}</div>
2450
<div className="systems__name">{item.name}</div>
2551
<div className="systems__count">Games: {item.games}</div>
2652
<div className="systems__description">{item.description}</div>
27-
<img
28-
loading="lazy"
29-
className="systems__controller"
30-
src={item.controller}
31-
alt=""
32-
/>
33-
<img loading="lazy" className="systems__logo" src={item.logo} alt="" />
53+
<div className="systems__controller-holder">
54+
<img
55+
loading="lazy"
56+
className="systems__controller"
57+
src={item.controller}
58+
alt=""
59+
/>
60+
</div>
61+
<div className="systems__logo-holder">
62+
<img
63+
loading="lazy"
64+
className="systems__logo"
65+
src={`file:///Users/rsedano/emudeck/launcher/themes/${themeName}/logos/${item.id}.svg`}
66+
alt=""
67+
/>
68+
</div>
3469
</Link>
3570
</div>
3671
);

src/components/organisms/Systems/Systems.jsx

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function Systems({ focusKey: focusKeyParam, systems }) {
3838

3939
const onAssetFocus = useCallback(
4040
({ x, y }) => {
41+
console.log({ scrollingRef });
4142
scrollingRef.current.scrollTo({
4243
left: x,
4344
top: y,
@@ -46,6 +47,14 @@ function Systems({ focusKey: focusKeyParam, systems }) {
4647
},
4748
[scrollingRef],
4849
);
50+
51+
const multifunction = (item) => {
52+
onAssetFocus();
53+
};
54+
55+
const setSystem = (system) => {
56+
console.log({ system });
57+
};
4958
const { ref, focusSelf, hasFocusedChild, focusKey } = useFocusable({
5059
focusable: true,
5160
saveLastFocusedChild: true,

src/components/organisms/Themes/Themes.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ function Themes({ focusKey: focusKeyParam, themes, onClick }) {
7676

7777
{themes &&
7878
themes.map((item, i) => {
79-
console.log({ item });
8079
return (
8180
<Theme
8281
name={item}

src/global.css

+9
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,12 @@ body {
196196
background-color: #fff;
197197
color: #fff;
198198
}
199+
200+
.global-background {
201+
position: absolute;
202+
top: 0;
203+
left: 0;
204+
width: 100vw;
205+
height: 100vh;
206+
z-index: -1;
207+
}

src/pages/HomePage.jsx

+22-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function HomePage({ focusKey: focusKeyParam }) {
4141
} = useContext(GlobalContext);
4242
const { gamepad } = stateGamePad;
4343
const { theme } = stateTheme;
44-
const { themes } = state;
44+
const { themes, themeName, currentSystem } = state;
4545

4646
// Mapeo de botones del D-pad a las teclas de teclado
4747
const dpadKeyMap = {
@@ -165,17 +165,29 @@ function HomePage({ focusKey: focusKeyParam }) {
165165
console.log({ systemsTemp });
166166
setState({ ...state, themes: systemsTemp });
167167
});
168+
169+
// Set current Selected theme.
170+
const currentTheme = localStorage.getItem('current_theme');
171+
if (currentTheme) {
172+
ipcChannel.sendMessage('get-theme', [currentTheme]);
173+
ipcChannel.once('get-theme', (theme) => {
174+
setState({ ...state, themeName: theme });
175+
setStateTheme({ ...stateTheme, theme });
176+
});
177+
}
168178
}, []);
169179

170180
const onClickSetTheme = (value) => {
171181
ipcChannel.sendMessage('get-theme', [value]);
172182
ipcChannel.once('get-theme', (theme) => {
173183
setStateTheme({ ...stateTheme, theme });
184+
setState({ ...state, themeName: value });
185+
localStorage.setItem('current_theme', value);
174186
});
175187
};
176188

177189
return (
178-
<>
190+
<div>
179191
<ul className="controls">
180192
<li>
181193
<span>A</span> Enter
@@ -193,7 +205,14 @@ function HomePage({ focusKey: focusKeyParam }) {
193205
<Themes themes={themes} onClick={onClickSetTheme} />
194206
)}
195207
{theme && systems && <Systems systems={systems} />}
196-
</>
208+
{currentSystem && (
209+
<img
210+
className="global-background"
211+
src={`file:///Users/rsedano/emudeck/launcher/themes/${themeName}/posters/${currentSystem}.jpg`}
212+
alt="System"
213+
/>
214+
)}
215+
</div>
197216
);
198217
}
199218

src/renderer/App.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default function App() {
2020
userfolder: undefined,
2121
themeName: 'default',
2222
themes: undefined,
23+
currentSystem: undefined,
2324
});
2425

2526
const [stateTheme, setStateTheme] = useState({

themes/epicnoir/index.css

+4
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,7 @@ body {
228228
background: rgba(93, 255, 77, 0.3);
229229
z-index: 1;
230230
}
231+
232+
.global-background {
233+
display: none;
234+
}

themes/epicnoir/logos/auto-allgames.svg

-5
This file was deleted.

themes/epicnoir/logos/auto-favorites.svg

-5
This file was deleted.

0 commit comments

Comments
 (0)