Skip to content

Commit

Permalink
Merge branch 'master' into credits-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Furrior committed Oct 21, 2023
2 parents ed34257 + 7438113 commit 6785225
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 23 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/auto_translate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Add new translation

on:
workflow_dispatch:
push:
branches: ['translate']

jobs:
add_translation:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
name: 'Add new translation'

steps:
- name: 'Update Branch'
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Installing Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Installing deps
run: |
python -m pip install --upgrade pip
pip install -r ./tools/translator/requirements.txt
- name: Create temporary branch
run: |
git checkout -b translate_tmp
git reset --hard origin/master
- name: Apply existing translation
run: |
git fetch origin translate
git checkout origin/translate -- ./tools/translator/ss220replace.json
./tools/translator/ss220_replacer_linux --prefix=ss220 --root=./../../ --location=./
- name: Apply PR translation
run: |
git cherry-pick -n origin/translate
- name: 'Generate Translation'
run: |
python ./tools/translator/converter.py
[ ! -f ./ss220replace.json ] || mv ./ss220replace.json ./tools/translator/ss220replace.json
git add ./tools/translator/ss220replace.json
- name: 'Push Translation'
run: |
git config --local user.email "[email protected]"
git config --local user.name "SS220Manager"
git commit -m "Generate translation file"
git push -f origin translate_tmp:translate
36 changes: 36 additions & 0 deletions .github/workflows/translate_branch_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Update translate branch

on:
workflow_dispatch:
push:
branches: ['master']

jobs:
add_translation:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: 'Update Branch'
uses: actions/checkout@v4

- name: Create temporary branch
run: |
git branch -f translate_tmp
git checkout translate_tmp
git reset --hard origin/master
- name: Apply existing translation
run: |
git fetch origin translate
git checkout origin/translate -- ./tools/translator/ss220replace.json
./tools/translator/ss220_replacer_linux --prefix=ss220 --root=./../../ --location=./
- name: 'Push Translation'
run: |
git config --local user.email "[email protected]"
git config --local user.name "SS220Manager"
git commit -m "Generate translation file"
git push -u -f origin translate
55 changes: 34 additions & 21 deletions modular_ss220/_modpacks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SUBSYSTEM_DEF(modpacks)
init_order = INIT_ORDER_MODPACKS
flags = SS_NO_FIRE
var/list/loaded_modpacks
var/list/tgui_data

/datum/controller/subsystem/modpacks/Initialize()
var/list/all_modpacks = list()
Expand Down Expand Up @@ -34,30 +35,42 @@ SUBSYSTEM_DEF(modpacks)

load_admins() // To make admins always have modular added verbs

/client/verb/modpacks_list()
/mob/verb/modpacks_list()
set name = "Modpacks List"
set category = "OOC"

if(!mob || !SSmodpacks.initialized)
if(!SSmodpacks.initialized)
return

if(length(SSmodpacks.loaded_modpacks))
. = "<hr><br><center><b><font size = 3>Список модификаций</font></b></center><br><hr><br>"
for(var/datum/modpack/M as anything in SSmodpacks.loaded_modpacks)
if(M.name)
. += "<div class = 'statusDisplay'>"
. += "<center><b>[M.name]</b></center>"

if(M.desc || M.author)
. += "<br>"
if(M.desc)
. += "<br>Описание: [M.desc]"
if(M.author)
. += "<br><i>Автор: [M.author]</i>"
. += "</div><br>"

var/datum/browser/popup = new(mob, "modpacks_list", "Список Модификаций", 480, 580)
popup.set_content(.)
popup.open()
else
if(!length(SSmodpacks.loaded_modpacks))
to_chat(src, "Этот сервер не использует какие-либо модификации.")
return

SSmodpacks.ui_interact(src)

/datum/controller/subsystem/modpacks/ui_static_data(mob/user)
var/list/data = list()

if(!length(tgui_data))
tgui_data = generate_modpacks_data()
data["modpacks"] = tgui_data

return data

/datum/controller/subsystem/modpacks/proc/generate_modpacks_data()
var/list/modpacks = list()
for(var/datum/modpack/modpack as anything in loaded_modpacks)
if(modpack.name)
modpacks += list(list(
"name" = modpack.name,
"desc" = modpack.desc,
"author" = modpack.author
))
return modpacks

/datum/controller/subsystem/modpacks/ui_interact(mob/user, ui_key, datum/tgui/ui, force_open, datum/tgui/master_ui, datum/ui_state/state = GLOB.always_state)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, ui_key, "ModpacksList", "Modpacks List", 500, 550, master_ui, state)
ui.open()
ui.set_autoupdate(FALSE)
84 changes: 84 additions & 0 deletions tgui/packages/tgui/interfaces/ModpacksList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useBackend, useLocalState } from '../backend';
import { Window } from '../layouts';
import { Section, Input, Flex, Collapsible } from '../components';

export const ModpacksList = (props, context) => {
return (
<Window resizable>
<Window.Content scrollable>
<ModpacksListContent />
</Window.Content>
</Window>
);
};

export const ModpacksListContent = (props, context) => {
const { act, data } = useBackend(context);
const { modpacks } = data;

const [searchText, setSearchText] = useLocalState(
context,
'searchText',
''
);

const searchBar = (
<Input
placeholder="Искать модпак по имени, описанию или автору..."
fluid
onInput={(e, value) => setSearchText(value)}
/>
);

return (
<Section>
<Section
title="Фильтры"
>
{searchBar}
</Section>
<Section
title={
searchText.length > 0
? `Результаты поиска "${searchText}"`
: `Все модификации`
}
fill
>
<Flex>
<Flex.Item
grow="1"
basis="100%"
width="100%"
display="inline-block"
>
{modpacks
.filter(modpack => modpack.name &&
(searchText.length > 0 ?
(modpack.name.toLowerCase().includes(searchText.toLowerCase()) ||
modpack.desc.toLowerCase().includes(searchText.toLowerCase()) ||
modpack.author.toLowerCase().includes(searchText.toLowerCase())
) : true))
.map((modpack) =>
<Collapsible
key={modpack.name}
title={modpack.name}
>
<Section
title="Авторы"
>
{modpack.author}
</Section>
<Section
title="Описание"
>
{modpack.desc}
</Section>
</Collapsible>
)}
</Flex.Item>
</Flex>
</Section>
</Section>
);
};
4 changes: 2 additions & 2 deletions tgui/packages/tgui/public/tgui.bundle.js

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions tools/translator/converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import git
import json
BUILD_PATH = "./"


repo = git.Repo(BUILD_PATH)
tree = repo.head.commit.tree
if not tree:
print("No changes")
exit()
diff = repo.git.diff(tree)
if not diff:
print("No changes")
exit()
diff = [line for line in diff.split("\n") if line[0] in "+-" and not line.startswith("+++")]

translation = {"files": []}

lastfile = ''
lastaction = ''
for line in diff:
if line.startswith("---"):
lastfile = line[6:]
lastaction = '---'
translation["files"].append({"path": lastfile, "replaces": []})
elif line.startswith("-"):
if lastaction == "---" or lastaction == "+":
translation["files"][-1]["replaces"].append({"original": line[1:], "replace": ""})
elif lastaction == "-":
translation["files"][-1]["replaces"][-1]["original"]+=f"\n{line[1:]}"
lastaction = "-"
elif line.startswith("+"):
if lastaction == "-":
translation["files"][-1]["replaces"][-1]["replace"] = line[1:]
elif lastaction == "+":
translation["files"][-1]["replaces"][-1]["replace"] += f"\n{line[1:]}"
lastaction = "+"

with open('ss220replace.json', 'w+', encoding='utf-8') as f:
json.dump(translation, f, ensure_ascii=False, indent=2)
print(f"Added translation for {len(translation['files'])} files.")
1 change: 1 addition & 0 deletions tools/translator/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GitPython
Binary file added tools/translator/ss220_replacer_linux
Binary file not shown.
Binary file added tools/translator/ss220_replacer_windows.exe
Binary file not shown.
3 changes: 3 additions & 0 deletions tools/translator/ss220replace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": []
}

0 comments on commit 6785225

Please sign in to comment.