[Scummvm-git-logs] scummvm master -> 4f213d7a98e66f6bf88579b74855fba6c4bf065d
bluegr
noreply at scummvm.org
Sun Jul 24 09:01:33 UTC 2022
This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
125258caf1 SCI: create main method for scifx_to_cpp script
5c8781a369 SCI: remove global variables in scifx_to_cpp
df404e3b8d SCI: whitespace changes in output of scifx_to_cpp
4f213d7a98 SCI: add typing to scifx_to_cpp script
Commit: 125258caf1ab6417727710c1dcd957dd6d8556b0
https://github.com/scummvm/scummvm/commit/125258caf1ab6417727710c1dcd957dd6d8556b0
Author: matthewdippel (mattdippel at gmail.com)
Date: 2022-07-24T12:01:27+03:00
Commit Message:
SCI: create main method for scifx_to_cpp script
The scifx_to_cpp.py script has methods intermingled with method calls
that execute when you call the script. Moving the method calls under
a "__main__" header to improve readability.
Tested by calling the script like shown below on the .scifx files in
the same directory. The output is the name.
```
python .\scifx_to_cpp.py .\lsl2.scifx
```
Changed paths:
devtools/sci/scifx/scifx_to_cpp.py
diff --git a/devtools/sci/scifx/scifx_to_cpp.py b/devtools/sci/scifx/scifx_to_cpp.py
index b5be565715a..93112af8a4f 100644
--- a/devtools/sci/scifx/scifx_to_cpp.py
+++ b/devtools/sci/scifx/scifx_to_cpp.py
@@ -1,41 +1,6 @@
from __future__ import print_function
import sys
-if len(sys.argv) < 2:
- print("Usage: python scifx_to_header.py [scifx files] > scifx.cpp")
- sys.exit(-1)
-
-print("""
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-// NB: This file is AUTO-GENERATED by devtools/sci/scifx/scifx_to_cpp.py
-// from devtools/sci/scifx/*.scifx
-
-#include "sci/graphics/helpers.h"
-#include "sci/graphics/screen.h"
-
-namespace Sci {
-""")
-
def Chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
@@ -105,126 +70,162 @@ def ParseTriple(l):
assert(len(L) == 3)
return L
-GIDs = []
-
-for F in sys.argv[1:]:
- comments = []
- pics = []
- views = []
- Mods = [(1.,1.,1.)]
- GID = ""
-
- for l in open(F, "r").readlines():
- l = l.strip()
- if len(l) == 0:
- continue
- if l[0] == '#':
- comment = l[1:].strip()
- # Only add the top comments (before the game ID is set)
- if (GID == ""):
- comments.append(comment)
- continue
- if l[0:6] == "gameid":
- assert(GID == "")
- l = l[6:].strip()
+if __name__ == "__main__":
+
+ if len(sys.argv) < 2:
+ print("Usage: python scifx_to_header.py [scifx files] > scifx.cpp")
+ sys.exit(-1)
+
+ print("""
+ /* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+ // NB: This file is AUTO-GENERATED by devtools/sci/scifx/scifx_to_cpp.py
+ // from devtools/sci/scifx/*.scifx
+
+ #include "sci/graphics/helpers.h"
+ #include "sci/graphics/screen.h"
+
+ namespace Sci {
+ """)
+ GIDs = []
+
+ for F in sys.argv[1:]:
+ comments = []
+ pics = []
+ views = []
+ Mods = [(1.,1.,1.)]
+ GID = ""
+
+ for l in open(F, "r").readlines():
+ l = l.strip()
+ if len(l) == 0:
+ continue
+ if l[0] == '#':
+ comment = l[1:].strip()
+ # Only add the top comments (before the game ID is set)
+ if (GID == ""):
+ comments.append(comment)
+ continue
+ if l[0:6] == "gameid":
+ assert(GID == "")
+ l = l[6:].strip()
+ l = l.strip()
+ assert(l[0] == "=")
+ assert(l[-1] == ";")
+ l = l[1:-1].strip()
+ GID = l
+ continue
+ if l[0:4] == "view":
+ ruletype = "view"
+ l = l[4:]
+ elif l[0:3] == "pic":
+ ruletype = "pic"
+ l = l[3:]
+ else:
+ assert(False)
+
+ ids = []
+ loops = [-1]
+ cels = [-1]
+ l,ids = ParseList(l)
+ if l[0] == "(":
+ l,loops = ParseList(l)
+ if l[0] == "(":
+ l,cels = ParseList(l)
l = l.strip()
- assert(l[0] == "=")
+ assert(l[0:2] == "*=")
assert(l[-1] == ";")
- l = l[1:-1].strip()
- GID = l
- continue
- if l[0:4] == "view":
- ruletype = "view"
- l = l[4:]
- elif l[0:3] == "pic":
- ruletype = "pic"
- l = l[3:]
- else:
- assert(False)
-
- ids = []
- loops = [-1]
- cels = [-1]
- l,ids = ParseList(l)
- if l[0] == "(":
- l,loops = ParseList(l)
- if l[0] == "(":
- l,cels = ParseList(l)
- l = l.strip()
- assert(l[0:2] == "*=")
- assert(l[-1] == ";")
- l = l[2:-1].strip()
- if l[0] == "(":
- val = ParseTriple(l)
- val = (float(v) for v in val)
- else:
- val = (float(l), float(l), float(l))
- if ruletype == "pic":
- for pic in ids:
- pics.append([pic, ModToIndex(val)])
- elif ruletype == "view":
- for view in ids:
- for loop in loops:
- for cel in cels:
- views.append([view, loop, cel, ModToIndex(val)])
-
- if GID == "":
- raise ValueError("No gameid specified")
-
- GIDs.append(GID)
-
- PrintMods()
- print()
- PrintPic(pics, comments)
- print()
- PrintView(views, comments)
- print()
-
-print("static const SciFxMod mods[] = {")
-for GID in GIDs:
- print("\t{{ GID_{0}, paletteMods{0}, ARRAYSIZE(paletteMods{0}), picMods{0}, ARRAYSIZE(picMods{0}), viewMods{0}, ARRAYSIZE(viewMods{0}) }},".format(GID));
-print("};")
-
-print("""
-void setupCustomPaletteMods(GfxScreen *screen) {
- for (int i = 0; i < ARRAYSIZE(mods); i++) {
- if (mods[i].gameId == g_sci->getGameId()) {
- screen->setPaletteMods(mods[i].paletteMods, mods[i].paletteModsSize);
- break;
- }
- }
-}
-
-void doCustomViewPalette(GfxScreen *screen, GuiResourceId view, int16 loop, int16 cel) {
- for (int i = 0; i < ARRAYSIZE(mods); i++) {
- SciFxMod mod = mods[i];
- if (mod.gameId == g_sci->getGameId()) {
- for (int j = 0; j < mod.viewModsSize; j++) {
- ViewMod m = mod.viewMods[j];
- if (m.id == view && (m.loop == -1 || m.loop == loop) && (m.cel == -1 || m.cel == cel)) {
- screen->setCurPaletteMapValue(m.multiplier);
- break;
- }
- }
- break;
- }
- }
-}
-
-void doCustomPicPalette(GfxScreen *screen, GuiResourceId pic) {
- for (int i = 0; i < ARRAYSIZE(mods); i++) {
- SciFxMod mod = mods[i];
- if (mod.gameId == g_sci->getGameId()) {
- for (int j = 0; j < mod.picModsSize; j++) {
- PicMod m = mod.picMods[j];
- if (m.id == pic) {
- screen->setCurPaletteMapValue(m.multiplier);
- break;
- }
- }
- break;
- }
- }
-}
-
-}""")
+ l = l[2:-1].strip()
+ if l[0] == "(":
+ val = ParseTriple(l)
+ val = (float(v) for v in val)
+ else:
+ val = (float(l), float(l), float(l))
+ if ruletype == "pic":
+ for pic in ids:
+ pics.append([pic, ModToIndex(val)])
+ elif ruletype == "view":
+ for view in ids:
+ for loop in loops:
+ for cel in cels:
+ views.append([view, loop, cel, ModToIndex(val)])
+
+ if GID == "":
+ raise ValueError("No gameid specified")
+
+ GIDs.append(GID)
+
+ PrintMods()
+ print()
+ PrintPic(pics, comments)
+ print()
+ PrintView(views, comments)
+ print()
+
+ print("static const SciFxMod mods[] = {")
+ for GID in GIDs:
+ print("\t{{ GID_{0}, paletteMods{0}, ARRAYSIZE(paletteMods{0}), picMods{0}, ARRAYSIZE(picMods{0}), viewMods{0}, ARRAYSIZE(viewMods{0}) }},".format(GID));
+ print("};")
+
+ print("""
+ void setupCustomPaletteMods(GfxScreen *screen) {
+ for (int i = 0; i < ARRAYSIZE(mods); i++) {
+ if (mods[i].gameId == g_sci->getGameId()) {
+ screen->setPaletteMods(mods[i].paletteMods, mods[i].paletteModsSize);
+ break;
+ }
+ }
+ }
+
+ void doCustomViewPalette(GfxScreen *screen, GuiResourceId view, int16 loop, int16 cel) {
+ for (int i = 0; i < ARRAYSIZE(mods); i++) {
+ SciFxMod mod = mods[i];
+ if (mod.gameId == g_sci->getGameId()) {
+ for (int j = 0; j < mod.viewModsSize; j++) {
+ ViewMod m = mod.viewMods[j];
+ if (m.id == view && (m.loop == -1 || m.loop == loop) && (m.cel == -1 || m.cel == cel)) {
+ screen->setCurPaletteMapValue(m.multiplier);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ void doCustomPicPalette(GfxScreen *screen, GuiResourceId pic) {
+ for (int i = 0; i < ARRAYSIZE(mods); i++) {
+ SciFxMod mod = mods[i];
+ if (mod.gameId == g_sci->getGameId()) {
+ for (int j = 0; j < mod.picModsSize; j++) {
+ PicMod m = mod.picMods[j];
+ if (m.id == pic) {
+ screen->setCurPaletteMapValue(m.multiplier);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ }""")
Commit: 5c8781a369ae9a3989aa64d3a155c91cc039353a
https://github.com/scummvm/scummvm/commit/5c8781a369ae9a3989aa64d3a155c91cc039353a
Author: matthewdippel (mattdippel at gmail.com)
Date: 2022-07-24T12:01:27+03:00
Commit Message:
SCI: remove global variables in scifx_to_cpp
Methods in scifx_to_cpp.py refer to arrays outside of their scope.
Refactored them to take them as parameters instead to improve
readability.
Tested by calling on the .scifx files in the same directory as below.
Output is unchanged.
```
python .\scifx_to_cpp.py .\lsl2.scifx
```
Changed paths:
devtools/sci/scifx/scifx_to_cpp.py
diff --git a/devtools/sci/scifx/scifx_to_cpp.py b/devtools/sci/scifx/scifx_to_cpp.py
index 93112af8a4f..82ad0d1f962 100644
--- a/devtools/sci/scifx/scifx_to_cpp.py
+++ b/devtools/sci/scifx/scifx_to_cpp.py
@@ -4,21 +4,21 @@ import sys
def Chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
-def ModToIndex(m):
+def ModToIndex(mods, m):
try:
- return Mods.index(m)
+ return mods.index(m)
except ValueError:
- Mods.append(m)
- return len(Mods)-1
+ mods.append(m)
+ return len(mods)-1
-def PrintMods():
- L = [ "\t{ " + ", ".join( [ "%4d" % (round(128 * (val - 1)),) for val in m ] ) + " }" for m in Mods ]
- print("static const PaletteMod paletteMods" + GID + "[] = {")
+def PrintMods(gid, mods):
+ L = [ "\t{ " + ", ".join( [ "%4d" % (round(128 * (val - 1)),) for val in m ] ) + " }" for m in mods ]
+ print("static const PaletteMod paletteMods" + gid + "[] = {")
print( ",\n".join(L) )
print("};")
-def PrintPic(pics, comments):
- print("static const PicMod picMods" + GID + "[] = {")
+def PrintPic(gid, pics, comments):
+ print("static const PicMod picMods" + gid + "[] = {")
for comment in comments:
print("\t// " + comment)
@@ -31,8 +31,8 @@ def PrintPic(pics, comments):
print("};")
-def PrintView(views, comments):
- print("static const ViewMod viewMods" + GID + "[] = {")
+def PrintView(gid, views, comments):
+ print("static const ViewMod viewMods" + gid + "[] = {")
for comment in comments:
print("\t// " + comment)
@@ -71,7 +71,6 @@ def ParseTriple(l):
return L
if __name__ == "__main__":
-
if len(sys.argv) < 2:
print("Usage: python scifx_to_header.py [scifx files] > scifx.cpp")
sys.exit(-1)
@@ -106,14 +105,15 @@ if __name__ == "__main__":
namespace Sci {
""")
- GIDs = []
+ input_files = sys.argv[1:]
+ gids = []
- for F in sys.argv[1:]:
+ for F in input_files:
comments = []
pics = []
views = []
- Mods = [(1.,1.,1.)]
- GID = ""
+ mods = [(1.,1.,1.)]
+ gid = ""
for l in open(F, "r").readlines():
l = l.strip()
@@ -122,17 +122,17 @@ if __name__ == "__main__":
if l[0] == '#':
comment = l[1:].strip()
# Only add the top comments (before the game ID is set)
- if (GID == ""):
+ if (gid == ""):
comments.append(comment)
continue
if l[0:6] == "gameid":
- assert(GID == "")
+ assert(gid == "")
l = l[6:].strip()
l = l.strip()
assert(l[0] == "=")
assert(l[-1] == ";")
l = l[1:-1].strip()
- GID = l
+ gid = l
continue
if l[0:4] == "view":
ruletype = "view"
@@ -162,28 +162,28 @@ if __name__ == "__main__":
val = (float(l), float(l), float(l))
if ruletype == "pic":
for pic in ids:
- pics.append([pic, ModToIndex(val)])
+ pics.append([pic, ModToIndex(mods, val)])
elif ruletype == "view":
for view in ids:
for loop in loops:
for cel in cels:
- views.append([view, loop, cel, ModToIndex(val)])
+ views.append([view, loop, cel, ModToIndex(mods, val)])
- if GID == "":
+ if gid == "":
raise ValueError("No gameid specified")
- GIDs.append(GID)
+ gids.append(gid)
- PrintMods()
+ PrintMods(gid, mods)
print()
- PrintPic(pics, comments)
+ PrintPic(gid, pics, comments)
print()
- PrintView(views, comments)
+ PrintView(gid, views, comments)
print()
print("static const SciFxMod mods[] = {")
- for GID in GIDs:
- print("\t{{ GID_{0}, paletteMods{0}, ARRAYSIZE(paletteMods{0}), picMods{0}, ARRAYSIZE(picMods{0}), viewMods{0}, ARRAYSIZE(viewMods{0}) }},".format(GID));
+ for gid in gids:
+ print("\t{{ gid_{0}, paletteMods{0}, ARRAYSIZE(paletteMods{0}), picMods{0}, ARRAYSIZE(picMods{0}), viewMods{0}, ARRAYSIZE(viewMods{0}) }},".format(gid));
print("};")
print("""
Commit: df404e3b8d70df61ee5ac6673699d897216eece5
https://github.com/scummvm/scummvm/commit/df404e3b8d70df61ee5ac6673699d897216eece5
Author: matthewdippel (mattdippel at gmail.com)
Date: 2022-07-24T12:01:27+03:00
Commit Message:
SCI: whitespace changes in output of scifx_to_cpp
Several whitespace changes to the output in order to make the resulting
cpp file consistent with how cpp is formatted in the repo.
- Properly align the opening of the first comment block.
- Properly align the closing brace of the Sci namespace scope.
Changed paths:
devtools/sci/scifx/scifx_to_cpp.py
diff --git a/devtools/sci/scifx/scifx_to_cpp.py b/devtools/sci/scifx/scifx_to_cpp.py
index 82ad0d1f962..25a453facb6 100644
--- a/devtools/sci/scifx/scifx_to_cpp.py
+++ b/devtools/sci/scifx/scifx_to_cpp.py
@@ -76,7 +76,7 @@ if __name__ == "__main__":
sys.exit(-1)
print("""
- /* ScummVM - Graphic Adventure Engine
+ /* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
@@ -228,4 +228,4 @@ if __name__ == "__main__":
}
}
- }""")
+}""")
Commit: 4f213d7a98e66f6bf88579b74855fba6c4bf065d
https://github.com/scummvm/scummvm/commit/4f213d7a98e66f6bf88579b74855fba6c4bf065d
Author: matthewdippel (mattdippel at gmail.com)
Date: 2022-07-24T12:01:27+03:00
Commit Message:
SCI: add typing to scifx_to_cpp script
Adding type hints to the various helper methods in this script
to make it easier to read and understand how the scifx parsing is
done.
Changed paths:
devtools/sci/scifx/scifx_to_cpp.py
diff --git a/devtools/sci/scifx/scifx_to_cpp.py b/devtools/sci/scifx/scifx_to_cpp.py
index 25a453facb6..ceb396afcef 100644
--- a/devtools/sci/scifx/scifx_to_cpp.py
+++ b/devtools/sci/scifx/scifx_to_cpp.py
@@ -1,23 +1,24 @@
from __future__ import print_function
import sys
+from typing import List, Tuple, Any
-def Chunker(seq, size):
+def Chunker(seq: List[Any], size: int) -> List[List[Any]]:
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
-def ModToIndex(mods, m):
+def ModToIndex(mods: List[Tuple[int]], m: int):
try:
return mods.index(m)
except ValueError:
mods.append(m)
return len(mods)-1
-def PrintMods(gid, mods):
+def PrintMods(gid: str, mods: List[Tuple[int]]):
L = [ "\t{ " + ", ".join( [ "%4d" % (round(128 * (val - 1)),) for val in m ] ) + " }" for m in mods ]
print("static const PaletteMod paletteMods" + gid + "[] = {")
print( ",\n".join(L) )
print("};")
-def PrintPic(gid, pics, comments):
+def PrintPic(gid: str, pics: List[List[int]], comments: List[str]):
print("static const PicMod picMods" + gid + "[] = {")
for comment in comments:
@@ -31,7 +32,7 @@ def PrintPic(gid, pics, comments):
print("};")
-def PrintView(gid, views, comments):
+def PrintView(gid: str, views: List[List[int]], comments: List[str]):
print("static const ViewMod viewMods" + gid + "[] = {")
for comment in comments:
@@ -45,7 +46,7 @@ def PrintView(gid, views, comments):
print("};")
-def ParseList(l):
+def ParseList(l: str) -> Tuple[str, List[str]]:
assert(l[0] == '(')
e = l.find(")")
L = l[1:e].split(",")
@@ -58,12 +59,12 @@ def ParseList(l):
end = int(t[ell+2:])
# interval
for x in range(start, end + 1):
- tests.append(x)
+ tests.append(str(x))
else:
tests.append(t)
return l[e+1:], tests
-def ParseTriple(l):
+def ParseTriple(l: str) -> List[str]:
assert(l[0] == '(')
e = l.find(")")
L = l[1:e].split(",")
More information about the Scummvm-git-logs
mailing list