This commit is contained in:
2024-12-16 16:51:46 +02:00
parent e264956831
commit 96fbfb60e8
16 changed files with 250 additions and 295 deletions
+31 -30
View File
@@ -8,21 +8,21 @@ import path from 'path';
const collection = 'assets';
/**
* Game objects manager
* Game objects manager, контролен клас за управление на игрови обекти
*/
class GameObjectsManager{
name = 'gameObject';
/**
* Plugin initializer
* @param {App} app The Application
* Plugin initializer, инициализация на плъгин
* @param {App} app The Application, обект приложение
*/
init(app){
const {db, config} = app;
/**
* Gets last asset Id from database
* @returns {Number} Last Asset Id
* Gets last asset Id from database, намира последния пореден идентификатор на обект в базата от данни
* @returns {Number} Last Asset Id, последен (най-голям) идентификатор
*/
this.getLastId = async function(){
let ag = await db.aggregate(collection, [
@@ -39,9 +39,9 @@ class GameObjectsManager{
}
/**
* Creates a game object
* @param {Context} ctx Request context
* @param {GameObject} data Asset data
* Creates a game object, създаване на игрови обект
* @param {Context} ctx Request context, контекст на заявката
* @param {GameObject} data Asset data, данни за игровия обект
*/
this.create = async function(ctx, data){
data.id = (await this.getLastId()) + 1;
@@ -55,9 +55,9 @@ class GameObjectsManager{
}
/**
* Retrieves game object from database
* @param {Number} id Game object ID
* @returns {GameObject} The game object
* Retrieves game object from database, прочитане на обект от базата от данни
* @param {Number} id Game object ID, идентификатор на обекта
* @returns {GameObject} The game object, игрови обект
*/
this.read = async function(id){
id = parseInt(id);
@@ -65,9 +65,9 @@ class GameObjectsManager{
}
/**
* Updates game object into the database
* @param {Context} ctx Request context
* @param {GameObject} data Game object
* Updates game object into the database, обновяване на игрови обект
* @param {Context} ctx Request context, контекст на заявката
* @param {GameObject} data Game object, данни за игровия обект
*/
this.update = async function(ctx, data){
data.id = parseInt(data.id);
@@ -85,8 +85,8 @@ class GameObjectsManager{
}
/**
* Removes game object from database
* @param {Number} id Game object ID
* Removes game object from database, изтриване на игрови обект от базата от данни
* @param {Number} id Game object ID, идентификатор на игровия обект
*/
this.remove = async function(id){
id = parseInt(id);
@@ -94,9 +94,9 @@ class GameObjectsManager{
}
/**
* Assigns a file to a game object
* @param {GameObject} object Game object
* @param {File} tmpFile A file
* Assigns a file to a game object, закачване на файл към игрови обект
* @param {GameObject} object Game object, игрови обект
* @param {File} tmpFile A file, файл
*/
this.addFile = async function(object, tmpFile){
let i = tmpFile;
@@ -124,9 +124,9 @@ class GameObjectsManager{
}
/**
* Assigns a thumbnail to a game object
* @param {GameObject} object Game object
* @param {File} thumbSrc A thumbnail
* Assigns a thumbnail to a game object, закачане на представително изображение към игрови обект
* @param {GameObject} object Game object, игрови обект
* @param {File} thumbSrc A thumbnail, представително изображение
*/
this.addThumb = async function(object, thumbSrc){
let dest = `${config.fs.repo}/thumb/${object.id}.webp`;
@@ -135,9 +135,9 @@ class GameObjectsManager{
}
/**
* Returns list of GameObjects
* @param {Object} query Query to DB
* @returns {GameObject[]} Array of game objects
* Returns list of GameObjects, търсене в игровите обекти по зададени критерии
* @param {Object} query Query to DB, критерии - заявка към базата от данни
* @returns {GameObject[]} Array of game objects, масив от игрови обекти
*/
this.list = async function(query){
return await db.list(collection, {
@@ -148,8 +148,8 @@ class GameObjectsManager{
}
/**
* Class starter
* @param {App} app The application
* Class starter, стартиране на класа
* @param {App} app The application, базова апликация
*/
async start(app){
@@ -158,22 +158,23 @@ class GameObjectsManager{
/**
* GameObject entity, can be: panorama picture, 3d environment, 3d object, 2d object (picture), a player (3d), audio or video asset
* Игрови обект, може да бъде панорамна снимка, триизмерна среда, обект или играч, двуизмерен обект, аудио или видео актив
*/
class GameObject {
/**
* Game object name
* Game object name, име на игровия обект
* @type string
*/
name = null;
/**
* Game object type
* Game object type, тип на игровия обект
* @type string
*/
type = null;
/**
* Associated file
* Associated file, асоцииран файл
* @type File
*/
file = null;
+20 -20
View File
@@ -6,51 +6,51 @@ class GamesManager{
name = 'games';
/**
* Class initializer
* @param {App} app Class initializer
* Class initializer, инициализация на плъгин
* @param {App} app Class initializer, основна апликация
*/
init(app){
const {db} = app;
/**
* Creates a new game definition
* @param {Context} ctx Request context
* @param {Game} data the game description
* Creates a new game definition, създаване на нова игрова дефиниция
* @param {Context} ctx Request context, контекст на заявката
* @param {Game} data the game description, дефиниция на играта
*/
this.create = async function(ctx, data){
}
/**
* Reads game definition by ID
* @param {Number} id game ID
* @returns {Game} the game
* Reads game definition by ID, извличане на игрова дефиниция от базата от данни по подаден идентификатор
* @param {Number} id game ID, идентификатор на играта
* @returns {Game} the game, игрова дефиниция
*/
this.read = async function(id){
}
/**
* Updates game definition
* @param {Context} ctx Request context
* @param {Game} data the game description
* Updates game definition, обновяване на игрова дефиниция
* @param {Context} ctx Request context, контекст на заявката
* @param {Game} data the game description, игрова дефиниция
*/
this.update = async function(ctx, data){
}
/**
* Removes game by ID
* @param {Number} id game definition ID
* Removes game by ID, изтриване на игрова дефиниция по зададен идентификатор
* @param {Number} id game definition ID, идентификатор на игровата дефиниция
*/
this.remove = async function(id){
}
/**
* Returns a set of games by given criteria
* @param {Query} query criteria
* @returns {Game[]} Array of games
* Returns a set of games by given criteria, търсене в игровите дефиниции по зададени критерии
* @param {Query} query criteria, критерии за търсене - заявка към базата от данни
* @returns {Game[]} Array of games, масив от игрови дефиниции
*/
this.list = async function(query){
@@ -60,7 +60,7 @@ class GamesManager{
/**
* Class starter
* @param {App} app The application
* @param {App} app The application, основна апликация
*/
async start(app){
@@ -68,17 +68,17 @@ class GamesManager{
}
/**
* Game entity
* Game entity, игрова дефиниция - елемент
*/
class Game {
/**
* Game name
* Game name, име на играта
* @type {string}
*/
name = null;
/**
* Game scenario
* Game scenario, сценарий на играта
* @type { Scenario }
*/
scenario = null;
+19 -19
View File
@@ -1,29 +1,29 @@
/**
* Rules manager class
* Rules manager class, контролен клас за управление на игрови правила
*/
class RulesManager{
name = 'rules';
/**
* Class initializer
* @param {App} app Class initializer
* Class initializer, инициализация на плъгин
* @param {App} app Class initializer, основна апликация
*/
init(app){
const {db} = app;
/**
* Creates a new rule
* @param {Context} ctx Request context
* @param {Rule} data the rule
* Creates a new rule, създаване на ново правило
* @param {Context} ctx Request context, контекст на заявката
* @param {Rule} data the rule, данни за правилото
*/
this.create = async function(ctx, data){
}
/**
* Reads rule by ID
* @param {Number} id rule ID
* Reads rule by ID, извличане на игрово правило от базата от данни по подаден идентификатор
* @param {Number} id rule ID, идентификатор на правило
* @returns {Rule}
*/
this.read = async function(id){
@@ -31,25 +31,25 @@ class RulesManager{
}
/**
* Updates rule
* @param {Context} ctx Request context
* @param {Rule} data the rule
* Updates rule, обновяване на игрово правило
* @param {Context} ctx Request context, контекст на заявката
* @param {Rule} data the rule, данни за правилото
*/
this.update = async function(ctx, data){
}
/**
* Removes rule by ID
* @param {Number} id rule ID
* Removes rule by ID, изтриване на игрово правило по подаден идентификатор
* @param {Number} id rule ID, идентификатор на правилото
*/
this.remove = async function(id){
}
/**
* Returns a set of rules by given criteria
* @param {Query} query criteria
* Returns a set of rules by given criteria, търсене в игровите правила по зададени критерии
* @param {Query} query criteria, критерии, заявка към базата от данни
* @returns {Rule[]}
*/
this.list = async function(query){
@@ -60,7 +60,7 @@ class RulesManager{
/**
* Class starter
* @param {App} app The application
* @param {App} app The application, основна апликация
*/
async start(app){
@@ -68,17 +68,17 @@ class RulesManager{
}
/**
* Rule entity
* Rule entity, игрово правило - елемент
*/
class Rule {
/**
* Rule name
* Rule name, име на правилото
* @type string
*/
name = null;
/**
* Rule definition
* Rule definition, дефиниция на правилото
* @type Object
*/
name = null;
+37 -37
View File
@@ -1,29 +1,29 @@
/**
* Scenarios manager class
* Scenarios manager class, контролен клас за управление на игрови сценарии
*/
class ScenariosManager{
name = 'scenarios';
/**
* Class initializer
* @param {App} app Class initializer
* Class initializer, инициализация
* @param {App} app Class initializer, основна апликация
*/
init(app){
const {db} = app;
/**
* Creates a new scenario
* @param {Context} ctx Request context
* @param {Scenario} data the scenario
* Creates a new scenario, създаване на нов сценарий
* @param {Context} ctx Request context, контекст на заявката
* @param {Scenario} data the scenario, данни за сценария
*/
this.create = async function(ctx, data){
}
/**
* Reads scenario by ID
* @param {Number} id scenario ID
* Reads scenario by ID, извличане на сценарий по подаден идентификатор
* @param {Number} id scenario ID, идентификатор
* @returns {Scenario}
*/
this.read = async function(id){
@@ -31,8 +31,8 @@ class ScenariosManager{
}
/**
* Updates scenario
* @param {Context} ctx Request context
* Updates scenario, обновяване на сценарий
* @param {Context} ctx Request context, контекст на заявката
* @param {Scenario} data the scenario
*/
this.update = async function(ctx, data){
@@ -40,16 +40,16 @@ class ScenariosManager{
}
/**
* Removes scenario by ID
* @param {Number} id scenario ID
* Removes scenario by ID, изтриване на сценарий по подаден идентификатор
* @param {Number} id scenario ID, идентификатор на сценарий
*/
this.remove = async function(id){
}
/**
* Returns a set of scenarios by given criteria
* @param {Query} query criteria
* Returns a set of scenarios by given criteria, търсене в игровите сценарии по зададени критерии
* @param {Query} query criteria, критерии - заявка към базата от данни
* @returns {Scenario[]}
*/
this.list = async function(query){
@@ -59,8 +59,8 @@ class ScenariosManager{
}
/**
* Class starter
* @param {App} app The application
* Class starter, стартиране на класа
* @param {App} app The application, основна апликация
*/
async start(app){
@@ -68,121 +68,121 @@ class ScenariosManager{
}
/**
* Scenario entity
* Scenario entity, обект - сценарий
*/
class Scenario {
/**
* Scenario name
* Scenario name, име на сценария
* @type {string}
*/
name = null;
/**
* Scenario levels
* Scenario levels, нива
* @type {Level[]}
*/
levels = [];
}
/**
* Game scenario level
* Game scenario level, ниво на игрови сценарий
*/
class Level {
/**
* Scenario name
* Level name, име на нивото
* @type {string}
*/
name = null;
/**
* Active objects
* Active objects, активни обекти
* @type {LevelObject[]}
*/
activeObjects = []
}
/**
* Game object associated to a level
* Game object associated to a level, игрови обекти, асоциирани към дадено ниво
*/
class LevelObject {
/**
* Associated game object
* Associated game object, асоцииран игрови обект
* @type {GameObject}
*/
gameObject = null;
/**
* Available actions
* Available actions, възможни действия
* @type {GameAction}
*/
actions = []
}
/**
* Action associated to game object
* Action associated to game object, действие, асоциирано към игрови обект
*/
class GameAction {
/**
* Scenario name
* Action name, име на действието
* @type {string}
*/
name = null;
/**
* Scenario name
* Action description, описание на действието
* @type {string}
*/
description = null;
/**
* Associated inventory item
* Associated inventory item, асоцииран инвентар
* @type {InventoryItem}
*/
inventoryItem = null;
/**
* Available outcomes from the action
* Available outcomes from the action, възможни резултати от действието
* @type {GameActionResult}
*/
results = []
}
/**
* Result associated to game action
* Result associated to game action, резултати, асоциирани към дадено игрово действие
*/
class GameActionResult{
/**
* Applied rules to the specific result
* Applied rules to the specific result, приложени игрови правила към даден резултат
* @type Rule[]
*/
rules = []
/**
* Scenario name
* Result name, име на резултата
* @type string
*/
name = null;
/**
* Scenario name
* Result description, описание на резултата
* @type string
*/
description = null;
}
/**
* Inventory item required to perform specific action
* Inventory item required to perform specific action, инвентар необходим за изпълнението на определено действие
*/
class InventoryItem {
/**
* Scenario name
* Inventory item name, име на елемент от инвентара
* @type string
*/
name = null;
/**
* Scenario name
* Inventory item description, описание на елемент от инвентара
* @type string
*/
description = null;