Skip to content

Commit 6aee631

Browse files
author
Keisuke Izumiya
committed
[other] fix simulator
1 parent 10d5e87 commit 6aee631

File tree

7 files changed

+49
-42
lines changed

7 files changed

+49
-42
lines changed

src/pon2/app/color.nim

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,12 @@ const
2525
# ------------------------------------------------
2626

2727
when defined(js):
28-
import std/[strutils]
28+
import std/[strformat, strutils]
2929
import karax/[kbase]
3030

3131
func toColorCode*(color: Color): kstring {.inline.} =
3232
## Returns the color code (including '#') converted from the color.
33-
kstring join [
34-
"#",
35-
color.red.toHex(2),
36-
color.green.toHex(2),
37-
color.blue.toHex(2),
38-
color.alpha.toHex(2),
39-
]
33+
kstring &"#{color.red.toHex 2}{color.green.toHex 2}{color.blue.toHex 2}{color.alpha.toHex 2}"
4034
else:
4135
import nigui
4236

src/pon2/app/ide/web.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ proc newIdeNode(self: Ide, id: string): VNode {.inline.} =
6565
simulatorNode
6666
tdiv(class = "block"):
6767
self.newShareNode(&"{ShareIdPrefix}{id}", false)
68-
if self.simulator.mode in {PlayEditor, Edit} and self.simulator.kind == Nazo:
68+
if self.simulator.mode != Play and self.simulator.kind == Nazo:
6969
tdiv(class = "column is-narrow"):
7070
section(class = "section"):
7171
tdiv(class = "block"):
@@ -82,6 +82,8 @@ proc newIdeNode(self: Ide, id: string): VNode {.inline.} =
8282
self.newAnswerSimulatorNode &"{AnswerSimulatorIdPrefix}{id}"
8383
tdiv(class = "block"):
8484
self.newShareNode(&"{AnswerShareIdPrefix}{id}", true)
85+
tdiv(class = "column is-narrow"):
86+
self.newDisplayNode &"{ShareIdPrefix}{id}"
8587
8688
proc newIdeNode*(
8789
self: Ide, setKeyHandler = true, wrapSection = true, id = ""

src/pon2/app/simulator/web.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import
3030

3131
const ReqIdPrefix = "pon2-simulator-req-"
3232

33-
proc newSimulatorNode(self: Simulator, id: string): VNode {.inline.} =
33+
proc newSimulatorNode(self: Simulator, id: string, hideSelect: bool): VNode {.inline.} =
3434
## Returns the node without the external section.
3535
buildHtml(tdiv):
3636
tdiv(class = "block"):
@@ -46,7 +46,7 @@ proc newSimulatorNode(self: Simulator, id: string): VNode {.inline.} =
4646
if self.mode != Edit:
4747
tdiv(class = "block"):
4848
self.newMessagesNode
49-
if self.mode in {PlayEditor, Edit}:
49+
if not hideSelect and self.mode != Play:
5050
tdiv(class = "block"):
5151
self.newSelectNode
5252
if self.mode != Edit:
@@ -62,9 +62,11 @@ proc newSimulatorNode(self: Simulator, id: string): VNode {.inline.} =
6262
tdiv(class = "block"):
6363
self.newPairsNode
6464

65-
proc newSimulatorNode*(self: Simulator, wrapSection = true, id = ""): VNode {.inline.} =
65+
proc newSimulatorNode*(
66+
self: Simulator, wrapSection = true, id = "", hideSelect = false
67+
): VNode {.inline.} =
6668
## Returns the simulator node.
67-
let node = self.newSimulatorNode id
69+
let node = self.newSimulatorNode(id, hideSelect)
6870

6971
if wrapSection:
7072
result = buildHtml(section(class = "section")):

src/pon2/private/app/ide/web/answer.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ import ../../../../app/simulator/[web]
1414

1515
proc newAnswerSimulatorNode*(ide: Ide, id: string): VNode {.inline.} =
1616
## Returns the answer simulator node.
17-
ide.answerSimulator.newSimulatorNode(wrapSection = false, id = id)
17+
ide.answerSimulator.newSimulatorNode(wrapSection = false, id = id, hideSelect = true)

src/pon2/private/app/ide/web/share.nim

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ proc downloadDisplayImage(
3232
&"""
3333
const div = document.getElementById('{DisplayDivIdPrefix}' + (#));
3434
div.style.display = 'block';
35-
html2canvas(div).then((canvas) => {{
35+
html2canvas(div, {{scale: 3}}).then((canvas) => {{
3636
div.style.display = 'none';
3737
3838
const element = document.createElement('a');
@@ -76,7 +76,7 @@ proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} =
7676
sim = if useAnswer: ide.answerSimulator else: ide.simulator
7777

7878
result = buildHtml(tdiv):
79-
if sim.mode != View:
79+
if not useAnswer:
8080
tdiv(class = "block"):
8181
span(class = "icon"):
8282
italic(class = "fa-brands fa-x-twitter")
@@ -153,24 +153,30 @@ proc newShareNode*(ide: Ide, id: string, useAnswer: bool): VNode {.inline.} =
153153
),
154154
):
155155
text "操作有"
156+
157+
proc newDisplayNode*(ide: Ide, id: string): VNode {.inline.} =
158+
## Returns the display node for image saving.
159+
## `id` should be the same as the one used in `newShareNode`.
160+
buildHtml(
156161
tdiv(
157162
id = kstring &"{DisplayDivIdPrefix}{id}",
158163
style = style(StyleAttr.display, kstring"none"),
159-
):
160-
tdiv(class = "block"):
161-
sim.newRequirementNode(true, id)
162-
tdiv(class = "block"):
163-
tdiv(class = "columns is-mobile is-variable is-1"):
164-
tdiv(class = "column is-narrow"):
165-
tdiv(class = "block"):
166-
sim.newFieldNode(true)
167-
tdiv(class = "block"):
168-
sim.newMessagesNode
169-
tdiv(id = kstring &"{DisplayPairDivIdPrefix}{id}", class = "column is-narrow"):
170-
tdiv(class = "block"):
171-
sim.newPairsNode(true, false)
172-
tdiv(
173-
id = kstring &"{DisplayPairPosDivIdPrefix}{id}", class = "column is-narrow"
174-
):
175-
tdiv(class = "block"):
176-
sim.newPairsNode(true, true)
164+
)
165+
):
166+
tdiv(class = "block"):
167+
ide.simulator.newRequirementNode(true, id)
168+
tdiv(class = "block"):
169+
tdiv(class = "columns is-mobile is-variable is-1"):
170+
tdiv(class = "column is-narrow"):
171+
tdiv(class = "block"):
172+
ide.simulator.newFieldNode(true)
173+
tdiv(class = "block"):
174+
ide.simulator.newMessagesNode
175+
tdiv(id = kstring &"{DisplayPairDivIdPrefix}{id}", class = "column is-narrow"):
176+
tdiv(class = "block"):
177+
ide.simulator.newPairsNode(true, false)
178+
tdiv(
179+
id = kstring &"{DisplayPairPosDivIdPrefix}{id}", class = "column is-narrow"
180+
):
181+
tdiv(class = "block"):
182+
ide.simulator.newPairsNode(true, true)

src/pon2/private/app/simulator/web/select.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ proc newSelectNode*(simulator: Simulator): VNode {.inline.} =
2323
playEditorButtonClass =
2424
if simulator.mode == PlayEditor: SelectedClass else: NotSelectedClass
2525
editButtonClass = if simulator.mode == Edit: SelectedClass else: NotSelectedClass
26+
viewButtonClass = if simulator.mode == View: SelectedClass else: NotSelectedClass
2627

2728
tsuButtonClass = if simulator.rule == Tsu: SelectedClass else: NotSelectedClass
2829
waterButtonClass = if simulator.rule == Water: SelectedClass else: NotSelectedClass
@@ -37,6 +38,9 @@ proc newSelectNode*(simulator: Simulator): VNode {.inline.} =
3738
button(class = editButtonClass, onclick = () => (simulator.mode = Edit)):
3839
span(class = "icon"):
3940
italic(class = "fa-solid fa-pen-to-square")
41+
button(class = viewButtonClass, onclick = () => (simulator.mode = View)):
42+
span(class = "icon"):
43+
italic(class = "fa-solid fa-circle-play")
4044
if simulator.mode == Edit:
4145
tdiv(class = "buttons has-addons"):
4246
button(class = tsuButtonClass, onclick = () => (simulator.rule = Tsu)):

tests/color/main.nim

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import std/[unittest]
99
import ../../src/pon2/app/[color]
1010

1111
when defined(js):
12+
import std/[strformat, strutils]
1213
import karax/[kbase]
1314
else:
1415
import nigui
@@ -21,14 +22,12 @@ proc main*() =
2122
when defined(js):
2223
# toColorCode
2324
block:
24-
check WaterColor.toColorCode == "#87CEFAFF"
25+
let c = WaterColor
26+
check c.toColorCode ==
27+
kstring &"#{c.red.toHex 2}{c.green.toHex 2}{c.blue.toHex 2}{c.alpha.toHex 2}"
2528
else:
2629
# toNiguiColor
2730
block:
28-
check WaterColor.toNiguiColor ==
29-
nigui.Color(
30-
red: WaterColor.red,
31-
green: WaterColor.green,
32-
blue: WaterColor.blue,
33-
alpha: WaterColor.alpha,
34-
)
31+
let c = WaterColor
32+
check c.toNiguiColor ==
33+
nigui.Color(red: c.red, green: c.green, blue: c.blue, alpha: c.alpha)

0 commit comments

Comments
 (0)