Skip to content

Commit

Permalink
Merge pull request #21 from BA-OST-Index/dev_v2
Browse files Browse the repository at this point in the history
2024-04-14 v2 code
  • Loading branch information
sctop authored Apr 13, 2024
2 parents 0eb321b + 3767bd6 commit 0286d81
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 94 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Dev Branch
on:
push:
branches:
- 'dev'
- 'dev_v2'

jobs:
build:
Expand All @@ -18,10 +18,9 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Update submodules
run: |
git submodule update --remote

# Run main script to test if it can work
- name: Run main.py
run: python main.py
- name: Run testing script
run: |
mkdir -p data_export
python main_quick_test.py
9 changes: 4 additions & 5 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Update submodules
run: |
git submodule update --remote

# Run main script to test if it can work
- name: Run main.py
run: python main.py
- name: Run testing script
run: |
mkdir -p data_export
python main_quick_test.py
31 changes: 11 additions & 20 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,28 @@ name: Push
on:
push:
branches:
- 'main'
- 'main_v2'
workflow_dispatch:
repository_dispatch:
types: [ost-data-update-event]
types: [ost-data-push-direct]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Update submodules
run: |
git submodule update --remote
- name: Run main.py
run: python main.py
- name: Push changes
- name: Run main_quick_test.py
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
cd data_export
git add .
git commit -m "Update: ${{ github.event.head_commit.message }}"
git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all
git push https://github-actions[bot]:$REPO_KEY@github.com/BA-OST-Index/ost_data_export.git HEAD:main
env:
REPO_KEY: ${{secrets.ACTION_SCRIPT}}
mkdir -p data_export
python main_quick_test.py
- name: Generator Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.ACTION_SCRIPT }}
event-type: ost-data-parser-push-direct
repository: BA-OST-Index/ost_data_site_generator
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
test*.py
/data_export/

# -----------------------------------------
# From https://github.com/github/gitignore/blob/main/Python.gitignore
Expand Down Expand Up @@ -156,5 +157,4 @@ dmypy.json
.pytype/

# Cython debug symbols
cython_debug/
/data_export/
cython_debug/
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
[submodule "data"]
path = data
url = https://github.com/BA-OST-Index/ost_data.git
branch = main
[submodule "data_export"]
path = data_export
url = https://github.com/BA-OST-Index/ost_data_export.git
branch = main
2 changes: 1 addition & 1 deletion data
Submodule data updated 128 files
1 change: 0 additions & 1 deletion data_export
Submodule data_export deleted from 0c42c1
9 changes: 9 additions & 0 deletions data_model/actual_data/_story/story_part_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def load(self):
self._char_to_bg[char_id] = bg.uuid

# char to char
_char_to_char = []
for (char_id, data) in self.data["char_to_char"].items():
try:
char1 = self.data_all.character[char_id]
Expand All @@ -152,6 +153,14 @@ def load(self):
except KeyError:
continue

# 唯一识别ID,防止二次注册
_ctc_id1 = f"{char_id}_{char2_id}"
_ctc_id2 = f"{char2_id}_{char_id}"
if _ctc_id1 in _char_to_char or _ctc_id2 in _char_to_char:
continue
_char_to_char.append(_ctc_id1)
_char_to_char.append(_ctc_id2)

char1.register(char2)
char2.register(char1)

Expand Down
5 changes: 4 additions & 1 deletion data_model/actual_data/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ def __init__(self, **kwargs):
self._bond_track = None
self._bond_rank = -1

self.profile_intro = i18n_translator.query(f"[CHARACTER_{self._id}_GET_DIALOG_TEXT]")

self.used_by = CharacterUsedBy()
if "related_to" not in kwargs["data"].keys():
self.related_to = CharacterRelatedTo(self, CharacterRelatedTo.BLANK_DATA)
Expand Down Expand Up @@ -372,7 +374,8 @@ def to_json(self):
},
"profile": {
"profile": self.profile.to_json(),
"gacha": self.profile_gacha.to_json()
"gacha": self.profile_gacha.to_json(),
"intro": self.profile_intro.to_json()
},
"school": {
"short": self.school.to_json(),
Expand Down
113 changes: 113 additions & 0 deletions data_model/actual_data/composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from collections import OrderedDict

from ..loader import FileLoader
from .used_by import BaseUsedBy, UsedByRegisterMixin, UsedByToJsonMixin
from ..constant.file_type import FILETYPES_TRACK
from ..tool.interpage import InterpageMixin
from ..types.url import UrlModel
from ..tool.tool import ObjectAccessProxier


class ComposerUsedBy(BaseUsedBy, UsedByToJsonMixin):
SUPPORTED_FILETYPE = [*FILETYPES_TRACK]

def __init__(self):
self.data_track = OrderedDict()

def register(self, file_loader: FileLoader, count_increase=True):
filetype = file_loader.filetype
instance_id = file_loader.instance_id

if filetype in self.SUPPORTED_FILETYPE:
if filetype in FILETYPES_TRACK:
self.data_track[instance_id] = file_loader
else:
raise ValueError

def to_json(self, no_used_by: bool = True):
return {"data_track": [i.to_json_basic() for i in self.data_track.values()]}


class NameMasker(ObjectAccessProxier):
def __init__(self, obj: str):
"""兼容Interpage相关策略"""
super().__init__(obj)

def to_json(self):
return {
"en": self._object,
"zh_cn": self._object,
"jp": self._object
}

def to_json_basic(self):
return self.to_json()


class ComposerInfo(FileLoader, UsedByRegisterMixin, InterpageMixin):
_instance = {}

def __init__(self, **kwargs):
super().__init__(data=kwargs["data"], namespace=kwargs["namespace"], parent_data=kwargs["parent_data"])
self.data = data = kwargs["data"]

self.no = data["no"]
self.name = NameMasker(data["name"]["nickname"])
self.realname = data["name"]["realname"]
self.nickname = data["name"]["nickname"]
self.intro = data["intro"]

self.contact = UrlModel()
self.contact.load(data["contact"])

self.used_by = ComposerUsedBy()

@staticmethod
def _get_instance_id(data: dict):
return str(data["no"])

def to_json(self):
d = {
"uuid": self.uuid,
"filetype": self.filetype,
"namespace": self.namespace,

"name": self.name.to_json(),
"no": self.no,
"realname": self.realname,
"nickname": self.nickname,
"intro": self.intro,
"contact": self.contact.to_json(),

"used_by": self.used_by.to_json(),
"interpage": self.get_interpage_data()
}
return d

def to_json_basic(self):
d = {
"uuid": self.uuid,
"filetype": self.filetype,
"namespace": self.namespace,

"name": self.name.to_json(),
"no": self.no,
"realname": self.realname,
"nickname": self.nickname,
"intro": self.intro,
"contact": self.contact.to_json(),

"interpage": self.get_interpage_data()
}
return d

def _get_instance_offset(self, offset: int):
keys = list(self._instance.keys())
curr_index = keys.index(self.instance_id)

try:
if curr_index == 0 and offset < 0:
return None
return self._instance[keys[curr_index + offset]]
except (IndexError, KeyError):
return None
6 changes: 6 additions & 0 deletions data_model/actual_data/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def register(self, file_loader: FileLoader, count_increase=True):
else:
raise ValueError

def to_json(self, no_used_by: bool = True):
return {
"data_track": [i.to_json_basic() for i in self.data_track.values()],
"data_background": [i.to_json_basic() for i in self.data_background.values()]
}


class TagInfo(FileLoader, UsedByRegisterMixin, InterpageMixin):
_color_to_css = {"green": "success", "blue": "primary",
Expand Down
61 changes: 9 additions & 52 deletions data_model/actual_data/track.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
from itertools import chain
from collections import OrderedDict

from data_model.types.url import *
from data_model.types.metatype.base_type import *
from data_model.types.metatype.base_model import *
from data_model.types.metatype.complex import *
from data_model.types.lang_string import *

from data_model.loader import i18n_translator, FileLoader
from data_model.loader.manager_constant import constant_manager

from data_model.actual_data.used_by import BaseUsedBy, UsedByRegisterMixin, OrderedDictWithCounter, UsedByToJsonMixin
from data_model.actual_data.related_to import BaseRelatedTo, RelatedToJsonMixin, RelatedToRegisterMixin
from data_model.actual_data._track.track_version import *
from data_model.actual_data.tag import TagListManager
from data_model.actual_data.composer import ComposerInfo

from data_model.constant.file_type import FILETYPES_STORY, FILETYPES_BATTLE, FILETYPES_BACKGROUND, \
FILE_VIDEO_INFO, FILETYPES_TRACK, FILE_STORY_EVENT, FILE_BATTLE_EVENT, FILE_UI_EVENT, FILE_UI_CHILD, \
FILETYPES_CHARACTER, FILE_STUDENT_INFO, \
FILE_STORY_BOND, FLAG_STORY_BATTLE
from data_model.actual_data.tag import TagListManager

from data_model.tool.tool import seconds_to_minutes
from data_model.tool.interpage import InterpageMixin

from ..tool.tool import counter_dict_sorter, PostExecutionManager

__all__ = ["TrackInfo", "TrackListManager"]
Expand Down Expand Up @@ -315,56 +322,6 @@ def to_json_basic(self):
return self.to_json()


class Composer(BaseDataModel, UsedByRegisterMixin):
"""
Defines a `composer` dict.
Note: This class implements irregular Singleton behaviour, in which when
you're loading the data, it might return an existing instance if
there's a match in either the `nickname` or `composer_id`.
"""
realname = String("realname")
nickname = String("nickname")
_components = ["composer_id", "realname", "nickname", "contact"]
_instance = {}

def __init__(self, key_name="composer"):
super().__init__(key_name)
self.contact = Contact()
self.used_by = ComposerUsedBy()

def load(self, value: dict):
self.composer_id = str(value.get("composer_id", ""))
if self.composer_id in self._instance.keys():
return self._instance[self.composer_id]

# If none is found, then it's the first time to create
# Check if the composer is auto-indexed
if value.get("composer_id", "") != "":
value = constant_manager.query("composer", value["composer_id"])
super().load(value)

self.realname = value["realname"]
self.nickname = value["nickname"]
self.contact.load(value["contact"])

self._instance[self.composer_id] = self

return self

def to_json(self):
return {"composer_id": self.composer_id,
"realname": self.realname,
"nickname": self.nickname,
"contact": self.contact.to_json_basic(),
"used_by": self.used_by.to_json_basic()}

def to_json_basic(self):
return {"composer_id": self.composer_id,
"nickname": self.nickname,
"contact": self.contact.to_json_basic()}


# -------------------------------------------------------

class TrackInfo(FileLoader, UsedByRegisterMixin, InterpageMixin, RelatedToRegisterMixin):
Expand Down Expand Up @@ -395,7 +352,7 @@ def __init__(self, **kwargs):
self.desc = i18n_translator[data["desc"]]

# Other stuff
self.composer = Composer().load(data["composer"])
self.composer = ComposerInfo.get_instance(str(data["composer"]["composer_id"]))
self.composer.register(self)
self.tags = TrackTags('tags', self)
self.version = TrackVersionListManager('version')
Expand Down
Loading

0 comments on commit 0286d81

Please sign in to comment.