From dd2f79eba37aee537ae1e27ea82dcd41a5c5e46f Mon Sep 17 00:00:00 2001 From: Keisuke Izumiya Date: Fri, 15 Nov 2024 06:21:14 +0900 Subject: [PATCH] [enhancement] [bug] simulator URI --- src/pon2/app.nim | 4 +- src/pon2/app/ide.nim | 89 +------------------ src/pon2/app/ide/web.nim | 22 ++--- src/pon2/app/simulator.nim | 87 ++++++++++++++++++ src/pon2/app/simulator/web.nim | 25 ++++-- src/pon2/private/app/ide/web/answer.nim | 2 +- src/pon2/private/app/simulator/common.nim | 29 +++++- .../private/app/simulator/web/requirement.nim | 6 +- .../app/{ide => simulator}/web/share.nim | 71 +++++++-------- src/pon2/private/main/web.nim | 4 +- tests/ide/main.nim | 4 +- tests/simulator/main.nim | 11 ++- 12 files changed, 189 insertions(+), 165 deletions(-) rename src/pon2/private/app/{ide => simulator}/web/share.nim (69%) diff --git a/src/pon2/app.nim b/src/pon2/app.nim index 066f1dd..d6b68ec 100644 --- a/src/pon2/app.nim +++ b/src/pon2/app.nim @@ -15,7 +15,7 @@ ## Compile Options: ## | Option | Description | Default | ## | ------------------------------ | -------------------------------- | ------------------- | -## | `-d:pon2.path=` | URI path of the web IDE. | `/pon2/` | +## | `-d:pon2.path=` | URI path of the web simulator. | `/pon2/` | ## | `-d:pon2.workerfilename=` | File name of the web worker. | `worker.min.js` | ## | `-d:pon2.assets.native=` | Assets directory for native app. | `/assets` | ## | `-d:pon2.assets.web=` | Assets directory for web app. | `./assets` | @@ -70,7 +70,7 @@ export simulator.moveOperatingPositionRight, simulator.moveOperatingPositionLeft, simulator.rotateOperatingPositionRight, simulator.rotateOperatingPositionLeft, simulator.forward, simulator.backward, simulator.reset, simulator.toUriQuery, - simulator.parseSimulator, simulator.operate + simulator.toUri, simulator.parseSimulator, simulator.operate export solve.SolveAnswer, solve.solve when defined(js): diff --git a/src/pon2/app/ide.nim b/src/pon2/app/ide.nim index b7299fc..56b4fe3 100644 --- a/src/pon2/app/ide.nim +++ b/src/pon2/app/ide.nim @@ -1,10 +1,5 @@ ## This module implements the IDE. ## -## Compile Options: -## | Option | Description | Default | -## | -------------------- | ------------------------ | -------- | -## | `-d:pon2.path=` | URI path of the web IDE. | `/pon2/` | -## when defined(js): ## See also the [backend-specific documentation](./ide/web.html). ## @@ -21,7 +16,7 @@ else: {.experimental: "strictFuncs".} {.experimental: "views".} -import std/[deques, sequtils, strformat, strutils, sugar, uri] +import std/[deques, sequtils, sugar, uri] import ./[key, nazopuyo, simulator] import ../core/[field, fqdn, nazopuyo, pairposition, puyopuyo, requirement] import ../private/[misc] @@ -58,11 +53,6 @@ type progressBarData: tuple[now: Natural, total: Natural] -const IdeUriPath* {.define: "pon2.path".} = "/pon2/" - -static: - doAssert IdeUriPath.startsWith '/' - # ------------------------------------------------ # Constructor # ------------------------------------------------ @@ -312,85 +302,12 @@ proc prevAnswer*(self: Ide) {.inline.} = func toUri*(self: Ide, withPositions = true, fqdn = Pon2): Uri {.inline.} = ## Returns the URI converted from the IDE. - result = initUri() - result.scheme = - case fqdn - of Pon2, Ishikawa: "https" - of Ips: "http" - result.hostname = $fqdn - result.query = self.simulator.toUriQuery(withPositions, fqdn) - - # path - case fqdn - of Pon2: - result.path = IdeUriPath - of Ishikawa, Ips: - let modeChar = - case self.simulator.kind - of Regular: - case self.simulator.mode - of Play, PlayEditor: 's' - of Edit: 'e' - of View: 'v' - of Nazo: - 'n' - result.path = &"/simu/p{modeChar}.html" - -func allowedUriPaths(path: string): seq[string] {.inline.} = - ## Returns the allowed paths. - result = @[path] - - if path.endsWith "/index.html": - result.add path.dup(removeSuffix("index.html")) - elif path.endsWith '/': - result.add &"{path}index.html" - -const AllowedSimulatorUriPaths = IdeUriPath.allowedUriPaths + self.simulator.toUri(withPositions, fqdn) proc parseIde*(uri: Uri): Ide {.inline.} = ## Returns the IDE converted from the URI. ## If the URI is invalid, `ValueError` is raised. - var - kind = SimulatorKind.low - mode = SimulatorMode.low - let fqdn: IdeFqdn - case uri.hostname - of $Pon2: - if uri.path notin AllowedSimulatorUriPaths: - raise newException(ValueError, "Invalid IDE: " & $uri) - - fqdn = Pon2 - of $Ishikawa, $Ips: - fqdn = if uri.hostname == $Ishikawa: Ishikawa else: Ips - - # kind, mode - case uri.path - of "/simu/pe.html": - kind = Regular - mode = Edit - of "/simu/ps.html": - kind = Regular - mode = Play - of "/simu/pv.html": - kind = Regular - mode = View - of "/simu/pn.html": - kind = Nazo - mode = Play - else: - result = newIde() # HACK: dummy to suppress warning - raise newException(ValueError, "Invalid IDE: " & $uri) - else: - fqdn = Pon2 # HACK: dummy to compile - result = newIde() # HACK: dummy to suppress warning - raise newException(ValueError, "Invalid IDE: " & $uri) - - let simulator = uri.query.parseSimulator fqdn - if fqdn in {Ishikawa, Ips}: - simulator.kind = kind - simulator.mode = mode - - result = simulator.newIde + uri.parseSimulator.newIde # ------------------------------------------------ # Keyboard Operation diff --git a/src/pon2/app/ide/web.nim b/src/pon2/app/ide/web.nim index 878f4e5..9aee143 100644 --- a/src/pon2/app/ide/web.nim +++ b/src/pon2/app/ide/web.nim @@ -12,8 +12,7 @@ import std/[strformat, sugar] import karax/[karax, karaxdsl, kdom, vdom] import ../[ide, key, simulator] import ../simulator/[web] -import - ../../private/app/ide/web/[answer, controller, pagination, settings, share, progress] +import ../../private/app/ide/web/[answer, controller, pagination, settings, progress] # ------------------------------------------------ # Keyboard Handler @@ -48,23 +47,16 @@ const MainSimulatorIdPrefix = "pon2-ide-mainsimulator-" AnswerSimulatorIdPrefix = "pon2-ide-answersimulator-" SettingsIdPrefix = "pon2-ide-settings-" - ShareIdPrefix = "pon2-ide-share-" - AnswerShareIdPrefix = "pon2-ide-share-answer-" proc newIdeNode(self: Ide, id: string): VNode {.inline.} = ## Returns the IDE node without the external section. - let - simulatorNode = self.simulator.newSimulatorNode( - wrapSection = false, id = &"{MainSimulatorIdPrefix}{id}" - ) - settingsId = &"{SettingsIdPrefix}{id}" + let settingsId = &"{SettingsIdPrefix}{id}" result = buildHtml(tdiv(class = "columns is-mobile is-variable is-1")): tdiv(class = "column is-narrow"): - tdiv(class = "block"): - simulatorNode - tdiv(class = "block"): - self.newShareNode(&"{ShareIdPrefix}{id}", false) + self.simulator.newSimulatorNode( + wrapSection = false, id = &"{MainSimulatorIdPrefix}{id}" + ) if self.simulator.mode != Play and self.simulator.kind == Nazo: tdiv(class = "column is-narrow"): section(class = "section"): @@ -80,10 +72,6 @@ proc newIdeNode(self: Ide, id: string): VNode {.inline.} = if self.answerData.pairsPositionsSeq.len > 0: tdiv(class = "block"): self.newAnswerSimulatorNode &"{AnswerSimulatorIdPrefix}{id}" - tdiv(class = "block"): - self.newShareNode(&"{AnswerShareIdPrefix}{id}", true) - tdiv(class = "column is-narrow"): - self.newDisplayNode &"{ShareIdPrefix}{id}" proc newIdeNode*( self: Ide, setKeyHandler = true, wrapSection = true, id = "" diff --git a/src/pon2/app/simulator.nim b/src/pon2/app/simulator.nim index 9d0eb82..3cec23e 100644 --- a/src/pon2/app/simulator.nim +++ b/src/pon2/app/simulator.nim @@ -1,5 +1,10 @@ ## This module implements Puyo Puyo simulators. ## +## Compile Options: +## | Option | Description | Default | +## | -------------------- | ------------------------------ | -------- | +## | `-d:pon2.path=` | URI path of the web simulator. | `/pon2/` | +## when defined(js): ## See also the [backend-specific documentation](./simulator/web.html). ## @@ -75,6 +80,11 @@ type operatingPos: Position editing: SimulatorEditing +const SimulatorUriPath* {.define: "pon2.path".} = "/pon2/" + +static: + doAssert SimulatorUriPath.startsWith '/' + # ------------------------------------------------ # Constructor # ------------------------------------------------ @@ -662,6 +672,29 @@ func toUriQuery*( of Ishikawa, Ips: result = mainQuery +func toUri*(self: Simulator, withPositions = true, fqdn = Pon2): Uri {.inline.} = + ## Returns the URI converted from the simulator. + result = initUri() + result.scheme = "https" + result.hostname = $fqdn + result.query = self.toUriQuery(withPositions, fqdn) + + # path + case fqdn + of Pon2: + result.path = SimulatorUriPath + of Ishikawa, Ips: + let modeChar = + case self.kind + of Regular: + case self.mode + of Play, PlayEditor: 's' + of Edit: 'e' + of View: 'v' + of Nazo: + 'n' + result.path = &"/simu/p{modeChar}.html" + func parseSimulator*(query: string, fqdn: IdeFqdn): Simulator {.inline.} = ## Returns the simulator converted from the URI query. ## If the URI is invalid, `ValueError` is raised. @@ -716,6 +749,60 @@ func parseSimulator*(query: string, fqdn: IdeFqdn): Simulator {.inline.} = of Ishikawa, Ips: result = parsePuyoPuyo[TsuField](query, fqdn).newSimulator Play +func allowedUriPaths(path: string): seq[string] {.inline.} = + ## Returns the allowed paths. + result = @[path] + + if path.endsWith "/index.html": + result.add path.dup(removeSuffix("index.html")) + elif path.endsWith '/': + result.add &"{path}index.html" + +const AllowedSimulatorUriPaths = SimulatorUriPath.allowedUriPaths + +proc parseSimulator*(uri: Uri): Simulator {.inline.} = + ## Returns the simulator converted from the URI. + ## If the URI is invalid, `ValueError` is raised. + var + kind = SimulatorKind.low + mode = SimulatorMode.low + let fqdn: IdeFqdn + case uri.hostname + of $Pon2: + if uri.path notin AllowedSimulatorUriPaths: + raise newException(ValueError, "Invalid simulator: " & $uri) + + fqdn = Pon2 + of $Ishikawa, $Ips: + fqdn = if uri.hostname == $Ishikawa: Ishikawa else: Ips + + # kind, mode + case uri.path + of "/simu/pe.html": + kind = Regular + mode = Edit + of "/simu/ps.html": + kind = Regular + mode = Play + of "/simu/pv.html": + kind = Regular + mode = View + of "/simu/pn.html": + kind = Nazo + mode = Play + else: + result = newSimulator[TsuField]() # HACK: dummy to suppress warning + raise newException(ValueError, "Invalid simulator: " & $uri) + else: + fqdn = Pon2 # HACK: dummy to compile + result = newSimulator[TsuField]() # HACK: dummy to suppress warning + raise newException(ValueError, "Invalid simulator: " & $uri) + + result = uri.query.parseSimulator fqdn + if fqdn in {Ishikawa, Ips}: + result.kind = kind + result.mode = mode + # ------------------------------------------------ # Keyboard Operation # ------------------------------------------------ diff --git a/src/pon2/app/simulator/web.nim b/src/pon2/app/simulator/web.nim index e7efd77..30c70a2 100644 --- a/src/pon2/app/simulator/web.nim +++ b/src/pon2/app/simulator/web.nim @@ -22,19 +22,25 @@ import palette, requirement, select, + share, ] # ------------------------------------------------ # Node # ------------------------------------------------ -const ReqIdPrefix = "pon2-simulator-req-" +const + ReqIdPrefix = "pon2-simulator-req-" + ShareIdPrefix = "pon2-simulator-share-" -proc newSimulatorNode(self: Simulator, id: string, hideSelect: bool): VNode {.inline.} = +proc newSimulatorNode(self: Simulator, id: string, isAnswer: bool): VNode {.inline.} = ## Returns the node without the external section. - buildHtml(tdiv): - tdiv(class = "block"): - self.newRequirementNode(id = &"{ReqIdPrefix}{id}") + let shareId = &"{ShareIdPrefix}{id}" + + result = buildHtml(tdiv): + if self.kind == Nazo: + tdiv(class = "block"): + self.newRequirementNode &"{ReqIdPrefix}{id}" tdiv(class = "block"): tdiv(class = "columns is-mobile is-variable is-1"): tdiv(class = "column is-narrow"): @@ -46,9 +52,11 @@ proc newSimulatorNode(self: Simulator, id: string, hideSelect: bool): VNode {.in if self.mode != Edit: tdiv(class = "block"): self.newMessagesNode - if not hideSelect and self.mode != Play: + if not isAnswer and self.mode != Play: tdiv(class = "block"): self.newSelectNode + tdiv(class = "block"): + self.newShareNode(shareId, isAnswer) if self.mode != Edit: tdiv(class = "column is-narrow"): tdiv(class = "block"): @@ -61,12 +69,13 @@ proc newSimulatorNode(self: Simulator, id: string, hideSelect: bool): VNode {.in self.newPaletteNode tdiv(class = "block"): self.newPairsNode + self.newDisplayNode shareId proc newSimulatorNode*( - self: Simulator, wrapSection = true, id = "", hideSelect = false + self: Simulator, wrapSection = true, id = "", isAnswer = false ): VNode {.inline.} = ## Returns the simulator node. - let node = self.newSimulatorNode(id, hideSelect) + let node = self.newSimulatorNode(id, isAnswer) if wrapSection: result = buildHtml(section(class = "section")): diff --git a/src/pon2/private/app/ide/web/answer.nim b/src/pon2/private/app/ide/web/answer.nim index 1be5405..0a26a9c 100644 --- a/src/pon2/private/app/ide/web/answer.nim +++ b/src/pon2/private/app/ide/web/answer.nim @@ -14,4 +14,4 @@ import ../../../../app/simulator/[web] proc newAnswerSimulatorNode*(ide: Ide, id: string): VNode {.inline.} = ## Returns the answer simulator node. - ide.answerSimulator.newSimulatorNode(wrapSection = false, id = id, hideSelect = true) + ide.answerSimulator.newSimulatorNode(wrapSection = false, id = id, isAnswer = true) diff --git a/src/pon2/private/app/simulator/common.nim b/src/pon2/private/app/simulator/common.nim index 0c2333c..ce91ffb 100644 --- a/src/pon2/private/app/simulator/common.nim +++ b/src/pon2/private/app/simulator/common.nim @@ -8,7 +8,8 @@ {.experimental: "strictFuncs".} {.experimental: "views".} -import std/[deques, sugar] +import std/[deques, strformat, sugar, uri] +import ../../[misc] import ../../../app/[color, nazopuyo, simulator] import ../../../core/[ @@ -187,3 +188,29 @@ func getMessages*( result.noticeGarbages[notice].dec count - ShownNoticeGarbageCount if count >= ShownNoticeGarbageCount: break + +# ------------------------------------------------ +# X +# ------------------------------------------------ + +const RuleDescriptions: array[Rule, string] = ["通", "すいちゅう"] + +func toXLink*(simulator: Simulator, withPositions: bool): Uri {.inline.} = + ## Returns the URI for posting to X. + let simUri = simulator.toUri withPositions + + case simulator.kind + of Nazo: + simulator.nazoPuyoWrapBeforeMoves.get: + let + ruleStr = + if simulator.rule == Tsu: + "" + else: + RuleDescriptions[simulator.rule] + moveCount = wrappedNazoPuyo.moveCount + reqStr = $wrappedNazoPuyo.requirement + + result = initXLink(&"{ruleStr}{moveCount}手・{reqStr}", "なぞぷよ", simUri) + of Regular: + result = initXLink(uri = simUri) diff --git a/src/pon2/private/app/simulator/web/requirement.nim b/src/pon2/private/app/simulator/web/requirement.nim index 5ee526e..2d6b0b5 100644 --- a/src/pon2/private/app/simulator/web/requirement.nim +++ b/src/pon2/private/app/simulator/web/requirement.nim @@ -53,14 +53,10 @@ func newNumberHandler(simulator: Simulator, id: string): () -> void = (simulator.requirementNumber = id.kstring.getSelectedNumberIndex.RequirementNumber) proc newRequirementNode*( - simulator: Simulator, displayMode = false, id: string + simulator: Simulator, id: string, displayMode = false ): VNode {.inline.} = ## Returns the requirement node. ## `id` is shared with other node-creating procedures and need to be unique. - if simulator.kind == Regular: - return buildHtml(tdiv): - discard - let req = simulator.nazoPuyoWrap.get: wrappedNazoPuyo.requirement diff --git a/src/pon2/private/app/ide/web/share.nim b/src/pon2/private/app/simulator/web/share.nim similarity index 69% rename from src/pon2/private/app/ide/web/share.nim rename to src/pon2/private/app/simulator/web/share.nim index 30cb87c..0ea9499 100644 --- a/src/pon2/private/app/ide/web/share.nim +++ b/src/pon2/private/app/simulator/web/share.nim @@ -10,20 +10,20 @@ import std/[strformat, sugar, uri] import karax/[karax, karaxdsl, kbase, kdom, vdom, vstyles] +import ./[field, messages, pairs, requirement] import ../[common] import ../../[misc] -import ../../simulator/web/[field, messages, pairs, requirement] -import ../../../../app/[ide, simulator] +import ../../../../app/[simulator] const - UrlCopyButtonIdPrefix = "pon2-ide-share-url-" - PosUrlCopyButtonIdPrefix = "pon2-ide-share-pos-url-" - EditorUrlCopyButtonIdPrefix = "pon2-ide-share-editor-url-" - EditorPosUrlCopyButtonIdPrefix = "pon2-ide-share-editor-pos-url-" + UrlCopyButtonIdPrefix = "pon2-simulator-share-url-" + PosUrlCopyButtonIdPrefix = "pon2-simulator-share-pos-url-" + EditorUrlCopyButtonIdPrefix = "pon2-simulator-share-editor-url-" + EditorPosUrlCopyButtonIdPrefix = "pon2-simulator-share-editor-pos-url-" - DisplayDivIdPrefix = "pon2-ide-share-display-" - DisplayPairDivIdPrefix = "pon2-ide-share-display-pair-" - DisplayPairPosDivIdPrefix = "pon2-ide-share-display-pair-pos-" + DisplayDivIdPrefix = "pon2-simulator-share-display-" + DisplayPairDivIdPrefix = "pon2-simulator-share-display-pair-" + DisplayPairPosDivIdPrefix = "pon2-simulator-share-display-pair-pos-" proc downloadDisplayImage( id: kstring @@ -57,15 +57,17 @@ func newDownloadHandler(id: string, withPositions: bool): () -> void = result = handler proc toPlayUri( - ide: Ide, useAnswer: bool, withPositions: bool, editor = false + simulator: Simulator, withPositions: bool, editor = false ): Uri {.inline.} = ## Returns the IDE URI for playing. - let ide2 = (if useAnswer: ide.answerSimulator else: ide.simulator).copy.newIde - ide2.simulator.mode = if editor: PlayEditor else: Play + let sim = simulator.copy + sim.mode = if editor: PlayEditor else: Play - result = ide2.toUri withPositions + result = sim.toUri withPositions -proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} = +proc newShareNode*( + simulator: Simulator, id: string, onlyEditorButton: bool +): VNode {.inline.} = ## Returns the share node. let urlCopyButtonId = &"{UrlCopyButtonIdPrefix}{id}" @@ -73,10 +75,8 @@ proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} = editorUrlCopyButtonId = &"{EditorUrlCopyButtonIdPrefix}{id}" editorPosUrlCopyButtonId = &"{EditorPosUrlCopyButtonIdPrefix}{id}" - sim = if useAnswer: ide.answerSimulator else: ide.simulator - result = buildHtml(tdiv): - if not useAnswer: + if not onlyEditorButton: tdiv(class = "block"): span(class = "icon"): italic(class = "fa-brands fa-x-twitter") @@ -87,14 +87,14 @@ proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} = class = "button is-size-7", target = "_blank", rel = "noopener noreferrer", - href = kstring $ide.toXlink(withPositions = false), + href = kstring $simulator.toXlink(withPositions = false), ): text "操作無" a( class = "button is-size-7", target = "_blank", rel = "noopener noreferrer", - href = kstring $ide.toXlink(withPositions = true), + href = kstring $simulator.toXlink(withPositions = true), ): text "操作有" tdiv(class = "block"): @@ -111,8 +111,7 @@ proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} = id = urlCopyButtonId.kstring, class = "button is-size-7", onclick = newCopyButtonHandler( - () => $ide.toPlayUri(useAnswer = useAnswer, withPositions = false), - urlCopyButtonId, + () => $simulator.toPlayUri(withPositions = false), urlCopyButtonId ), ): text "操作無" @@ -120,12 +119,11 @@ proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} = id = posUrlCopyButtonId.kstring, class = "button is-size-7", onclick = newCopyButtonHandler( - () => $ide.toPlayUri(useAnswer = useAnswer, withPositions = true), - posUrlCopyButtonId, + () => $simulator.toPlayUri(withPositions = true), posUrlCopyButtonId ), ): text "操作有" - if sim.mode != SimulatorMode.Play: + if simulator.mode != SimulatorMode.Play: tdiv(class = "block"): text "編集者URLコピー" tdiv(class = "buttons"): @@ -133,10 +131,7 @@ proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} = id = editorUrlCopyButtonId.kstring, class = "button is-size-7", onclick = newCopyButtonHandler( - () => - $ide.toPlayUri( - useAnswer = useAnswer, withPositions = false, editor = true - ), + () => $simulator.toPlayUri(withPositions = false, editor = true), editorUrlCopyButtonId, ), ): @@ -145,16 +140,13 @@ proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} = id = editorPosUrlCopyButtonId.kstring, class = "button is-size-7", onclick = newCopyButtonHandler( - () => - $ide.toPlayUri( - useAnswer = useAnswer, withPositions = true, editor = true - ), + () => $simulator.toPlayUri(withPositions = true, editor = true), editorPosUrlCopyButtonId, ), ): text "操作有" -proc newDisplayNode*(ide: Ide, id: string): VNode {.inline.} = +proc newDisplayNode*(simulator: Simulator, id: string): VNode {.inline.} = ## Returns the display node for image saving. ## `id` should be the same as the one used in `newShareNode`. buildHtml( @@ -163,20 +155,21 @@ proc newDisplayNode*(ide: Ide, id: string): VNode {.inline.} = style = style(StyleAttr.display, kstring"none"), ) ): - tdiv(class = "block"): - ide.simulator.newRequirementNode(true, id) + if simulator.kind == Nazo: + tdiv(class = "block"): + simulator.newRequirementNode(id, true) tdiv(class = "block"): tdiv(class = "columns is-mobile is-variable is-1"): tdiv(class = "column is-narrow"): tdiv(class = "block"): - ide.simulator.newFieldNode(true) + simulator.newFieldNode(true) tdiv(class = "block"): - ide.simulator.newMessagesNode + simulator.newMessagesNode tdiv(id = kstring &"{DisplayPairDivIdPrefix}{id}", class = "column is-narrow"): tdiv(class = "block"): - ide.simulator.newPairsNode(true, false) + simulator.newPairsNode(true, false) tdiv( id = kstring &"{DisplayPairPosDivIdPrefix}{id}", class = "column is-narrow" ): tdiv(class = "block"): - ide.simulator.newPairsNode(true, true) + simulator.newPairsNode(true, true) diff --git a/src/pon2/private/main/web.nim b/src/pon2/private/main/web.nim index 16e422e..8661e99 100644 --- a/src/pon2/private/main/web.nim +++ b/src/pon2/private/main/web.nim @@ -128,7 +128,7 @@ else: else: import std/[uri] import karax/[karax] - import ../../app/[ide] + import ../../app/[ide, simulator] import ../../app/ide/[web] # ------------------------------------------------ @@ -164,7 +164,7 @@ else: var uri = initUri() uri.scheme = "https" uri.hostname = $Pon2 - uri.path = IdeUriPath + uri.path = SimulatorUriPath uri.query = query try: diff --git a/tests/ide/main.nim b/tests/ide/main.nim index 75896e9..0ea7188 100644 --- a/tests/ide/main.nim +++ b/tests/ide/main.nim @@ -30,8 +30,8 @@ proc main*() = mainQuery = "field=t-rrb&pairs=rgby12&req-kind=0&req-color=7" mainQueryNoPos = "field=t-rrb&pairs=rgby&req-kind=0&req-color=7" kindModeQuery = "kind=n&mode=e" - uriStr = &"https://{Pon2}{IdeUriPath}?{kindModeQuery}&{mainQuery}" - uriStrNoPos = &"https://{Pon2}{IdeUriPath}?{kindModeQuery}&{mainQueryNoPos}" + uriStr = &"https://{Pon2}{SimulatorUriPath}?{kindModeQuery}&{mainQuery}" + uriStrNoPos = &"https://{Pon2}{SimulatorUriPath}?{kindModeQuery}&{mainQueryNoPos}" ide = uriStr.parseUri.parseIde nazo = parseNazoPuyo[TsuField](mainQuery, Pon2) diff --git a/tests/simulator/main.nim b/tests/simulator/main.nim index ed5de7b..492fcd4 100644 --- a/tests/simulator/main.nim +++ b/tests/simulator/main.nim @@ -5,7 +5,7 @@ {.experimental: "strictFuncs".} {.experimental: "views".} -import std/[deques, importutils, options, sequtils, strformat, unittest] +import std/[deques, importutils, options, sequtils, strformat, unittest, uri] import ../../src/pon2/app/[nazopuyo, simulator] import ../../src/pon2/core/[ @@ -583,7 +583,7 @@ rg|""" # Simulator <-> URI # ------------------------------------------------ - # toUriQuery, parseSimulator + # toUriQuery, toUri, parseSimulator block: let mainQuery = "field=t-rrb&pairs=rgby12&req-kind=0&req-color=7" @@ -602,3 +602,10 @@ rg|""" check simulator.toUriQuery(withPositions = false) == queryNoPos check simulator.toUriQuery(withPositions = true, fqdn = Ishikawa) == "1b_c1Ec__270" + + let + simUri = parseUri &"https://{Pon2}{SimulatorUriPath}?{query}" + simUriNoPos = parseUri &"https://{Pon2}{SimulatorUriPath}?{queryNoPos}" + + check simulator.toUri(withPositions = true) == simUri + check simulator.toUri(withPositions = false) == simUriNoPos