การแพ็กเกจและการแจกจ่าย¶
Wayward Crown มีวิธีการแพ็กเกจสองแบบเพื่อคอมไพล์เกมเป็นไฟล์ปฏิบัติการที่แจกจ่ายได้โดยตรง
การเปรียบเทียบวิธีการ¶
| รายการ | PyInstaller | Nuitka |
|---|---|---|
| ความเร็วในการบิลด์ | เร็ว (วินาทีถึงนาที) | ช้า (5–15 นาที) |
| ความเร็วขณะรัน | เท่ากับ Python | เร็วขึ้นเล็กน้อย (+5%–30%) |
| การป้องกันซอร์สโค้ด | .pyc สามารถดีคอมไพล์ได้ |
คอมไพล์เป็น C ยากมากในการย้อนกลับ |
| ขนาดไฟล์แจกจ่าย | เล็กกว่า | ใหญ่กว่า |
| ต้องการคอมไพเลอร์ C | ไม่ | ใช่ |
| แนะนำสำหรับ | การพัฒนาและทดสอบ | การเผยแพร่เวอร์ชันจริง |
ข้อกำหนดเบื้องต้น¶
pip install -r requirements.txt
python setup_ext.py build_ext --inplace # สร้าง game/_ccore.*.pyd
ต้องคอมไพล์ส่วนขยาย C ก่อน มิฉะนั้นเกมจะถอยกลับไปใช้เส้นทาง Python ล้วน (ประสิทธิภาพต่ำกว่า)
PyInstaller¶
การติดตั้ง¶
pip install pyinstaller
คำสั่งบิลด์¶
pyinstaller --noconfirm --clean --name WaywardCrown ^
--noconsole ^
--icon "assets/Icons/WaywardCrown.ico" ^
--add-data "assets;assets" ^
--add-data "game/content;game/content" ^
--add-data "game/lang;game/lang" ^
--add-data "plugins;plugins" ^
--add-data "campaigns;campaigns" ^
--add-data "maps;maps" ^
--add-data "steam_sdk;steam_sdk" ^
--add-data "THIRD_PARTY_LICENSES.md;." ^
--add-data "LGPL-3.0.txt;." ^
--add-data "GPL-3.0.txt;." ^
--add-binary "game/_ccore.cp314-win_amd64.pyd;game" ^
--hidden-import PySide6.QtWidgets ^
--hidden-import PySide6.QtCore ^
--hidden-import PySide6.QtGui ^
--hidden-import PySide6.QtOpenGLWidgets ^
--hidden-import PySide6.QtMultimedia ^
--hidden-import OpenGL.GL ^
main.py
ผลลัพธ์¶
dist/WaywardCrown/
├── WaywardCrown.exe
└── _internal/
├── assets/
├── game/
│ ├── _ccore.cp314-win_amd64.pyd
│ ├── content/
│ └── lang/
├── campaigns/
├── maps/
└── plugins/
Nuitka¶
การติดตั้ง¶
pip install nuitka zstandard ordered-set
ต้องมีคอมไพเลอร์ C (Visual Studio Build Tools หรือ MinGW64)
คำสั่งบิลด์¶
python -m nuitka ^
--standalone ^
--plugin-enable=pyside6 ^
--include-data-dir=assets=assets ^
--include-data-dir=game/content=game/content ^
--include-data-dir=game/lang=game/lang ^
--include-data-dir=plugins=plugins ^
--include-data-dir=campaigns=campaigns ^
--include-data-dir=maps=maps ^
--include-data-dir=steam_sdk=steam_sdk ^
--include-data-files=steam_sdk/steam_api.dll=steam_sdk/steam_api.dll ^
--include-data-files=steam_sdk/win64/steam_api64.dll=steam_sdk/win64/steam_api64.dll ^
--include-data-files=game/_ccore.cp314-win_amd64.pyd=game/_ccore.cp314-win_amd64.pyd ^
--include-data-files=THIRD_PARTY_LICENSES.md=THIRD_PARTY_LICENSES.md ^
--include-data-files=LGPL-3.0.txt=LGPL-3.0.txt ^
--include-data-files=GPL-3.0.txt=GPL-3.0.txt ^
--include-qt-plugins=multimedia ^
--include-package=OpenGL ^
--include-module=PySide6.QtOpenGLWidgets ^
--include-module=PySide6.QtMultimedia ^
--windows-console-mode=disable ^
--windows-icon-from-ico=assets/Icons/WaywardCrown.ico ^
--output-filename=WaywardCrown.exe ^
--output-dir=dist ^
--lto=yes ^
--jobs=8 ^
main.py
ไฟล์ที่จำเป็น¶
| ประเภท | เส้นทาง | คำอธิบาย |
|---|---|---|
| ส่วนขยาย C | game/_ccore.cp3XX-*.pyd |
การเร่งความเร็วหลักสำหรับการค้นหาเส้นทาง A*, spatial hashing ฯลฯ |
| เนื้อหาเกม | game/content/*.json |
นิยามคลาส ศัตรู และอาคาร |
| ชุดภาษา | game/lang/*.json |
คำแปล 15 ภาษา |
| แอสเซทกราฟิก | assets/ |
รูปภาพ เพลง และเอฟเฟกต์เสียงทั้งหมด |
| แคมเปญ | campaigns/ |
แคมเปญบทเรียนในตัว |
| แผนที่กำหนดเอง | maps/ |
แผนที่ผู้ใช้ |
| ปลั๊กอิน | plugins/ |
ส่วนขยายของบุคคลที่สาม |
| Steam SDK | steam_sdk/ |
Steamworks DLL |
| สัญญาอนุญาต | THIRD_PARTY_LICENSES.md ฯลฯ |
เอกสารการปฏิบัติตาม LGPLv3 |
เวอร์ชัน Python
ชื่อไฟล์ .pyd รวมเวอร์ชัน Python (เช่น cp314) หลังจากเปลี่ยนเวอร์ชัน Python คุณต้องคอมไพล์ส่วนขยาย C ใหม่และอัปเดตชื่อไฟล์ในคำสั่งบิลด์