Skip to content

Commit

Permalink
Merge pull request #123 from 24ik/ik
Browse files Browse the repository at this point in the history
[breaking] fix URL host
  • Loading branch information
24ik authored Sep 25, 2024
2 parents c2bebda + 2ea271b commit 3424d94
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 110 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Features:
- Generator: Generates the Nazo Puyo.
- Permuter: Permutes the pairs in the Nazo Puyo to find a unique-solution
problem.
- [GUI Application](https://izumiya-keisuke.github.io/pon2/gui?editor&kind=n&mode=e&field=t-&pairs&req-kind=0&req-color=0): GUI simulator for Puyo Puyo and Nazo Puyo.
- [Marathon](https://izumiya-keisuke.github.io/pon2/marathon): Search for pairs sequence and play a marathon mode.
- [GUI Application](https://24ik.github.io/pon2/gui?editor&kind=n&mode=e&field=t-&pairs&req-kind=0&req-color=0): GUI simulator for Puyo Puyo and Nazo Puyo.
- [Marathon](https://24ik.github.io/pon2/marathon): Search for pairs sequence and play a marathon mode.

Not supported now:
- Wall Puyo, Hard-garbage Puyo, and Iron Puyo
Expand All @@ -24,7 +24,7 @@ native-GUI application is beta version.
### Downloading Binary

You can get the binary at the
[latest release](https://github.com/izumiya-keisuke/pon2/releases/latest).
[latest release](https://github.com/24ik/pon2/releases/latest).
Note that the built binary may not work on macOS due to the limitation of
[NiGui](https://github.com/simonkrauter/NiGui).

Expand Down Expand Up @@ -58,7 +58,7 @@ See the documentations:

### API Usage

See the [API documentation](https://izumiya-keisuke.github.io/pon2/docs/pon2.html).
See the [API documentation](https://24ik.github.io/pon2/docs/pon2.html).

### Running Tests

Expand Down
6 changes: 3 additions & 3 deletions pon2.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.16.3"
version = "0.17.0"
author = "Keisuke Izumiya"
description = "Application for Puyo Puyo and Nazo Puyo"
license = "Apache-2.0"
Expand All @@ -11,12 +11,12 @@ bin = @["pon2"]

# Dependencies

requires "nim ^= 2.0.4"
requires "nim ^= 2.0.8"

requires "docopt ^= 0.7.1"
requires "karax ^= 1.3.3"
requires "nigui ^= 0.2.8"
requires "nimsimd ^= 1.2.10"
requires "nimsimd ^= 1.2.13"
requires "suru ^= 0.3.2"

# Tasks
Expand Down
3 changes: 3 additions & 0 deletions src/config.nims
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
--define:
ssl
--passC:
"-Wno-error=incompatible-pointer-types"
# NOTE: this can be removed after docopt's update
22 changes: 10 additions & 12 deletions src/pon2pkg/app/simulator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -619,20 +619,20 @@ const
for mode in SimulatorMode:
{$mode: mode}

func toUri*(self; withPositions: bool, editor: bool, host = Izumiya): Uri {.inline.} =
func toUri*(self; withPositions: bool, editor: bool, host = Ik): Uri {.inline.} =
## Returns the URI converted from the simulator.
## Any moves are reset.
## `self.editor` is overridden with `editor`.
result = initUri()
result.scheme =
case host
of Izumiya, Ishikawa: "https"
of Ik, Ishikawa: "https"
of Ips: "http"
result.hostname = $host

# path
case host
of Izumiya:
of Ik:
result.path = "/pon2/gui/index.html"
of Ishikawa, Ips:
let modeChar =
Expand Down Expand Up @@ -666,7 +666,7 @@ func toUri*(self; withPositions: bool, editor: bool, host = Izumiya): Uri {.inli
nazo.toUriQuery host

case host
of Izumiya:
of Ik:
# editor, kind, mode
var queries = newSeq[(string, string)](0)
if editor:
Expand All @@ -678,7 +678,7 @@ func toUri*(self; withPositions: bool, editor: bool, host = Izumiya): Uri {.inli
of Ishikawa, Ips:
result.query = mainQuery

func toUri*(self; withPositions: bool, host = Izumiya): Uri {.inline.} =
func toUri*(self; withPositions: bool, host = Ik): Uri {.inline.} =
## Returns the URI converted from the simulator.
## Any moves are reset.
self.toUri(withPositions, self.editor, host)
Expand All @@ -689,7 +689,7 @@ func parseSimulator*(uri: Uri): Simulator {.inline.} =
result = initPuyoPuyo[TsuField]().initSimulator # HACK: dummy to suppress warning

case uri.hostname
of $Izumiya:
of $Ik:
if uri.path != "/pon2/gui/index.html":
raise newException(ValueError, "Invalid simulator: " & $uri)

Expand Down Expand Up @@ -726,20 +726,18 @@ func parseSimulator*(uri: Uri): Simulator {.inline.} =
case kind
of Regular:
try:
result = parsePuyoPuyo[TsuField](mainQuery, Izumiya).initSimulator(mode, editor)
result = parsePuyoPuyo[TsuField](mainQuery, Ik).initSimulator(mode, editor)
except ValueError:
try:
result =
parsePuyoPuyo[WaterField](mainQuery, Izumiya).initSimulator(mode, editor)
result = parsePuyoPuyo[WaterField](mainQuery, Ik).initSimulator(mode, editor)
except ValueError:
raise newException(ValueError, "Invalid simulator: " & $uri)
of Nazo:
try:
result = parseNazoPuyo[TsuField](mainQuery, Izumiya).initSimulator(mode, editor)
result = parseNazoPuyo[TsuField](mainQuery, Ik).initSimulator(mode, editor)
except ValueError:
try:
result =
parseNazoPuyo[WaterField](mainQuery, Izumiya).initSimulator(mode, editor)
result = parseNazoPuyo[WaterField](mainQuery, Ik).initSimulator(mode, editor)
except ValueError:
raise newException(ValueError, "Invalid simulator: " & $uri)
of $Ishikawa, $Ips:
Expand Down
25 changes: 12 additions & 13 deletions src/pon2pkg/core/field.nim
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ func parseField*[F: TsuField or WaterField](str: string): F {.inline.} =
# ------------------------------------------------

const
IzumiyaUriRuleFieldSep = "-"
IzumiyaUriAirWaterSep = "~"
IkUriRuleFieldSep = "-"
IkUriAirWaterSep = "~"

IzumiyaUriToRule = collect:
IkUriToRule = collect:
for rule in Rule:
{$rule: rule}

Expand All @@ -355,7 +355,7 @@ func toUriQuery*(self: TsuField or WaterField, host: SimulatorHost): string {.in
let arr = self.toArray

case host
of Izumiya:
of Ik:
let cellsStr =
case self.rule
of Tsu:
Expand All @@ -376,11 +376,10 @@ func toUriQuery*(self: TsuField or WaterField, host: SimulatorHost): string {.in
for cell in arr[row]:
$cell

airChars.join.strip(trailing = false, chars = {($None)[0]}) &
IzumiyaUriAirWaterSep &
airChars.join.strip(trailing = false, chars = {($None)[0]}) & IkUriAirWaterSep &
underWaterChars.join.strip(leading = false, chars = {($None)[0]})

result = $self.rule & IzumiyaUriRuleFieldSep & cellsStr
result = $self.rule & IkUriRuleFieldSep & cellsStr
of Ishikawa, Ips:
var lines = newSeqOfCap[string](Height)
for row in Row.low .. Row.high:
Expand Down Expand Up @@ -408,14 +407,14 @@ func parseField*[F: TsuField or WaterField](
arr[Row.low][Column.low] = Cell.low # dummy to remove warning

case host
of Izumiya:
let strs = query.split IzumiyaUriRuleFieldSep
if strs.len != 2 or strs[0] notin IzumiyaUriToRule:
of Ik:
let strs = query.split IkUriRuleFieldSep
if strs.len != 2 or strs[0] notin IkUriToRule:
raise newException(ValueError, "Invalid field: " & query)

if strs[0] notin IzumiyaUriToRule:
if strs[0] notin IkUriToRule:
raise newException(ValueError, "Invalid field: " & query)
let rule = IzumiyaUriToRule[strs[0]]
let rule = IkUriToRule[strs[0]]

when F is TsuField:
if rule != Tsu:
Expand All @@ -434,7 +433,7 @@ func parseField*[F: TsuField or WaterField](
for col in Column.low .. Column.high:
arr[row][col] = parseCell $cellsStr[row * Width + col]
of Water:
let cellsStrs = strs[1].split IzumiyaUriAirWaterSep
let cellsStrs = strs[1].split IkUriAirWaterSep
if cellsStrs.len != 2 or cellsStrs[0].len > AirHeight * Width or
cellsStrs[1].len > WaterHeight * Width:
raise newException(ValueError, "Invalid field: " & query)
Expand Down
2 changes: 1 addition & 1 deletion src/pon2pkg/core/host.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

type SimulatorHost* {.pure.} = enum
## URI host of the web simulator.
Izumiya = "izumiya-keisuke.github.io"
Ik = "24ik.github.io"
Ishikawa = "ishikawapuyo.net"
Ips = "ips.karou.jp"
4 changes: 2 additions & 2 deletions src/pon2pkg/core/nazopuyo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func toUriQuery*[F: TsuField or WaterField](
## Returns the URI query converted from the Nazo Puyo.
let sep =
case host
of Izumiya: "&"
of Ik: "&"
of Ishikawa, Ips: "__"

result = &"{self.puyoPuyo.toUriQuery host}{sep}{self.requirement.toUriQuery host}"
Expand All @@ -104,7 +104,7 @@ func parseNazoPuyo*[F: TsuField or WaterField](
## Returns the Nazo Puyo converted from the URI query.
## If the query is invalid, `ValueError` is raised.
case host
of Izumiya:
of Ik:
var
puyoPuyoKeyVals = newSeq[(string, string)](0)
reqKeyVals = newSeq[(string, string)](0)
Expand Down
9 changes: 4 additions & 5 deletions src/pon2pkg/core/pair.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ using
# Constructor
# ------------------------------------------------

const FirstPairs: array[ColorPuyo, Pair] = [
RedRed, GreenRed, BlueRed, YellowRed, PurpleRed
]
const FirstPairs: array[ColorPuyo, Pair] =
[RedRed, GreenRed, BlueRed, YellowRed, PurpleRed]

func initPair*(axis, child: ColorPuyo): Pair {.inline.} =
## Returns a new Pair.
Expand Down Expand Up @@ -162,7 +161,7 @@ const
func toUriQuery*(self; host: SimulatorHost): string {.inline.} =
## Returns the URI query converted from the pair.
case host
of Izumiya:
of Ik:
$self
of Ishikawa, Ips:
$PairToIshikawaUri[self.ord]
Expand All @@ -171,7 +170,7 @@ func parsePair*(query: string, host: SimulatorHost): Pair {.inline.} =
## Returns the pair converted from the URI query.
## If the query is invalid, `ValueError` is raised.
case host
of Izumiya:
of Ik:
result = query.parsePair
of Ishikawa, Ips:
try:
Expand Down
12 changes: 8 additions & 4 deletions src/pon2pkg/core/pairposition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func parsePairPosition*(query: string, host: SimulatorHost): PairPosition {.inli
## If the query is invalid, `ValueError` is raised.
# NOTE: this function is not robust; dependent on the current URI format
case host
of Izumiya:
of Ik:
result.pair = query[0 ..< 2].parsePair host
result.position = query[2 ..^ 1].parsePosition host
of Ishikawa, Ips:
Expand All @@ -100,15 +100,19 @@ func parsePairPosition*(query: string, host: SimulatorHost): PairPosition {.inli
# PairsPositions <-> URI
# ------------------------------------------------

func toUriQuery*(pairsPositions: PairsPositions, host: SimulatorHost): string {.inline.} =
func toUriQuery*(
pairsPositions: PairsPositions, host: SimulatorHost
): string {.inline.} =
## Returns the URI query converted from the pairs&positions.
let strs = collect:
for pairPos in pairsPositions:
pairPos.toUriQuery host

result = strs.join

func parsePairsPositions*(query: string, host: SimulatorHost): PairsPositions {.inline.} =
func parsePairsPositions*(
query: string, host: SimulatorHost
): PairsPositions {.inline.} =
## Returns the pairs&positions converted from the URI query.
## If the query is invalid, `ValueError` is raised.
# NOTE: this function is not robust; dependent on the current URI format
Expand All @@ -118,7 +122,7 @@ func parsePairsPositions*(query: string, host: SimulatorHost): PairsPositions {.
result = newSeqOfCap[PairPosition](query.len div 2)

case host
of Izumiya:
of Ik:
var idx = 0
while idx < query.len:
try:
Expand Down
12 changes: 6 additions & 6 deletions src/pon2pkg/core/position.nim
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ func childDirection*(self): Direction {.inline.} =
const
RightPositions: array[Position, Position] = [
None, Up1, Up2, Up3, Up4, Up5, Up5, Right1, Right2, Right3, Right4, Right4, Down1,
Down2, Down3, Down4, Down5, Down5, Left2, Left3, Left4, Left5, Left5
Down2, Down3, Down4, Down5, Down5, Left2, Left3, Left4, Left5, Left5,
]
LeftPositions: array[Position, Position] = [
None, Up0, Up0, Up1, Up2, Up3, Up4, Right0, Right0, Right1, Right2, Right3, Down0,
Down0, Down1, Down2, Down3, Down4, Left1, Left1, Left2, Left3, Left4
Down0, Down1, Down2, Down3, Down4, Left1, Left1, Left2, Left3, Left4,
]

func movedRight*(self): Position {.inline.} = ## Returns the position moved rightward.
Expand All @@ -151,11 +151,11 @@ func moveLeft*(mSelf) {.inline.} = ## Moves the position leftward.
const
RightRotatePositions: array[Position, Position] = [
None, Right0, Right1, Right2, Right3, Right4, Right4, Down0, Down1, Down2, Down3,
Down4, Left1, Left1, Left2, Left3, Left4, Left5, Up1, Up2, Up3, Up4, Up5
Down4, Left1, Left1, Left2, Left3, Left4, Left5, Up1, Up2, Up3, Up4, Up5,
]
LeftRotatePositions: array[Position, Position] = [
None, Left1, Left1, Left2, Left3, Left4, Left5, Up0, Up1, Up2, Up3, Up4, Right0,
Right1, Right2, Right3, Right4, Right4, Down1, Down2, Down3, Down4, Down5
Right1, Right2, Right3, Right4, Right4, Down1, Down2, Down3, Down4, Down5,
]

func rotatedRight*(self): Position {.inline.} =
Expand Down Expand Up @@ -202,7 +202,7 @@ const
func toUriQuery*(self; host: SimulatorHost): string {.inline.} =
## Returns the URI query converted from the position.
case host
of Izumiya:
of Ik:
$self
of Ishikawa, Ips:
$PosToIshikawaUri[self.ord]
Expand All @@ -211,7 +211,7 @@ func parsePosition*(query: string, host: SimulatorHost): Position {.inline.} =
## Returns the position converted from the URI query.
## If the query is invalid, `ValueError` is raised.
case host
of Izumiya:
of Ik:
result = query.parsePosition
of Ishikawa, Ips:
try:
Expand Down
4 changes: 2 additions & 2 deletions src/pon2pkg/core/puyopuyo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func toUriQuery*[F: TsuField or WaterField](
): string {.inline.} =
## Returns the URI query converted from the Puyo Puyo.
case host
of Izumiya:
of Ik:
encodeQuery [
(FieldKey, self.field.toUriQuery host),
(PairsPositionsKey, self.pairsPositions.toUriQuery host),
Expand All @@ -323,7 +323,7 @@ func parsePuyoPuyo*[F: TsuField or WaterField](
result.operatingIdx = 0

case host
of Izumiya:
of Ik:
var
fieldSet = false
pairsPositionsSet = false
Expand Down
6 changes: 3 additions & 3 deletions src/pon2pkg/core/requirement.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type
const
NoColorKinds* = {
DisappearColor, DisappearColorMore, Chain, ChainMore, DisappearColorSametime,
DisappearColorMoreSametime
DisappearColorMoreSametime,
} ## All requirement kinds not containing 'c'.
NoNumberKinds* = {Clear} ## All requirement kinds not containing 'n'.

Expand Down Expand Up @@ -153,7 +153,7 @@ const
func toUriQuery*(req: Requirement, host: SimulatorHost): string {.inline.} =
## Returns the URI query converted from the requirement.
case host
of Izumiya:
of Ik:
var queries = @[(KindKey, $req.kind.ord)]
if req.kind in ColorKinds:
queries.add (ColorKey, $req.color.ord)
Expand Down Expand Up @@ -186,7 +186,7 @@ func parseRequirement*(query: string, host: SimulatorHost): Requirement {.inline
number = RequirementNumber.low

case host
of Izumiya:
of Ik:
var
kindSet = false
colorSet = false
Expand Down
Loading

0 comments on commit 3424d94

Please sign in to comment.