Browse Source

Lisää pikatyökalut provinnsien ja yhteyksien luomiseen.

master
Linus Vanas 1 month ago
parent
commit
7b1e5e93d9
12 changed files with 321 additions and 52 deletions
  1. +2
    -2
      ReadMe.txt
  2. +58
    -33
      src/client-locale/fi_FI/LC_MESSAGES/veturi_client.po
  3. +8
    -0
      src/veturi-js/MapModule.js
  4. +14
    -11
      src/veturi-js/OrderForm.js
  5. +5
    -1
      src/veturi-js/Panels/InfoPanel.js
  6. +84
    -0
      src/veturi-js/Panels/ToolsPanel.js
  7. +22
    -0
      src/veturi-js/Tool.js
  8. +34
    -0
      src/veturi-js/Tools/CreateConnectionsTool.js
  9. +38
    -0
      src/veturi-js/Tools/CreateProvincesTool.js
  10. +21
    -4
      src/veturi-js/UpdatingObjects/Selection.js
  11. +33
    -1
      src/veturi-js/VeturiUI.js
  12. +2
    -0
      www/index.html

+ 2
- 2
ReadMe.txt View File

@@ -12,8 +12,8 @@ Veturi can be seen as made up of four parts:
1. The client is web application (JS, HTML, CSS) that the players can use
to plan and send their orders.
2. The client/server-interface (PHP) logins and receiving orders
from the client and saving them to the database.
4. The admin-interface (PHP, HTML), used for example to create accounts and edit configurations.
from the client and saving them to the database.
4. The admin-interface (PHP, HTML), used for example to create accounts and edit configurations.
3. The turn simulator (PHP) loads the orders from the database and changes to world according to them.

2. Changelog


+ 58
- 33
src/client-locale/fi_FI/LC_MESSAGES/veturi_client.po View File

@@ -3,13 +3,13 @@
# Copyright (C) 2019 Linus Vanas
# This file is distributed under the same license as Veturi.
#
# Linus Vanas <linus@vanas.fi>, 2019.
# Linus Vanas <linus@vanas.fi>, 2019, 2020.
msgid ""
msgstr ""
"Project-Id-Version: Veturi 0.8 \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-29 21:06+0200\n"
"PO-Revision-Date: 2019-12-29 21:07+0200\n"
"POT-Creation-Date: 2020-01-15 15:31+0200\n"
"PO-Revision-Date: 2020-01-15 15:35+0200\n"
"Last-Translator: Linus Vanas <linus@vanas.fi>\n"
"Language-Team: Finnish <>\n"
"Language: fi\n"
@@ -17,7 +17,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Lokalize 19.12.0\n"
"X-Generator: Lokalize 19.12.1\n"

#: src/veturi-js/Panels/OrdersPanel.js:18
msgid "Submit orders"
@@ -31,80 +31,105 @@ msgstr "Lähetetään käskyjä..."
msgid "You're not logged in!"
msgstr "Et ole kirjautunut sisään!"

#: src/veturi-js/Panels/OrdersPanel.js:50
#: src/veturi-js/Panels/OrdersPanel.js:55
msgid "Give an order"
msgstr "Anna käsky"

#: src/veturi-js/Panels/OrdersPanel.js:57
#: src/veturi-js/Panels/OrdersPanel.js:62
msgid "Create a country"
msgstr "Luo valtio"

#: src/veturi-js/Panels/OrdersPanel.js:62
#: src/veturi-js/Panels/OrdersPanel.js:67
msgid "Create a province"
msgstr "Luo provinssi"

#: src/veturi-js/Panels/OrdersPanel.js:67
#: src/veturi-js/Panels/OrdersPanel.js:72
msgid "Create a connection"
msgstr "Luo yhteys"

#: src/veturi-js/Panels/OrdersPanel.js:94
#: src/veturi-js/Panels/OrdersPanel.js:99
msgid "Orders sent."
msgstr "Käskyt lähetetty."

#: src/veturi-js/Panels/OrdersPanel.js:97
#: src/veturi-js/Panels/OrdersPanel.js:102
msgid "Failed to send orders."
msgstr "Käskyjen lähetys epäonnistui."

#: src/veturi-js/VeturiUI.js:38
#: src/veturi-js/Panels/ToolsPanel.js:31
msgid "Inspect"
msgstr "Tarkastele "

#: src/veturi-js/Panels/ToolsPanel.js:34
msgid "Create provinces"
msgstr "Luo provinsseja"

#: src/veturi-js/Panels/ToolsPanel.js:36
msgid "Province settings"
msgstr "Provinssin asetukset"

#: src/veturi-js/Panels/ToolsPanel.js:37
#: src/veturi-js/Orders/CreateProvinceOrder.js:17
msgid "Country"
msgstr "Valtio"

#: src/veturi-js/Panels/ToolsPanel.js:40
msgid "Create connections"
msgstr "Luo yhteyksiä"

#: src/veturi-js/VeturiUI.js:41
msgid "Settings"
msgstr "Asetukset"

#: src/veturi-js/VeturiUI.js:42
#: src/veturi-js/VeturiUI.js:45
msgid "Orders"
msgstr "Käskyt"

#: src/veturi-js/Orders/CreateCountryOrder.js:13
#: src/veturi-js/VeturiUI.js:70
msgid "Selection info"
msgstr "Kohteen tiedot"

#: src/veturi-js/VeturiUI.js:74
msgid "Tools"
msgstr "Työkalut"

#: src/veturi-js/Orders/CreateCountryOrder.js:15
#, javascript-format
msgid "Create country #%1$d"
msgstr "Luo valtio (%1$d)"

#: src/veturi-js/Orders/CreateCountryOrder.js:14
#: src/veturi-js/Orders/CreateProvinceOrder.js:14
#: src/veturi-js/Orders/CreateCountryOrder.js:16
#: src/veturi-js/Orders/CreateProvinceOrder.js:16
msgid "Name"
msgstr "Nimi"

#: src/veturi-js/Orders/CreateCountryOrder.js:15
#: src/veturi-js/Orders/CreateCountryOrder.js:17
msgid "Color"
msgstr "Väri"

#: src/veturi-js/Orders/CreateConnectionOrder.js:13
#: src/veturi-js/Orders/CreateConnectionOrder.js:16
#, javascript-format
msgid "Create connection #%1$d"
msgstr "Luo yhteys (%1$d)"

#: src/veturi-js/Orders/CreateConnectionOrder.js:14
#: src/veturi-js/Orders/CreateConnectionOrder.js:15
#: src/veturi-js/Orders/CreateConnectionOrder.js:17
#: src/veturi-js/Orders/CreateConnectionOrder.js:18
msgid "Province"
msgstr "Provinssi"

#: src/veturi-js/Orders/CreateProvinceOrder.js:13
#: src/veturi-js/Orders/CreateProvinceOrder.js:15
#, javascript-format
msgid "Create province #%1$d"
msgstr "Luo provinssi (%1$d)"

#: src/veturi-js/Orders/CreateProvinceOrder.js:15
msgid "Country"
msgstr "Valtio"

#: src/veturi-js/Orders/CreateProvinceOrder.js:16
#: src/veturi-js/Orders/CreateProvinceOrder.js:18
msgid "Province x-location"
msgstr "Provinssin x-sijainti"

#: src/veturi-js/Orders/CreateProvinceOrder.js:18
#: src/veturi-js/Orders/CreateProvinceOrder.js:20
msgid "Province y-location"
msgstr "Provinssin y-sijainti"

#: src/veturi-js/UpdatingObjects/Login.js:65 src/veturi-js/LoginForm.js:73
#: src/veturi-js/UpdatingObjects/Login.js:65 src/veturi-js/LoginForm.js:77
msgid "Logging in failed for an unknown reason."
msgstr "Sisäänkirjautuminen epäonnistui."

@@ -118,27 +143,27 @@ msgstr "Käyttäjää %1$s ei ole olemassa."
msgid "The given password does not match the user %1$s."
msgstr "Annettu salasana ei vastaa käyttäjää %1$s."

#: src/veturi-js/OrderForm.js:119
#: src/veturi-js/OrderForm.js:122
msgid "Choose"
msgstr ""
msgstr "Valitse"

#: src/veturi-js/LoginForm.js:16
msgid "Username:"
msgstr "Käyttäjänimi: "

#: src/veturi-js/LoginForm.js:20
#: src/veturi-js/LoginForm.js:21
msgid "Password:"
msgstr "Salasana:"

#: src/veturi-js/LoginForm.js:23
#: src/veturi-js/LoginForm.js:25
msgid "Log in"
msgstr "Kirjaudu sisään"

#: src/veturi-js/LoginForm.js:42
#: src/veturi-js/LoginForm.js:44
msgid "Log out"
msgstr "Kirjaudu ulos"

#: src/veturi-js/LoginForm.js:66
#: src/veturi-js/LoginForm.js:68
#, javascript-format
msgid "Logged in as %1$s."
msgstr "Kirjautuneena: %1$s."


+ 8
- 0
src/veturi-js/MapModule.js View File

@@ -18,6 +18,14 @@ class MapModule
zoomSnap:0.25
}
this.map = L.map("map",opt).fitBounds(bounds);
this.map.on
(
"click",
function(e)
{
VETURI.selection.selectPoint(Math.round(e.latlng.lng),Math.round(e.latlng.lat));
}
)

if (VETURI.config.map_background_image_file)
{


+ 14
- 11
src/veturi-js/OrderForm.js View File

@@ -5,6 +5,7 @@ class OrderForm
{
/**
* Alusta käskyn käyttöliittymäelementit.
* @param {Order} order Käskyolio, johon käyttöliittymäesitys liittyy (jos sellainen on)
*/
constructor(order)
{
@@ -12,20 +13,22 @@ class OrderForm

this.element = document.createElement("details");
this.summaryElement = document.createElement("summary");
this.element.appendChild(this.summaryElement);

this.deleteButton = document.createElement("input");
this.deleteButton.setAttribute("type","button");
this.deleteButton.setAttribute("value","Poista");
this.deleteButton.order = this.order;
this.deleteButton.onclick = function(e)
if (order)
{
this.order.delete();
}

this.element.appendChild(this.summaryElement);
this.element.appendChild(this.deleteButton);
this.deleteButton = document.createElement("input");
this.deleteButton.setAttribute("type","button");
this.deleteButton.setAttribute("value","Poista");
this.deleteButton.order = this.order;
this.deleteButton.onclick = function(e)
{
this.order.delete();
}
this.element.appendChild(this.deleteButton);

VETURI.ui.ordersPanel.addElement(this.element);
VETURI.ui.ordersPanel.addElement(this.element);
}
}

/**


+ 5
- 1
src/veturi-js/Panels/InfoPanel.js View File

@@ -14,7 +14,11 @@ class InfoPanel extends Panel

receiveUpdate()
{
this.showObjectInfo(VETURI.selection.getSelectedObject());
const obj = VETURI.selection.getSelectedObject();
if (obj)
{
this.showObjectInfo(obj);
}
}

/**


+ 84
- 0
src/veturi-js/Panels/ToolsPanel.js View File

@@ -0,0 +1,84 @@
/**
* Paneeli, jolla voi valita käytettävän työkalun.
*/
class ToolsPanel extends Panel
{
/**
* Alusta paneeli.
*/
constructor()
{
super("tools");

this.inspectTool = new Tool();
this.provinceTool = new CreateProvincesTool();
this.connectionTool = new CreateConnectionsTool();

this.selectedTool = this.inspectTool;

this.inputs = new Map();

VETURI.login.subscribeToUpdates(this);
}

receiveUpdate(object)
{
if (object === VETURI.login)
{
this.selectTool(this.inspectTool);
if (VETURI.login.isAdmin())
{
this.addToolChoice(_("Inspect"),this.inspectTool);
this.inputs.get(this.inspectTool).checked = true;

this.addToolChoice(_("Create provinces"),this.provinceTool);
const provinceToolSettings = new OrderForm();
provinceToolSettings.setSummary(_("Province settings"));
provinceToolSettings.addObjectSelectField(_("Country"),this.provinceTool,"getCountry","setCountry","Country");
this.element.appendChild(provinceToolSettings.getElement());

this.addToolChoice(_("Create connections"),this.connectionTool);
}
else
{
while (this.element.firstChild)
{
this.element.removeChild(this.element.firstChild);
}
}
}
}

/**
* Vaihda aktiivista työkalua.
* @param {Tool} tool Työkalu, joka otetaan käyttöön
*/
selectTool(tool)
{
this.selectedTool.deactivate();
this.selectedTool = tool;
this.selectedTool.activate();
}

/**
* Lisää työkaluvaihtoehto paneeliin.
* @param {string} labelText Vaihtoehdon kuvausteksti
* @param {Tool} tool Työkalu, joka vaihtoehdolla valitaan
*/
addToolChoice(labelText,tool)
{
const label = document.createElement("label");
label.innerText = labelText;
const input = document.createElement("input");
input.type = "radio";
input.name = "tool";
input.tool = tool;
input.oninput = function()
{
VETURI.ui.toolsPanel.selectTool(this.tool);
};
this.inputs.set(tool,input);
label.appendChild(input);
this.element.appendChild(label);
}
}

+ 22
- 0
src/veturi-js/Tool.js View File

@@ -0,0 +1,22 @@
/**
* Työkalujen yläluokka.
*/
class Tool
{
/**
* Ota työkalu käyttöön.
*/
activate()
{
VETURI.selection.subscribeToUpdates(this);
}
/**
* Poista työkalu käytöstä.
*/
deactivate()
{
VETURI.selection.unsubscribeFromUpdates(this);
}
receiveUpdate() {}
}


+ 34
- 0
src/veturi-js/Tools/CreateConnectionsTool.js View File

@@ -0,0 +1,34 @@
/**
* Työkalu, jolla voi luoda nopeasti yhteyksiä klikkailemalla provinsseja kartalla.
*/
class CreateConnectionsTool extends Tool
{
receiveUpdate()
{
const obj = VETURI.selection.getSelectedObject();
if (obj && obj.getClass && obj.getClass() === "Province" && obj !== this.firstProvince)
{
if (this.firstProvince)
{
const order = new CreateConnectionOrder();
const connection = order.connection;
connection.setProvinceA(this.firstProvince);
connection.setProvinceB(obj);
order.activate();

this.firstProvince = null;
}
else
{
this.firstProvince = obj;
}
}
}
deactivate()
{
super.deactivate();
this.firstProvince = null;
}
}



+ 38
- 0
src/veturi-js/Tools/CreateProvincesTool.js View File

@@ -0,0 +1,38 @@
/**
* Työkalu, jolla voi luoda nopeasti useita provinsseja karttaa klikkailemalla.
*/
class CreateProvincesTool extends Tool
{
receiveUpdate()
{
const p = VETURI.selection.getSelectedPoint();
if (p)
{
const order = new CreateProvinceOrder({province:p});
const province = order.province;
province.deserialize();
province.activate();
province.setCountry(this.country);
order.activate();
}
}

/**
* @return {number} Luotavien provinssien omistajavaltio
*/
getCountry()
{
return this.country;
}

/**
* Aseta luotavien provinssien omistajavaltio.
* @param {number} country omistajavaltio
*/
setCountry(country)
{
this.country = country;
}
}



+ 21
- 4
src/veturi-js/UpdatingObjects/Selection.js View File

@@ -10,14 +10,23 @@ class Selection extends UpdatingObject
*/
selectObject(object)
{
if (object === this.selectedObject)
{
return;
}
this.selectedPoint = null;
this.selectedObject = object;
this.sendUpdate();
}

/**
* Valitse annettu piste.
* @param {number} x Valittavan pisteen x-koordinaatti
* @param {number} y Valittavan pisteen y-koordinaatti
*/
selectPoint(x,y)
{
this.selectedObject = null;
this.selectedPoint = {x:x,y:y}
this.sendUpdate();
}

/**
* @return {GameObject} Valittuna oleva olio
*/
@@ -25,4 +34,12 @@ class Selection extends UpdatingObject
{
return this.selectedObject;
}

/**
* @return {object} Valittuna oleva piste
*/
getSelectedPoint()
{
return this.selectedPoint;
}
}

+ 33
- 1
src/veturi-js/VeturiUI.js View File

@@ -11,10 +11,12 @@ class VeturiUI
this.settingsPanel = document.getElementById("settings");

this.loginForm = new LoginForm();
this.infoPanel = new InfoPanel();
this.ordersPanel = new OrdersPanel();
this.infoPanel = new InfoPanel();
this.toolsPanel = new ToolsPanel();

this.ordersPanel.hide();
this.toolsPanel.hide();

//Oikea paneelivalitsin

@@ -31,6 +33,7 @@ class VeturiUI
break;
case "settings":
VETURI.ui.settingsPanel.style.display = "";
break;
}
}

@@ -45,6 +48,35 @@ class VeturiUI
this.rightPanelSelect.appendChild(settingsOpt);
this.rightPanelSelect.appendChild(ordersOpt);

//Vasen paneelivalitsin
this.leftPanelSelect = document.getElementById("left-panel-select");
this.leftPanelSelect.oninput = function()
{
VETURI.ui.infoPanel.hide();
VETURI.ui.toolsPanel.hide();

switch(this.value)
{
case "info":
VETURI.ui.infoPanel.show();
break;
case "tools":
VETURI.ui.toolsPanel.show();
break;
}
}

const infoOpt = document.createElement("option");
infoOpt.innerText = _("Selection info");
infoOpt.value = "info";

const toolsOpt = document.createElement("option");
toolsOpt.innerText = _("Tools");
toolsOpt.value = "tools";

this.leftPanelSelect.appendChild(infoOpt);
this.leftPanelSelect.appendChild(toolsOpt);


VETURI.login.subscribeToUpdates(this);
}


+ 2
- 0
www/index.html View File

@@ -25,10 +25,12 @@
</head>
<body>
<header>
<select id="left-panel-select"></select>
<select id="right-panel-select"></select>
</header>
<main>
<div id="info" class="panel"></div>
<div id="tools" class="panel"></div>
<div id="map"></div>
<form id="orders" class="panel"></form>
<div id="settings" class="panel"><form id="login"></form></div>


Loading…
Cancel
Save