Skip to content

Commit b5e3c3b

Browse files
swz-gitVirxEC
andauthored
Loadout editor (#25)
* Add loadout editor (#24) * nicer loadout-editor flexing * add fix for nvidia cards on linux * remove comment --------- Co-authored-by: Eric Veilleux <virx@virxcase.dev>
1 parent 206c1db commit b5e3c3b

19 files changed

Lines changed: 9651 additions & 32 deletions

frontend/rsbuild.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@ export default defineConfig({
1313
js: "inline-source-map",
1414
},
1515
},
16+
tools: {
17+
rspack(config, { addRules }) {
18+
addRules([
19+
{
20+
test: /\.csv$/,
21+
type: "asset/resource",
22+
},
23+
]);
24+
},
25+
},
1626
});

frontend/src/assets/arrows.svg

Lines changed: 1 addition & 0 deletions
Loading

frontend/src/assets/eye.svg

Lines changed: 1 addition & 0 deletions
Loading

frontend/src/assets/items.csv

Lines changed: 7877 additions & 0 deletions
Large diffs are not rendered by default.

frontend/src/assets/random.svg

Lines changed: 1 addition & 0 deletions
Loading

frontend/src/components/BotList.svelte

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import defaultIcon from "../assets/rlbot_mono.png";
1313
import starIcon from "../assets/star.svg";
1414
import filledStarIcon from "../assets/starFilled.svg";
1515
import { BASE_PLAYERS } from "../base-players";
16-
import { uuidv4, type DraggablePlayer, type ToggleableScript } from "../index";
16+
import { type DraggablePlayer, type ToggleableScript, uuidv4 } from "../index";
17+
//@ts-ignore
18+
import LoadoutEditor from "./LoadoutEditor/Main.svelte";
19+
import { getAndParseItems } from "./LoadoutEditor/items";
1720
import Modal from "./Modal.svelte";
1821
import Switch from "./Switch.svelte";
1922
@@ -26,6 +29,7 @@ let {
2629
enabledScripts = $bindable({}),
2730
bluePlayers = $bindable(),
2831
orangePlayers = $bindable(),
32+
map,
2933
}: {
3034
bots: DraggablePlayer[];
3135
scripts: ToggleableScript[];
@@ -35,6 +39,7 @@ let {
3539
enabledScripts: { [key: string]: boolean };
3640
bluePlayers: DraggablePlayer[];
3741
orangePlayers: DraggablePlayer[];
42+
map: string;
3843
} = $props();
3944
const flipDurationMs = 100;
4045
@@ -87,9 +92,25 @@ const subCategoryTags: { [x: string]: string[] } = {
8792
};
8893
8994
let showInfoModal = $state(false);
95+
let infoModalWasOpen = false;
96+
let showLoadoutEditor = $state(false);
97+
$effect(() => {
98+
if (!showLoadoutEditor && infoModalWasOpen) {
99+
showInfoModal = true;
100+
infoModalWasOpen = false;
101+
}
102+
});
103+
104+
let everSelectedAgent = $state(false);
105+
$effect(() => {
106+
if (selectedAgent) {
107+
everSelectedAgent = true;
108+
}
109+
});
110+
90111
let selectedAgent: [BotInfo, string, string] | null = $state(null);
91112
$effect(() => {
92-
if (!showInfoModal) {
113+
if (!showInfoModal && !showLoadoutEditor) {
93114
selectedAgent = null;
94115
}
95116
});
@@ -247,7 +268,9 @@ function OpenSelectedBotSource() {
247268
248269
function EditSelectedBotLoadout() {
249270
if (selectedAgent) {
250-
alert.bind(null, "Not implemented yet")();
271+
infoModalWasOpen = showInfoModal;
272+
showInfoModal = false;
273+
showLoadoutEditor = true;
251274
}
252275
}
253276
@@ -430,6 +453,25 @@ function SelectedToggleFavorite() {
430453
{/if}
431454
</Modal>
432455

456+
<!-- prevent loading the items if unneeded,
457+
but also prevent loading the items more than once -->
458+
{#if everSelectedAgent}
459+
<!-- svelte-ignore block_empty -->
460+
{#await getAndParseItems() then items}
461+
{#if selectedAgent && selectedAgent[0].loadout}
462+
<LoadoutEditor
463+
bind:visible={showLoadoutEditor}
464+
basePath={selectedAgent[0].tomlPath}
465+
loadoutFile={selectedAgent[0].config.settings.loadoutFile}
466+
loadout={selectedAgent[0].loadout}
467+
{items}
468+
name={selectedAgent[1]}
469+
{map}
470+
/>
471+
{/if}
472+
{/await}
473+
{/if}
474+
433475
<style>
434476
.bots span {
435477
color: gray;
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<script lang="ts">
2+
import { COLORS } from "./colors";
3+
4+
let {
5+
value = $bindable(),
6+
team,
7+
text,
8+
onchange,
9+
}: {
10+
value: number;
11+
team: string | null;
12+
text: string;
13+
onchange: () => void;
14+
} = $props();
15+
16+
let pickedColor = $derived(getColorStyle(value));
17+
18+
const ROWS = 7;
19+
const COLUMNS = team ? 10 : 15;
20+
21+
function getColorStyle(colorID: number) {
22+
const colors = team ? COLORS[team] : COLORS.secondary;
23+
const rgb = colors[colorID];
24+
return rgb ? rgb.toString() : "";
25+
}
26+
27+
function pickedItemClass(colorID: number) {
28+
return value === colorID ? "selected-color" : "";
29+
}
30+
31+
const COLOR_IDS: number[][] = [];
32+
for (let i = 0; i < ROWS; i++) {
33+
COLOR_IDS.push([]);
34+
for (let j = 0; j < COLUMNS; j++) {
35+
COLOR_IDS[i].push(i * COLUMNS + j);
36+
}
37+
}
38+
39+
function handleClick(id: number) {
40+
value = id;
41+
onchange();
42+
}
43+
</script>
44+
45+
<div class="dropdown">
46+
<button>
47+
<span class="color-indicator" style="background-color: rgb({pickedColor})"
48+
></span>
49+
{text}
50+
</button>
51+
<div class="dropmenu {team ? 'left' : 'center'}">
52+
<table>
53+
<tbody>
54+
{#each COLOR_IDS as idsRow}
55+
<tr>
56+
{#each idsRow as id}
57+
<td>
58+
<!-- svelte-ignore a11y_consider_explicit_label -->
59+
<button
60+
style="background-color: rgb({getColorStyle(id)})"
61+
onclick={() => handleClick(id)}
62+
>
63+
<div class="colorpicker-color {pickedItemClass(id)}"></div>
64+
</button>
65+
</td>
66+
{/each}
67+
</tr>
68+
{/each}
69+
</tbody>
70+
</table>
71+
</div>
72+
</div>
73+
74+
<style>
75+
button {
76+
display: flex;
77+
align-items: center;
78+
gap: 8px;
79+
}
80+
table {
81+
border-spacing: 0;
82+
}
83+
.dropmenu {
84+
padding: 0px;
85+
margin-left: 10px;
86+
margin-right: 10px;
87+
margin-bottom: -5px;
88+
border: 8px solid var(--background-but);
89+
border-radius: 5px;
90+
}
91+
.dropmenu td,
92+
.dropmenu button {
93+
border: 0;
94+
border-radius: 0;
95+
padding: 0;
96+
}
97+
.colorpicker-color {
98+
width: 25px;
99+
height: 25px;
100+
cursor: pointer;
101+
}
102+
.colorpicker-color:hover {
103+
border: 2px solid rgba(0, 0, 0, 0.74);
104+
}
105+
.selected-color {
106+
border: 2px dashed rgba(0, 0, 0, 0.897);
107+
}
108+
.color-indicator {
109+
border-radius: 12px;
110+
width: 24px;
111+
height: 24px;
112+
display: inline-block;
113+
vertical-align: middle;
114+
}
115+
</style>

0 commit comments

Comments
 (0)