| 1544 | } |
| 1545 | |
| 1546 | void ConditionDialog::on_pushLuaExample_clicked() |
| 1547 | { |
| 1548 | QStringList examples = { |
| 1549 | tr("Empty check functions"), |
| 1550 | tr("Village along the way from A to B"), |
| 1551 | }; |
| 1552 | QMap<QString, QString> code = { |
| 1553 | { examples[0], |
| 1554 | "-- check48() is an optional function to check 48-bit seed bases.\n" |
| 1555 | "function check48(seed, at, deps)\n" |
| 1556 | "\t-- Return a position (x, z), or nil to fail the check.\n" |
| 1557 | "\treturn at.x, at.z\n" |
| 1558 | "end\n\n" |
| 1559 | "-- check() determines if the condition passes.\n" |
| 1560 | "-- seed: current seed\n" |
| 1561 | "-- at : {x, z} where the condition is tested\n" |
| 1562 | "-- deps: list of {x, z, id, parent} entries for the dependent\n" |
| 1563 | "-- conditions (i.e. those later in the condition list)\n" |
| 1564 | "function check(seed, at, deps)\n" |
| 1565 | "\t-- Return a position (x, z), or nil to fail the check.\n" |
| 1566 | "\treturn at.x, at.z\n" |
| 1567 | "end" |
| 1568 | }, |
| 1569 | { examples[1], |
| 1570 | "-- Look for a village located between the first two dependent conditions\n" |
| 1571 | "function check(seed, at, deps)\n" |
| 1572 | "\tif #deps < 2 then return nil end -- fail with no dependencies\n" |
| 1573 | "\tlocal a, b = deps[1], deps[2]\n" |
| 1574 | "\tvils = getStructures(Village, a.x, a.z, b.x, b.z)\n" |
| 1575 | "\tif vils == nil then return nil end\n" |
| 1576 | "\tfor i = 1, #vils do\n" |
| 1577 | "\t\t-- calculate the square distance to the line a -> b\n" |
| 1578 | "\t\tlocal dx, dz = b.x - a.x, b.z - a.z\n" |
| 1579 | "\t\tlocal d = dx * (vils[i].z - a.z) - dz * (vils[i].x - a.x)\n" |
| 1580 | "\t\td = (d * d) / (dx * dx + dz * dz + 1)\n" |
| 1581 | "\t\tif d < 32*32 then -- village within 32 blocks of the line\n" |
| 1582 | "\t\t\treturn vils[i].x, vils[i].z\n" |
| 1583 | "\t\tend\n" |
| 1584 | "\tend\n" |
| 1585 | "\treturn nil\n" |
| 1586 | "end" |
| 1587 | }, |
| 1588 | }; |
| 1589 | |
| 1590 | QInputDialog *dialog = new QInputDialog(this); |
| 1591 | dialog->setWindowTitle(tr("Lua examples")); |
| 1592 | dialog->setLabelText(tr("Replace editor content with example:")); |
| 1593 | dialog->setComboBoxItems(examples); |
| 1594 | dialog->setTextValue(examples.first()); |
| 1595 | dialog->setComboBoxEditable(false); |
| 1596 | connect(dialog, &QInputDialog::textValueSelected, [=](const QString &text) { |
| 1597 | if (code.contains(text)) |
| 1598 | ui->textEditLua->document()->setPlainText(code[text]); |
| 1599 | }); |
| 1600 | dialog->show(); |
| 1601 | } |
| 1602 | |
| 1603 | void ConditionDialog::on_comboHeightRange_currentIndexChanged(int index) |
nothing calls this directly
no outgoing calls
no test coverage detected