Skip to content

Instantly share code, notes, and snippets.

@CannoHarito
Created December 31, 2023 08:51
Show Gist options
  • Save CannoHarito/3a16327079bdca05a817d91331dda578 to your computer and use it in GitHub Desktop.
Save CannoHarito/3a16327079bdca05a817d91331dda578 to your computer and use it in GitHub Desktop.
BLUE PROTOCOL(ブルプロ)のレグナス時間をターミナルのプロンプトで表示するPowerShell
. .\Regnus-Clock.ps1
# 更新間隔秒数
$tickDuration = 10
function Invoke-Regnus-Clock {
$currentName = Get-Name
$first = Get-Next-Term
$second = $first | Get-Next-Term
try {
while (1) {
while ( ($remain = $first.date - (Get-Date)) -gt [timespan]::FromSeconds(0.5)) {
$sec = [Math]::Round($remain.TotalSeconds)
Write-Progress ("{0} 残り[{1:00}分{2:00}秒]" -f $currentName, ([Math]::Truncate($sec / 60)), ($sec % 60)) `
"次の$($first.name)[$($first.date.ToString("T"))], 次の$($second.name)[$($second.date.ToString("T"))]" `
-PercentComplete ((1 - $remain.TotalSeconds / $termDuration) * 100)
Start-Sleep -Seconds (($remain.TotalSeconds - 0.3) % $tickDuration + 0.3)
}
$currentName = $first.name
$first = $second
$second = $second | Get-Next-Term
}
}
finally {
Write-Progress "" -Completed
}
}
if ($MyInvocation.InvocationName -ne ".") {
Invoke-Regnus-Clock
}
# UTC00:00:00以降、最初の昼の始まる秒数
$termStart = 728
# レグナスの昼の秒数
$termDuration = 25 * 60
# 昼と夜は0番目の昼,1番目の夜,~,($termCountMax-1)番目まで
$termCountMax = [Math]::Floor( 24 * 60 * 60 / $termDuration) + 1
# 24時間で昼夜を繰り返し残る端数の秒数
$fixSecond = ( 24 * 60 * 60 - $termStart) % $termDuration
function Get-Count {
param([Parameter(ValueFromPipeline)][datetime]$date = (Get-Date))
process {
$utcInstant = $date.ToUniversalTime() | ForEach-Object { $_.Hour * 60 * 60 + $_.Minute * 60 + $_.Second }
$fixedInstant = ($utcInstant + $fixSecond) % (24 * 60 * 60) - $fixSecond
($fixedInstant - $termStart) / $termDuration
}
}
function Get-Name {
param([Parameter(ValueFromPipeline)][double]$count = (Get-Count))
process {
switch ([Math]::Floor($count)) {
{ $_ % 2 -eq 0 } { "昼" }
default { "夜" }
}
}
}
function Get-Second {
param([Parameter(ValueFromPipeline)][double]$count = 0)
process {
$termStart + [int]($count * $termDuration)
}
}
function New-Term {
param([Parameter(ValueFromPipeline)][datetime]$date = (Get-Date))
process {
$count = Get-Count $date
$name = Get-Name $count
[PSCustomObject]@{
date = $date
count = $count
name = $name
}
}
}
function Get-Next-Term {
param(
[Parameter(ValueFromPipelineByPropertyName)][datetime]$date = (Get-Date),
[Parameter(ValueFromPipelineByPropertyName)][double]$count = (Get-Count)
)
process {
$nextCount = ([Math]::Floor($count) + 1) % $termCountMax
$nextDate = (Get-Date $date.ToUniversalTime().ToString("yyyy/MM/dd Z")).AddSeconds((Get-Second $nextCount))
if ($nextDate - $date -le 0) {
$nextDate = $nextDate.AddDays(1)
}
[PSCustomObject]@{
date = $nextDate
count = $nextCount
name = Get-Name $nextCount
}
}
}
if ($MyInvocation.InvocationName -ne ".") {
# $current = Get-Date "8:57" | New-Term
$current = New-Term
$first = $current | Get-Next-Term
$second = $first | Get-Next-Term
$current
$first
$second
}
@CannoHarito
Copy link
Author

wt.exeだとこんな感じ。Ctrl+Cで終了する。残り秒数表示が$tickDurationの倍数になるように時間調整しているのがこだわり。
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment