Skip to content

Commit 294803f

Browse files
committed
feat: Add multiple machine for lottery draw
- Implemented `MachineAnimation` component with animation and collision handling for lottery balls. - Added functionality to draw balls with callbacks for drawing and animation end. - Created utility functions for managing machine and ball interactions within the animation. feat: Enhance main page functionality - Introduced `clickElement` function to programmatically trigger clicks on elements. - Added drag-and-drop file input handling with `addDropEventToChangeInputFile`. feat: Integrate Lottie animations - Created `startLottie` function to control Lottie animations on the random page. chore: Update global types - Extended global types to include `ImportMetaEnv` for environment mode. feat: Register new custom elements - Added `Textfield` component to the custom elements list for Spectrum Web Components. fix: Improve custom elements registration logic - Refined the custom elements registration check to ensure elements are only defined if not already registered.
1 parent 2c04516 commit 294803f

14 files changed

Lines changed: 930 additions & 874 deletions

File tree

src/DotNetDevLottery/Components/Random/MachineAnimation.razor

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33

44
<div class="container">
55
<div class="button-row">
6-
<ui-button treatment="outline" @onclick="OnClickButton"
7-
variant="@TriggerButtonVariant(Status == DrawMachineStatus.Pending)"
6+
<ui-button type="" variant="primary" @onclick="@(() => TargetPersonCount--)">
7+
<span slot="icon">-</span>
8+
</ui-button>
9+
<span>
10+
@TargetPersonCount
11+
</span>
12+
<ui-button variant="primary" @onclick="@(() => TargetPersonCount++)">
13+
<span slot="icon">+</span>
14+
</ui-button>
15+
<ui-button @onclick="OnClickButton" variant="@TriggerButtonVariant(Status == DrawMachineStatus.Pending)"
816
class="@TriggerButtonClass(Status == DrawMachineStatus.Pending)">
917
추첨 진행
1018
</ui-button>
@@ -32,6 +40,7 @@
3240
string TriggerButtonClass(bool isDisabled) => isDisabled ? "" : "success";
3341
string TriggerButtonVariant(bool isDisabled) => isDisabled ? "secondary" : "";
3442
int PersonCount = 0;
43+
int TargetPersonCount = 1;
3544
int RemainedPersonCount = 0;
3645
List<int> WinnedUserList = new List<int>();
3746

@@ -45,7 +54,7 @@
4554
}
4655
machineUtils = await JSRuntime.InvokeAsync<IJSObjectReference>(
4756
"import",
48-
"./Components/Random/MachineAnimation.razor.js"
57+
"/js/Components/Random/MachineAnimation.r.js"
4958
);
5059
componentRef = DotNetObjectReference.Create(this);
5160
await machineUtils.InvokeVoidAsync(
@@ -66,7 +75,8 @@
6675
}
6776
SelectedUserInfo = null;
6877
Status = DrawMachineStatus.Pending;
69-
await machineUtils.InvokeVoidAsync("executeDrawBall");
78+
Console.WriteLine($"TargetPersonCount: {TargetPersonCount}");
79+
await machineUtils.InvokeVoidAsync("executeDrawBall", TargetPersonCount);
7080
await OnBeforeDrawMachine.InvokeAsync();
7181
}
7282

@@ -106,7 +116,7 @@
106116
return;
107117
}
108118
Status = DrawMachineStatus.Done;
109-
Console.WriteLine("ASDF");
119+
110120
await OnDrawAnimationEnd.InvokeAsync(new DrawAnimationEndEventArgs
111121
{
112122
user = SelectedUserInfo,

src/DotNetDevLottery/Components/Random/MachineAnimation.razor.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,33 @@
1919
--spectrum-button-content-color-down: hsl(355.7 100% 97.3%/.9);
2020
--spectrum-button-content-color-focus: hsl(355.7 100% 97.3%/.9);
2121
}
22+
2223
.button-row {
2324
flex: 0 0 auto;
2425
padding: 5px 0;
26+
gap: 1rem;
27+
line-height: 50px;
2528
height: 50px;
2629
display: flex;
2730
justify-content: center;
2831
box-sizing: border-box;
32+
33+
& ui-button:has(span) {
34+
padding: 0;
35+
}
2936
}
37+
3038
.machine-wrapper {
3139
flex: 1 1 auto;
3240
display: flex;
3341
justify-content: center;
3442
align-items: center;
3543
}
44+
3645
.machine {
3746
position: relative;
3847
}
48+
3949
.machine ::deep .machine-inner {
4050
position: absolute;
4151
top: 50%;
@@ -45,6 +55,7 @@
4555
border-radius: 50%;
4656
padding: 0;
4757
}
58+
4859
.machine ::deep .ball {
4960
position: absolute;
5061
background-color: #666666;

src/DotNetDevLottery/DotNetDevLottery.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
8-
<ItemGroup>
9-
<Compile Remove="wwwroot\js\**" />
10-
<Content Remove="wwwroot\js\**" />
11-
<EmbeddedResource Remove="wwwroot\js\**" />
12-
<None Remove="wwwroot\js\**" />
13-
</ItemGroup>
148
<Target Name="NpmInstall" Inputs="package.json" Outputs="node_modules/.install-stamp">
159
<Exec Command="pnpm i" Condition="$(RestorePackagesWithLockFile) != 'true'" ConsoleToMsBuild="true" />
1610

src/DotNetDevLottery/Pages/Main.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class Main : ComponentBase, IAsyncDisposable
2727

2828
protected override async Task OnInitializedAsync()
2929
{
30-
elementUtils = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./Pages/Main.razor.js");
30+
elementUtils = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "/js/Pages/Main.r.js");
3131
await elementUtils.InvokeVoidAsync("addDropEventToChangeInputFile", dropzoneElement);
3232
}
3333

src/DotNetDevLottery/Pages/Random.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected override async Task OnInitializedAsync()
3030
return;
3131
}
3232

33-
lottieUtils = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./Pages/Random.razor.js");
33+
lottieUtils = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "/js/Pages/Random.r.js");
3434
}
3535

3636
public void OnBeforeDrawMachine()

src/DotNetDevLottery/config/build-script.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ const cwd = process.cwd();
1010
const indexEntryPoint = path.resolve(cwd, "./typescript/index.ts");
1111

1212
const componentEntryPoints = await glob([
13-
"./typescript/Components/**/*.razor.ts",
13+
"./typescript/Components/**/*.r.ts",
1414
], {
1515
cwd
1616
});
1717
const pageEntryPoints = await glob([
18-
"./typescript/Pages/**/*.razor.ts",
18+
"./typescript/Pages/**/*.r.ts",
1919
], {
2020
cwd
2121
});
@@ -35,7 +35,7 @@ const baseOptions = {
3535
const pageEntryPointOptions = {
3636
...baseOptions,
3737
entryPoints: pageEntryPoints,
38-
outdir: path.resolve(cwd, "./wwwroot/Pages"),
38+
outdir: path.resolve(cwd, "./wwwroot/js/Pages"),
3939
outbase: path.resolve(cwd, "./typescript/Pages"),
4040
};
4141
/** @type {import('esbuild').BuildOptions} */
@@ -44,7 +44,7 @@ const componentEntryPointOptions = {
4444
ignoreAnnotations: true,
4545
splitting: true,
4646
entryPoints: componentEntryPoints,
47-
outdir: path.resolve(cwd, "./wwwroot/Components"),
47+
outdir: path.resolve(cwd, "./wwwroot/js/Components"),
4848
outbase: path.resolve(cwd, "./typescript/Components"),
4949
};
5050
const indexOptions = {

src/DotNetDevLottery/package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99
"keywords": [],
1010
"author": "",
1111
"license": "ISC",
12-
"packageManager": "pnpm@9.3.0+sha512.ee7b93e0c2bd11409c6424f92b866f31d3ea1bef5fbe47d3c7500cdc3c9668833d2e55681ad66df5b640c61fa9dc25d546efa54d76d7f8bf54b13614ac293631",
12+
"packageManager": "pnpm@10.13.1",
1313
"dependencies": {
14-
"@dimforge/rapier2d": "^0.14.0",
15-
"@dimforge/rapier2d-compat": "^0.14.0",
16-
"@lottiefiles/dotlottie-wc": "^0.2.22",
17-
"@spectrum-web-components/bundle": "^0.48.1",
14+
"@dimforge/rapier2d": "^0.17.3",
15+
"@dimforge/rapier2d-compat": "^0.17.3",
16+
"@lottiefiles/dotlottie-wc": "^0.6.3",
17+
"@spectrum-web-components/bundle": "^1.7.0",
18+
"@spectrum-web-components/textfield": "^1.7.0",
1819
"mitt": "^3.0.1"
1920
},
2021
"devDependencies": {
2122
"@microsoft/dotnet-js-interop": "^8.0.0",
22-
"@types/node": "^20.16.5",
23-
"esbuild": "^0.24.0",
23+
"@types/node": "^24.0.14",
24+
"esbuild": "^0.25.6",
2425
"esbuild-plugin-wasm": "^1.1.0",
25-
"tinyglobby": "^0.2.9",
26-
"typescript": "^5.6.3"
26+
"tinyglobby": "^0.2.14",
27+
"typescript": "^5.8.3"
2728
}
2829
}

0 commit comments

Comments
 (0)