{"id":341949,"date":"2022-11-30T15:00:31","date_gmt":"2022-11-30T15:00:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341949"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341949","title":{"rendered":"<span>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 Entity Component System \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 python<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438<\/h2>\n<p>Entity Component System (ECS) &#8212; \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0432\u0438\u0434\u0435\u043e\u0438\u0433\u0440, \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<h3>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b (Components)<\/h3>\n<p>\u0412\u0441\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0445 \u0441\u0445\u043e\u0436\u0438\u0435 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u043c\u043e\u0436\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0451\u043c\u043a\u0438\u0445 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u041d\u0438\u043a\u043e\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0440\u0430\u0437\u0434\u0443\u0442\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0430\u043b\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.  <\/p>\n<h3>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 (Entity)<\/h3>\n<p>\u0421\u0430\u043c\u0438 \u0436\u0435 \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438) \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0438 \u0447\u0435\u043c \u0438\u043d\u044b\u043c \u043a\u0430\u043a \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043a\u0440\u043e\u043c\u0435 id \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u043e \u044d\u0442\u043e\u043c\u0443 id \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0430\u043c\u044b\u043c\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u043e\u0442 \u0441\u0442\u0440\u0435\u043b\u044b \u0434\u043e \u043c\u0438\u0448\u0435\u043d\u0438 \u0438 \u043c\u043d\u043e\u0433\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e. \u0414\u043e\u0431\u0430\u0432\u0438\u0432 \u0438\u043b\u0438 \u0443\u0431\u0440\u0430\u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. <\/p>\n<h3>\u0421\u0438\u0441\u0442\u0435\u043c\u044b (Systems)<\/h3>\n<p>\u0412\u043e\u0442 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u043e\u043d\u0438 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 &#8212; \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b, \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u0439 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u0421\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u043e\u0447\u0435\u0440\u0451\u0434\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u0438\u0445.<\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0430 \u043e\u0442 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0438 \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a \u043d\u0435\u0439 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f.<\/p>\n<p>\u0422\u0430\u043a, \u0441\u043e\u0437\u0434\u0430\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b), \u043d\u0430 \u043d\u0435\u0451 \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u0434\u0432\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b (\u0440\u0435\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e). <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u044b. \u0423\u0431\u0440\u0430\u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u043c\u0435\u0440\u0442\u0438, \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u0447\u0435\u0437\u0430\u0442\u044c \u0438 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435\u043c, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u0435\u0436\u0434\u0435. <\/p>\n<h3>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/h3>\n<h4>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0417\u0430 \u0441\u0447\u0451\u0442 \u043f\u043b\u043e\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0448\u0438\u0440\u043e\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 python \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0442\u044b \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0430 \u0432 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 &#8212; \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 \u0446\u0435\u043b\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. <\/p>\n<h4>\u0420\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0430, \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043d\u0435 \u043b\u043e\u043c\u0430\u044f \u0441\u0442\u0430\u0440\u044b\u0435.<\/p>\n<h4>\u0413\u0438\u0431\u043a\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0451\u043d \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0438 \u044d\u0442\u043e \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.<\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0443 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 ECS, \u0430 \u043d\u0435 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 EntityComponentSystem \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u0430\u0445. \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u043e\u043d \u0441\u043d\u0430\u0431\u0436\u0451\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<details class=\"spoiler\">\n<summary>ecs_types.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from dataclasses import dataclass from typing import Any, Type  EntityId = str Component = object   @dataclass class StoredSystem:     variables: dict[str, Any]     components: dict[str, Type[Component]]  # key is argument name     has_entity_id_argument: bool     has_ecs_argument: bool<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>unique_id.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439, \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 uuid class UniqueIdGenerator:     last_id = 0      @classmethod     def generate_id(cls) -> str:         cls.last_id += 1         return str(cls.last_id)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>entity_component_system.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import inspect from typing import Callable, Type, Any, Iterator  from ecs_types import EntityId, Component, StoredSystem from unique_id import UniqueIdGenerator   class EntityComponentSystem:     def __init__(self, on_create: Callable[[EntityId, list[Component]], None] = None,                  on_remove: Callable[[EntityId], None] = None):         \"\"\"         :param on_create:         \u0425\u0443\u043a, \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438,         \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439          :param on_remove:         \u0425\u0443\u043a, \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u0435\u0440\u0435\u0434 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438         \"\"\"          # \u0417\u0434\u0435\u0441\u044c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u043e\u0442 \u043d\u0438\u0445 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430\u043c\u0438         self._systems: dict[Callable, StoredSystem] = {}         # \u041f\u043e \u0442\u0438\u043f\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0441\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043f\u043e \u043a\u043b\u044e\u0447\u0430\u043c entity_id         self._components: dict[Type[Component], dict[EntityId, Component]] = {}         self._entities: list[EntityId] = []         self._vars = {}         self.on_create = on_create         self.on_remove = on_remove      def _unsafe_get_component(self, entity_id: EntityId, component_class: Type[Component]) -> Component:         \"\"\"         \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441 \u0442\u0438\u043f\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 component_class         \u041a\u0438\u0434\u0430\u0435\u0442 KeyError \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430         \"\"\"          return self._components[component_class][entity_id]      def init_component(self, component_class: Type[Component]) -> None:         \"\"\"         \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0434\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439         \"\"\"          self._components[component_class] = {}      def add_variable(self, variable_name: str, variable_value: Any) -> None:         \"\"\"         \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0414\u0430\u043b\u0435\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439.         \"\"\"          self._vars[variable_name] = variable_value      def init_system(self, system: Callable):         \"\"\"         \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0415\u0441\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 - \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u0435\u0451 \u0432 add_variable \u0434\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.          \u0412\u043d\u0435\u0448\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b (ecs: EntityComponentSystem \u0438 entity_id: EntityId) \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442\u0441\u044f         \u0447\u0435\u0440\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.          \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 dummy_health: HealthComponent).         \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u043e \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e.         \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b         \"\"\"          stored_system = StoredSystem(             components={},             variables={},             has_entity_id_argument=False,             has_ecs_argument=False         )          # \u0427\u0435\u0440\u0435\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043e\u043d\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442.         # \u0421\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432 StoredSystem \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0430\u0434\u0440.         system_params = inspect.signature(system).parameters         for param_name, param in system_params.items():             if param_name == 'entity_id':  # \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 entity_id \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432                 stored_system.has_entity_id_argument = True              elif param_name == 'ecs':  # \u0421\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 ecs. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439                 stored_system.has_ecs_argument = True              elif param.annotation in self._components:                 stored_system.components[param_name] = param.annotation              elif param_name in self._vars:                 stored_system.variables[param_name] = self._vars[param_name]              else:                 raise Exception(f'Wrong argument: {param_name}')          self._systems[system] = stored_system      def create_entity(self, components: list[Component], entity_id=None) -> EntityId:         \"\"\"         \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432         \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 entity_id \u043d\u043e \u043e\u043d \u043e\u0431\u044f\u0437\u0430\u043d \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c         \"\"\"          if entity_id is None:             entity_id = UniqueIdGenerator.generate_id()         else:             assert entity_id not in self._entities, f\"Entity with id {entity_id} already exists\"          for component in components:             self._components[component.__class__][entity_id] = component         self._entities.append(entity_id)          if self.on_create:             self.on_create(entity_id, components)          return entity_id      def get_entity_ids_with_components(self, *component_classes) -> set[EntityId]:         \"\"\"         \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 entity_id \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432 component_classes         \"\"\"          if not component_classes:             return set(self._entities)          # \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 - \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u043a\u0430\u0436\u0434\u044b\u043c \u0438\u0437 \u043d\u0438\u0445         # \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 entity_id \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430         entities = set.intersection(*[set(self._components[component_class].keys())                                       for component_class in component_classes])         return entities      def get_entities_with_components(self, *component_classes) -> Iterator[tuple[EntityId, list[Component]]]:         \"\"\"         \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 entity_id \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438         \"\"\"          for entity_id in self.get_entity_ids_with_components(*component_classes):             components = tuple(self._unsafe_get_component(entity_id, component_class)                                for component_class in component_classes)             yield entity_id, components      def update(self) -> None:         \"\"\"         \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.         \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432 \u0438\u0433\u0440\u043e\u0432\u043e\u043c \u0446\u0438\u043a\u043b\u0435.         \"\"\"          for system_function, system in self._systems.items():             for entity_id in self.get_entity_ids_with_components(*system.components.values()):                 special_args = {}                 if system.has_ecs_argument:                     special_args['ecs'] = self                 if system.has_entity_id_argument:                     special_args['entity_id'] = entity_id                                      # \u0421\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432                 required_components_arguments = {param: self._unsafe_get_component(entity_id, component_name) for                                                  param, component_name in                                                  system.components.items()}                                  system_function(**(required_components_arguments | system.variables | special_args))      def remove_entity(self, entity_id: EntityId):         \"\"\"         \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c         \"\"\"                  if self.on_remove is not None:             self.on_remove(entity_id)         for components in self._components.values():             components.pop(entity_id, None)         self._entities.remove(entity_id)      def get_component(self, entity_id: EntityId, component_class: Type[Component]):         \"\"\"         :return         \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441 \u0442\u0438\u043f\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 component_class         \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 None \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430         \"\"\"                  return self._components[component_class].get(entity_id, None)      def get_components(self, entity_id: EntityId, component_classes):         \"\"\"         :return         \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438.         \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 None \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432         \"\"\"                  try:             return tuple(self._unsafe_get_component(entity_id, component_class)                           for component_class in component_classes)         except KeyError:             return None<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0438\u043c\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438 &#8212; \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<details class=\"spoiler\">\n<summary>entity_component_system.pyi<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from typing import Protocol, Type, TypeVar, overload, Callable, Any, Iterator  from ecs_types import EntityId, Component, StoredSystem  Component1 = TypeVar('Component1') Component2 = TypeVar('Component2') Component3 = TypeVar('Component3') Component4 = TypeVar('Component4')   class EntityComponentSystem(Protocol):     _systems: dict[Callable, StoredSystem]     _components: dict[Type[Component], dict[EntityId, Component]]     _entities: list[EntityId]      _vars: dict[str, Any]     on_create: Callable[[EntityId, list[Component]], None]     on_remove: Callable[[EntityId], None]      def __init__(self, on_create: Callable[[EntityId, list[Component]], None] = None,                  on_remove: Callable[[EntityId], None] = None): ...      @overload     def _unsafe_get_component(self, entity_id: str, component_class: Type[Component1]) -> Component1: ...      @overload     def init_component(self, component_class: Type[Component1]) -> None: ...      @overload     def init_system(self, system: Callable): ...      @overload     def add_variable(self, variable_name: str, variable_value: Any) -> None: ...      @overload     def create_entity(self, components: list[Component1], entity_id=None) -> EntityId: ...      @overload     def get_entity_ids_with_components(self, class1: Type[Component1]) -> set[EntityId]: ...      @overload     def get_entity_ids_with_components(self, class1: Type[Component1], class2: Type[Component2]) -> set[EntityId]: ...      @overload     def get_entity_ids_with_components(self, class1: Type[Component1], class2: Type[Component2], class3: Type[Component3]) -> set[EntityId]: ...      @overload     def get_entity_ids_with_components(self, class1: Type[Component1], class2: Type[Component2], class3: Type[Component3], class4: Type[Component4]) -> set[EntityId]: ...      @overload     def get_entities_with_components(self, class1: Type[Component1]) -> Iterator[tuple[         EntityId, tuple[Component1]]]: ...      @overload     def get_entities_with_components(self, class1: Type[Component1], class2: Type[Component2]) -> Iterator[         tuple[             EntityId, tuple[Component1, Component2]]]: ...      @overload     def get_entities_with_components(self, class1: Type[Component1], class2: Type[Component2], class3: Type[Component3]) -> \\     Iterator[tuple[EntityId, tuple[Component1, Component2, Component3]]]: ...      @overload     def get_entities_with_components(self, class1: Type[Component1], class2: Type[Component2], class3: Type[Component3], class4: Type[Component4]) -> Iterator[tuple[         EntityId, tuple[Component1, Component2, Component3, Component4]]]: ...      def update(self) -> None: ...      def remove_entity(self, entity_id: EntityId): ...      def get_component(self, entity_id: EntityId, component_class: Type[Component1]) -> Component1: ...      @overload     def get_components(self, entity_id: EntityId,                        component_classes: tuple[Type[Component1]]) -> tuple[Component1]: ...      @overload     def get_components(self, entity_id: EntityId,                        component_classes: tuple[Type[Component1], Type[Component2]]) -> tuple[         Component1, Component2]: ...      @overload     def get_components(self, entity_id: EntityId,                        component_classes: tuple[Type[Component1], Type[Component2], Type[Component3]]) -> tuple[         Component1, Component2, Component3]: ... <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ECS \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u0435\u043b\u0443, \u0432\u0440\u0435\u0437\u0430\u044e\u0449\u0443\u044e\u0441\u044f \u0432 \u043c\u0438\u0448\u0435\u043d\u044c.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">from entity_component_system import EntityComponentSystem from ecs_types import EntityId from dataclasses import dataclass, field import math<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/docs.python.org\/3\/library\/dataclasses.html\" rel=\"noopener noreferrer nofollow\">\u0434\u0430\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b<\/a>. \u0412\u0435\u0434\u044c \u0432 python \u044d\u0442\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u0443 \u0441\u0442\u0440\u0435\u043b\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u044b:<\/p>\n<pre><code class=\"python\">@dataclass(slots=True) class ColliderComponent:     x: float     y: float     radius: float      def distance(self, other: 'ColliderComponent'):         return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)      def is_intersecting(self, other: 'ColliderComponent'):         return self.distance(other) &lt;= self.radius + other.radius<\/code><\/pre>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0448\u0435\u0439 \u0441\u0442\u0440\u0435\u043b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f:<\/p>\n<pre><code class=\"python\">@dataclass(slots=True) class VelocityComponent:     speed_x: float = 0.0     speed_y: float = 0.0<\/code><\/pre>\n<p>\u0415\u0449\u0451 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e \u043e\u043d\u0430 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u0440\u0438 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435, \u043d\u0430\u043d\u043e\u0441\u044f \u0443\u0440\u043e\u043d:<\/p>\n<pre><code class=\"python\">@dataclass(slots=True) class DamageOnContactComponent:     damage: int     die_on_contact: bool = True<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u0441\u0442\u0440\u0435\u043b\u0443. \u0423\u043a\u0430\u0436\u0435\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0435\u0451 \u0441\u043e\u0431\u0440\u0430\u0442\u044c, \u0437\u043d\u0430\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438:<\/p>\n<pre><code class=\"python\">def create_arrow(x: float, y: float, angle: int, speed: float, damage: int):     arrow_radius = 15     return [         ColliderComponent(x, y, arrow_radius),         # \u0412\u0435\u043a\u0442\u043e\u0440 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0438 \u0443\u0433\u043b\u0430 \u043f\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0441\u0442\u0440\u0435\u043b\u0443.         VelocityComponent(             speed_x=math.cos(math.radians(angle)) * speed,             speed_y=math.sin(math.radians(angle)) * speed         ),         DamageOnContactComponent(damage)     ]<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043c\u0438\u0448\u0435\u043d\u0438. \u0414\u043b\u044f \u0435\u0451 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f. \u041e\u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"python\">@dataclass(slots=True) class HealthComponent:     max_amount: int     amount: int = field(default=None)      def __post_init__(self):         if self.amount is None:             self.amount = self.max_amount      def apply_damage(self, damage: int):         self.amount = max(0, self.amount - damage)<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0436\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043c\u0438\u0448\u0435\u043d\u0435\u0439:<\/p>\n<pre><code class=\"python\">def create_dummy(x: float, y: float, health: int):     dummy_radius = 50     return [         ColliderComponent(x, y, dummy_radius),         HealthComponent(             max_amount=health,         )     ]<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u043c\u044b \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0432\u0441\u0451 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u041e\u043f\u0438\u0448\u0435\u043c, \u0447\u0442\u043e \u0441 \u043d\u0438\u043c\u0438 \u043d\u0430\u0434\u043e \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u0417\u0430\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0430\u0448\u0443 \u0441\u0442\u0440\u0435\u043b\u0443 \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0449\u0443\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"python\">def velocity_system(velocity: VelocityComponent, collider: ColliderComponent):     collider.x += velocity.speed_x     collider.y += velocity.speed_y<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448\u0430 \u0441\u0442\u0440\u0435\u043b\u0430 \u043c\u043e\u0436\u0435\u0442 \u043b\u0435\u0442\u0430\u0442\u044c. \u0421\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u043f\u0440\u0438\u043a\u043e\u0441\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0441 \u043c\u0438\u0448\u0435\u043d\u044c\u044e:<\/p>\n<pre><code class=\"python\">def damage_on_contact_system(entity_id: EntityId,                              # \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c EntityComponentSystem \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0435\u043b\u044b \u043f\u0440\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u0438                              ecs: EntityComponentSystem,                              damage_on_contact: DamageOnContactComponent,                              collider: ColliderComponent):     # \u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c \u0441 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 \u0438 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435\u043c     for enemy_id, (enemy_health, enemy_collider) in ecs.get_entities_with_components(HealthComponent,                                                                                      ColliderComponent):         # \u041f\u0443\u0441\u0442\u044c \u0441\u0442\u0440\u0435\u043b\u0430 \u0438 \u043d\u0435 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435\u043c, \u043d\u043e \u044d\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0443\u0436\u043d\u0430 \u043d\u0430 \u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439 \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0433\u0434\u0435 \u043e\u043d\u043e \u0435\u0441\u0442\u044c                if entity_id == enemy_id:             continue                  if collider.is_intersecting(enemy_collider):             enemy_health.apply_damage(damage_on_contact.damage)             if damage_on_contact.die_on_contact:                 ecs.remove_entity(entity_id)                 return<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u043c \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u043f\u0430\u043b\u043e \u0434\u043e \u043d\u0443\u043b\u044f:<\/p>\n<pre><code class=\"python\">def death_system(entity_id: EntityId, health: HealthComponent, ecs: EntityComponentSystem):     if health.amount &lt;= 0:         ecs.remove_entity(entity_id)<\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446 \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043d\u044b, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b:<\/p>\n<pre><code class=\"python\">ecs = EntityComponentSystem()  ecs.init_component(ColliderComponent) ecs.init_component(VelocityComponent) ecs.init_component(DamageOnContactComponent) ecs.init_component(HealthComponent)  ecs.init_system(velocity_system) ecs.init_system(damage_on_contact_system) ecs.init_system(death_system)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0438\u0448\u0435\u043d\u044c \u0438 \u0441\u0442\u0440\u0435\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0451 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442:<\/p>\n<pre><code class=\"python\">ecs.create_entity(create_arrow(x=0, y=0, angle=45, speed=2, damage=50)) ecs.create_entity(create_arrow(x=500, y=0, angle=135, speed=1.5, damage=50)) ecs.create_entity(create_arrow(x=0, y=500, angle=-45, speed=1.1, damage=50)) ecs.create_entity(create_arrow(x=500, y=500, angle=-135, speed=1, damage=50)) ecs.create_entity(create_dummy(x=250, y=250, health=200))<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0439 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/www.pygame.org\/\" rel=\"noopener noreferrer nofollow\">pygame<\/a> (\u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/web.archive.org\/web\/*\/https:\/\/www.pygame.org\/\" rel=\"noopener noreferrer nofollow\">\u0432\u0435\u0431 \u0430\u0440\u0445\u0438\u0432<\/a>):<\/p>\n<pre><code class=\"python\">import pygame from pygame import Color from pygame.time import Clock  screen = pygame.display.set_mode((500, 500)) running = True clock = Clock()  while running:     for event in pygame.event.get():          if event.type == pygame.QUIT:             running = False      ecs.update()      screen.fill((93, 161, 48))     for entity_id, (collider,) in ecs.get_entities_with_components(ColliderComponent):         pygame.draw.circle(screen, Color('gray'), (collider.x, collider.y), collider.radius)      pygame.display.flip()     clock.tick(60)<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412\u0435\u0441\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043e\u0431\u0440\u0430\u043d \u0432 <a href=\"https:\/\/gist.github.com\/RustyGuard\/1de7d9925f755d105df8ed53bb9c9bfe\" rel=\"noopener noreferrer nofollow\">\u0433\u0438\u0441\u0442\u0435<\/a>. <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u043c\u043d\u043e\u0439 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u043d\u043b\u0430\u0439\u043d \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 pygame. \u0415\u0441\u043b\u0438 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0442\u043e \u044f \u043d\u0430\u043f\u0438\u0448\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u0435\u0451 \u0440\u0430\u0431\u043e\u0442\u0443. <\/p>\n<p>\u0417\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0441\u043f\u0430\u0441\u0438\u0431\u043e <a class=\"mention\" href=\"\/users\/alexandrovroman\">@AlexandrovRoman<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/702598\/\"> https:\/\/habr.com\/ru\/post\/702598\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438<\/h2>\n<p>Entity Component System (ECS) &#8212; \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0432\u0438\u0434\u0435\u043e\u0438\u0433\u0440, \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<h3>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b (Components)<\/h3>\n<p>\u0412\u0441\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0445 \u0441\u0445\u043e\u0436\u0438\u0435 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u043c\u043e\u0436\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0451\u043c\u043a\u0438\u0445 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u041d\u0438\u043a\u043e\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0440\u0430\u0437\u0434\u0443\u0442\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0430\u043b\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.  <\/p>\n<h3>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 (Entity)<\/h3>\n<p>\u0421\u0430\u043c\u0438 \u0436\u0435 \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438) \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0438 \u0447\u0435\u043c \u0438\u043d\u044b\u043c \u043a\u0430\u043a \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043a\u0440\u043e\u043c\u0435 id \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u043e \u044d\u0442\u043e\u043c\u0443 id \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0430\u043c\u044b\u043c\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u043e\u0442 \u0441\u0442\u0440\u0435\u043b\u044b \u0434\u043e \u043c\u0438\u0448\u0435\u043d\u0438 \u0438 \u043c\u043d\u043e\u0433\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e. \u0414\u043e\u0431\u0430\u0432\u0438\u0432 \u0438\u043b\u0438 \u0443\u0431\u0440\u0430\u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. <\/p>\n<h3>\u0421\u0438\u0441\u0442\u0435\u043c\u044b (Systems)<\/h3>\n<p>\u0412\u043e\u0442 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u043e\u043d\u0438 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 &#8212; \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b, \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u0439 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u0421\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u043e\u0447\u0435\u0440\u0451\u0434\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u0438\u0445.<\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0430 \u043e\u0442 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0438 \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a \u043d\u0435\u0439 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f.<\/p>\n<p>\u0422\u0430\u043a, \u0441\u043e\u0437\u0434\u0430\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b), \u043d\u0430 \u043d\u0435\u0451 \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u0434\u0432\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b (\u0440\u0435\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e). <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u044b. \u0423\u0431\u0440\u0430\u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u043c\u0435\u0440\u0442\u0438, \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u0447\u0435\u0437\u0430\u0442\u044c \u0438 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435\u043c, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u0435\u0436\u0434\u0435. <\/p>\n<h3>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/h3>\n<h4>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0417\u0430 \u0441\u0447\u0451\u0442 \u043f\u043b\u043e\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0448\u0438\u0440\u043e\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 python \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0442\u044b \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0430 \u0432 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 &#8212; \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 \u0446\u0435\u043b\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. <\/p>\n<h4>\u0420\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0430, \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043d\u0435 \u043b\u043e\u043c\u0430\u044f \u0441\u0442\u0430\u0440\u044b\u0435.<\/p>\n<h4>\u0413\u0438\u0431\u043a\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0451\u043d \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0438 \u044d\u0442\u043e \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.<\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0443 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 ECS, \u0430 \u043d\u0435 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 EntityComponentSystem \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u0430\u0445. \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u043e\u043d \u0441\u043d\u0430\u0431\u0436\u0451\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<details class=\"spoiler\">\n<summary>ecs_types.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from dataclasses import dataclass from typing import Any, Type  EntityId = str Component = object   @dataclass class StoredSystem:     variables: dict[str, Any]     components: dict[str, Type[Component]]  # key is argument name     has_entity_id_argument: bool     has_ecs_argument: bool<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>unique_id.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439, \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 uuid class UniqueIdGenerator:     last_id = 0      @classmethod     def generate_id(cls) -> str:         cls.last_id += 1         return str(cls.last_id)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>entity_component_system.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import inspect from typing import Callable, Type, Any, Iterator  from ecs_types import EntityId, Component, StoredSystem from unique_id import UniqueIdGenerator   class EntityComponentSystem:     def __init__(self, on_create: Callable[[EntityId, list[Component]], None] = None,                  on_remove: Callable[[EntityId], None] = None):         \"\"\"         :param on_create:         \u0425\u0443\u043a, \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438,         \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439          :param on_remove:         \u0425\u0443\u043a, \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u0435\u0440\u0435\u0434 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438         \"\"\"          # \u0417\u0434\u0435\u0441\u044c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u043e\u0442 \u043d\u0438\u0445 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430\u043c\u0438         self._systems: dict[Callable, StoredSystem] = {}         # \u041f\u043e \u0442\u0438\u043f\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0441\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043f\u043e \u043a\u043b\u044e\u0447\u0430\u043c entity_id         self._components: dict[Type[Component], dict[EntityId, Component]] = {}         self._entities: list[EntityId] = []         self._vars = {}         self.on_create = on_create         self.on_remove = on_remove      def _unsafe_get_component(self, entity_id: EntityId, component_class: Type[Component]) -> Component:         \"\"\"         \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441 \u0442\u0438\u043f\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 component_class         \u041a\u0438\u0434\u0430\u0435\u0442 KeyError \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430         \"\"\"          return self._components[component_class][entity_id]      def init_component(self, component_class: Type[Component]) -> None:         \"\"\"         \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0434\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439         \"\"\"          self._components[component_class] = {}      def add_variable(self, variable_name: str, variable_value: Any) -> None:         \"\"\"         \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0414\u0430\u043b\u0435\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439.         \"\"\"          self._vars[variable_name] = variable_value      def init_system(self, system: Callable):         \"\"\"         \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0415\u0441\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 - \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u0435\u0451 \u0432 add_variable \u0434\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.          \u0412\u043d\u0435\u0448\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b (ecs: EntityComponentSystem \u0438 entity_id: EntityId) \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442\u0441\u044f         \u0447\u0435\u0440\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.          \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 dummy_health: HealthComponent).         \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u043e \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e.         \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b         \"\"\"          stored_system = StoredSystem(             components={},             variables={},             has_entity_id_argument=False,             has_ecs_argument=False         )          # \u0427\u0435\u0440\u0435\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043e\u043d\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442.         # \u0421\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432 StoredSystem \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0430\u0434\u0440.         system_params = inspect.signature(system).parameters         for param_name, param in system_params.items():             if param_name == 'entity_id':  # \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 entity_id \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432                 stored_system.has_entity_id_argument = True              elif param_name == 'ecs':  # \u0421\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 ecs. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439                 stored_system.has_ecs_argument = True              elif param.annotation in self._components:                 stored_system.components[param_name] = param.annotation              elif param_name in self._vars:                 stored_system.variables[param_name] = self._vars[param_name]              else:                 raise Exception(f'Wrong argument: {param_name}')          self._systems[system] = stored_system      def create_entity(self, components: list[Component], entity_id=None) -> EntityId:         \"\"\"         \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432         \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 entity_id \u043d\u043e \u043e\u043d \u043e\u0431\u044f\u0437\u0430\u043d \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c         \"\"\"          if entity_id is None:             entity_id = UniqueIdGenerator.generate_id()         else:             assert entity_id not in self._entities, f\"Entity with id {entity_id} already exists\"          for component in components:             self._components[component.__class__][entity_id] = component         self._entities.append(entity_id)          if self.on_create:             self.on_create(entity_id, components)          return entity_id      def get_entity_ids_with_components(self, *component_classes) -> set[EntityId]:         \"\"\"         \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 entity_id \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432 component_classes         \"\"\"          if not component_classes:             return set(self._entities)          # \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 - \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u043a\u0430\u0436\u0434\u044b\u043c \u0438\u0437 \u043d\u0438\u0445         # \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 entity_id \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430         entities = set.intersection(*[set(self._components[component_class].keys())                                       for component_class in component_classes])         return entities      def get_entities_with_components(self, *component_classes) -> Iterator[tuple[EntityId, list[Component]]]:         \"\"\"         \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 entity_id \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438         \"\"\"          for entity_id in self.get_entity_ids_with_components(*component_classes):             components = tuple(self._unsafe_get_component(entity_id, component_class)                                for component_class in component_classes)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-341949","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341949","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=341949"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341949\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}