-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,882 additions
and
1,394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20.14 | ||
20.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
public-hoist-pattern[]=@spectrum-web-components/theme | ||
public-hoist-pattern[]=@spectrum-web-components/theme |
Empty file.
99 changes: 99 additions & 0 deletions
99
src/DotNetDevLottery/Components/Random/MachineAnimation.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
@inject IJSRuntime JSRuntime | ||
|
||
<div class="container"> | ||
<div class="button-row"> | ||
<ui-button | ||
treatment="outline" | ||
@onclick="OnClickButton" | ||
class="success"> | ||
추첨 진행 | ||
</ui-button> | ||
</div> | ||
<div class="machine-wrapper"> | ||
<div class="machine" @ref="machineElement" /> | ||
</div> | ||
</div> | ||
|
||
@code { | ||
ElementReference machineElement; | ||
IJSObjectReference? machineUtils; | ||
[Parameter, EditorRequired] | ||
required public UserInfo[] UserInfoList { get; set; } | ||
[Parameter] | ||
public EventCallback OnBeforeDrawMachine { get; set; } | ||
[Parameter] | ||
public EventCallback<DrawUserEventArgs> OnDrawUser { get; set; } | ||
[Parameter] | ||
public EventCallback<DrawAnimationEndEventArgs> OnDrawAnimationEnd { get; set; } | ||
|
||
public UserInfo? SelectedUserInfo = null; | ||
int PersonCount = 0; | ||
int RemainedPersonCount = 0; | ||
List<int> WinnedUserList = new List<int>(); | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
PersonCount = UserInfoList.Count(); | ||
RemainedPersonCount = PersonCount; | ||
if (PersonCount == 0) { | ||
return; | ||
} | ||
machineUtils = await JSRuntime.InvokeAsync<IJSObjectReference>( | ||
"import", | ||
"/js/Components/MachineAnimation.razor.js" | ||
); | ||
await machineUtils.InvokeVoidAsync( | ||
"init", | ||
Math.Max(Math.Min(PersonCount, 60), 30), | ||
machineElement, | ||
DotNetObjectReference.Create(this), | ||
nameof(OnDrawMachine), | ||
nameof(OnDrawMachineAnimationEnd) | ||
); | ||
} | ||
|
||
public async Task OnClickButton() | ||
{ | ||
if (machineUtils == null) { | ||
return; | ||
} | ||
SelectedUserInfo = null; | ||
await machineUtils.InvokeVoidAsync("executeDrawBall"); | ||
await OnBeforeDrawMachine.InvokeAsync(); | ||
} | ||
|
||
[JSInvokable] | ||
public async Task<UserInfo?> OnDrawMachine() | ||
{ | ||
if (RemainedPersonCount < 1) | ||
{ | ||
// TODO: 남은 인원 없음 알림 | ||
return null; | ||
} | ||
var randomObj = new System.Random(); | ||
var index = randomObj.Next(RemainedPersonCount); | ||
while(WinnedUserList.Contains(index)) { | ||
index = randomObj.Next(RemainedPersonCount); | ||
} | ||
SelectedUserInfo = UserInfoList.ElementAtOrDefault(index); | ||
if (SelectedUserInfo == null) { | ||
return null; | ||
} | ||
WinnedUserList.Add(index); | ||
await OnDrawUser.InvokeAsync(new DrawUserEventArgs{ | ||
Status = DrawMachineStatus.Drawed | ||
}); | ||
return SelectedUserInfo; | ||
} | ||
[JSInvokable] | ||
public async Task OnDrawMachineAnimationEnd() | ||
{ | ||
if (SelectedUserInfo == null) { | ||
return; | ||
} | ||
await OnDrawAnimationEnd.InvokeAsync(new DrawAnimationEndEventArgs{ | ||
user = SelectedUserInfo, | ||
Status = DrawMachineStatus.Drawed | ||
}); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/DotNetDevLottery/Components/Random/MachineAnimation.razor.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
.container { | ||
width: 70%; | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.success { | ||
--spectrum-button-background-color-default: hsl(142.1 76.2% 36.3%); | ||
--spectrum-button-background-color-hover: hsl(142.1 76.2% 36.3%/.9); | ||
--spectrum-button-background-color-down: hsl(142.1 76.2% 36.3%/.9); | ||
--spectrum-button-background-color-focus: hsl(142.1 76.2% 36.3%/.9); | ||
--spectrum-button-border-color-default: hsl(142.1 76.2% 36.3%); | ||
--spectrum-button-border-color-hover: hsl(142.1 76.2% 36.3%/.9); | ||
--spectrum-button-border-color-down: hsl(142.1 76.2% 36.3%/.9); | ||
--spectrum-button-border-color-focus: hsl(142.1 76.2% 36.3%/.9); | ||
--spectrum-button-content-color-default: hsl(355.7 100% 97.3%); | ||
--spectrum-button-content-color-hover: hsl(355.7 100% 97.3%/.9); | ||
--spectrum-button-content-color-down: hsl(355.7 100% 97.3%/.9); | ||
--spectrum-button-content-color-focus: hsl(355.7 100% 97.3%/.9); | ||
} | ||
.button-row { | ||
flex: 0 0 auto; | ||
padding: 5px 0; | ||
height: 50px; | ||
display: flex; | ||
justify-content: center; | ||
box-sizing: border-box; | ||
} | ||
.machine-wrapper { | ||
flex: 1 1 auto; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: relative; | ||
} | ||
.machine ::deep .machine-inner { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
border: 2px solid #222222; | ||
border-radius: 50%; | ||
padding: 0; | ||
} | ||
.machine ::deep .ball { | ||
position: absolute; | ||
background-color: #666666; | ||
border: 2px solid #222222; | ||
border-radius: 50%; | ||
width: calc(var(--ball-size) * 1px); | ||
height: calc(var(--ball-size) * 1px); | ||
} | ||
|
||
.machine ::deep .ball.ball--drawed { | ||
background-color: #666666; | ||
border: 0; | ||
font-size: calc(var(--ball-size) * .07px); | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: calc(var(--ball-size) * .1px); | ||
} | ||
|
||
.machine ::deep .ball.ball--drawed .name { | ||
font-size: calc(var(--ball-size) * .1px); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace DotNetDevLottery.Models; | ||
|
||
public enum DrawMachineStatus { | ||
Init, | ||
Pending, | ||
Drawed, | ||
Done, | ||
} | ||
|
||
public class DrawUserEventArgs { | ||
public DrawMachineStatus Status; | ||
} | ||
|
||
public class DrawAnimationEndEventArgs { | ||
public DrawMachineStatus Status; | ||
required public UserInfo user; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.