Warning: session_start(): open(/var/lib/php/sessions/sess_2bh6krcddv064rit0bhqkh7mbu, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
module ShowRandomColor > DynModule {
RGB color;
S myGuess, yourName;
bool voiceMode = true; // voice input & output
transient double maxDiff = 0.25; // max difference to assume it's a similar color
transient JPanel colorPanel;
transient JTextField tfYourName;
transient JButton btnSave;
transient Pair closestColor;
enhanceFrame {
onInternalFrameDeactivated(f/JInternalFrame, r {
dm_hideYesPopupForComponent(btnSave)
});
}
visualize {
if (color == null) setField(color := makeRandomColor());
dm_onTopInput_q(voidfunc(S s) {
//if (!dm_isActiveModule(module())) ret with print("not active");
if (!voiceMode) ret;
JComponent popup = dm_generalMap_get('yesPopup);
if (match_vbar("okay|ok", s) || matchStart("yes|absolutely|correct", s)) {
if (isShowing(popup) && getOpt(popup, 'forComponent) == btnSave) {
removeFromParent(popup);
simulateClick(btnSave);
}
} else if "no" {
removeFromParent(popup);
if (voiceMode) dm_say("What is it then?");
} else if "new color|next color"
newColor();
else {
print("Got input: " + s);
setField(yourName := s);
dm_showYesToAcceptPopupAbove(btnSave);
if (voiceMode) dm_say(s);
}
});
JComponent theForm = vstackWithSpacing(
makeBold(fontSize(20, liveValueLabel(mapLiveValue(dm_fieldLiveValue('myGuess), S, func(S s) -> S { "I call this color: " + or2(s, "Uh... no idea") + "." })))),
westCenterAndEastWithMargin(fontSize(20, jBoldLabel("How do you call this color?")),
withSideMargin(15, 5, onEnter(tfYourName = focusOnShow(selectAllOnFocus(
fontSize(20, makeBold(dm_centeredFieldTextField('yourName))))), rThread saveName)),
btnSave = jBoldButton("SAVE", rThread saveName)),
withTopMargin(rightAlignedLine(jBoldButton("NEXT ONE PLEASE", rThread newColor))));
ret centerAndSouthWithMargin(
northAndCenterWithMargins(
westAndCenter(dm_fieldCheckBox('voiceMode),
rightAlignedLine(
withLabel("Color Code:", jBoldLiveValueLabel(mapLiveValue(func(O color) -> S { "#" + color }, S, dm_fieldLiveValue('color)))),
jPopDownButton_noText("Choose color...", rThread chooseColor))),
jCenteredSectionWithFont(sansSerifBold(18), " HERE'S A COLOR ", colorPanel = singleColorPanel(toColor(color)))),
withBottomMargin(withSideMargin(15, theForm)));
}
void newColor enter {
setColor(makeRandomColor());
}
void setColor(RGB color) enter {
setField(+color);
closestColor = (Pair) quickImport(dm_callModule(dm_colorNamesModule(), 'getClosestColor, color.getColor()));
setField(myGuess := or(pairA(closestColor), "no idea"));
setField(yourName := myGuess);
changeSingleColorPanel(colorPanel, color.getColor());
selectAll(tfYourName);
if (pairA(closestColor) != null) {
dm_showYesToAcceptPopupAbove(btnSave);
if (voiceMode)
if (pairB(closestColor) <= maxDiff)
dm_say("Is this " + myGuess + "that I see?");
else
dm_say("Master! What is the name of this color?");
}
}
void saveName enter {
setField(yourName := trim(yourName));
if (empty(yourName)) ret;
if (eqic(myGuess, yourName))
dm_infoBoxOrTalk(voiceMode, randomLL(
"Got this one right!",
"I'm good!",
"I'm so smart.",
"Yay!"));
else
dm_infoBoxOrTalk(voiceMode, /*quote(yourName) + (voiceMode ? "," : "...") +*/ " confirmed.");
dm_callModule(dm_colorNamesModule(), 'addColorName, color.getColor(), yourName, "");
newColor();
}
RGB makeRandomColor() { ret randomHSBColor(); }
void chooseColor enter {
inputText("Choose a color (RRGGBB)", color.getHexString(), voidfunc(S s) enter {
setColor(rgbFromHex(s))
});
}
S switchableFields() { ret 'voiceMode; }
}