Skip to content

Commit

Permalink
Codechange: rework how grf and ob[msg] are generated
Browse files Browse the repository at this point in the history
For grfs, it now uses CMake scripts to do its job, and both grf
files are split into their own folder to make more clear what is
going on. Additionally, it no longer builds in-source (although the
resulting grf is copied back in the source folder).

For ob[msg] it now uses CMake scripts to generate the translation
files; the result is no longer stored in-source (but in the build
folder).

Although all files are available to create the GRFs and basesets, it
won't really work till CMake is introduced (which will happen in a
few commits from here)
  • Loading branch information
TrueBrain authored and glx22 committed Jun 5, 2020
1 parent 203a77c commit 85315e2
Show file tree
Hide file tree
Showing 84 changed files with 220 additions and 255 deletions.
53 changes: 53 additions & 0 deletions cmake/scripts/Baseset.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.5)

#
# Create a single baseset meta file with the correct translations.
#

set(ARGC 1)
set(ARG_READ NO)

# Read all the arguments given to CMake; we are looking for -- and everything
# that follows. Those are our language files.
while(ARGC LESS CMAKE_ARGC)
set(ARG ${CMAKE_ARGV${ARGC}})

if (ARG_READ)
list(APPEND LANG_SOURCE_FILES "${ARG}")
endif (ARG_READ)

if (ARG STREQUAL "--")
set(ARG_READ YES)
endif (ARG STREQUAL "--")

math(EXPR ARGC "${ARGC} + 1")
endwhile()

# Place holder format is @<ini_key>_<str_id>@
file(STRINGS "${BASESET_SOURCE_FILE}" PLACE_HOLDER REGEX "^@")
string(REGEX REPLACE "@([^_]+).*@" "\\1" INI_KEY "${PLACE_HOLDER}")
string(REGEX REPLACE "@[^_]+_(.*)@" "\\1" STR_ID "${PLACE_HOLDER}")
string(REGEX REPLACE "@(.*)@" "\\1" PLACE_HOLDER "${PLACE_HOLDER}")

# Get the translations
foreach(LANGFILE IN LISTS LANG_SOURCE_FILES)
file(STRINGS "${LANGFILE}" LANGLINES REGEX "^(##isocode|${STR_ID})" ENCODING UTF-8)
string(FIND "${LANGLINES}" "${STR_ID}" HAS_STR_ID)
if (HAS_STR_ID LESS 0)
continue()
endif (HAS_STR_ID LESS 0)
string(REGEX REPLACE "##isocode ([^;]+).*" "\\1" ISOCODE "${LANGLINES}")
if ("${ISOCODE}" STREQUAL "en_GB")
string(REGEX REPLACE "[^:]*:(.*)" "${INI_KEY} = \\1" LANGLINES "${LANGLINES}")
else()
string(REGEX REPLACE "[^:]*:(.*)" "${INI_KEY}.${ISOCODE} = \\1" LANGLINES "${LANGLINES}")
endif()
list(APPEND ${PLACE_HOLDER} ${LANGLINES})
endforeach(LANGFILE)
list(SORT ${PLACE_HOLDER})
string(REPLACE ";" "\n" ${PLACE_HOLDER} "${${PLACE_HOLDER}}")

# Get the grf md5
file(MD5 ${BASESET_EXTRAGRF_FILE} ORIG_EXTRA_GRF_MD5)

configure_file(${BASESET_SOURCE_FILE} ${BASESET_BINARY_FILE})
44 changes: 44 additions & 0 deletions cmake/scripts/CreateGRF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.5)

#
# Create a single GRF file based on sprites/<grfname>.nfo and sprites/*.png
# files.
#

if (NOT NFORENUM_EXECUTABLE)
message(FATAL_ERROR "Script needs NFORENUM_EXECUTABLE defined")
endif (NOT NFORENUM_EXECUTABLE)
if (NOT GRFCODEC_EXECUTABLE)
message(FATAL_ERROR "Script needs GRFCODEC_EXECUTABLE defined")
endif (NOT GRFCODEC_EXECUTABLE)
if (NOT GRF_SOURCE_FOLDER)
message(FATAL_ERROR "Script needs GRF_SOURCE_FOLDER defined")
endif (NOT GRF_SOURCE_FOLDER)
if (NOT GRF_BINARY_FILE)
message(FATAL_ERROR "Script needs GRF_BINARY_FILE defined")
endif (NOT GRF_BINARY_FILE)

get_filename_component(GRF_SOURCE_FOLDER_NAME "${GRF_SOURCE_FOLDER}" NAME)

file(WRITE sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "")
file(READ ${GRF_SOURCE_FOLDER}/${GRF_SOURCE_FOLDER_NAME}.nfo NFO_LINES)
# Replace ; with \;, and make a list out of this based on \n
string(REPLACE ";" "\\;" NFO_LINES "${NFO_LINES}")
string(REPLACE "\n" ";" NFO_LINES "${NFO_LINES}")

foreach(NFO_LINE IN LISTS NFO_LINES)
# Recover the ; that was really in the text (and not a newline)
string(REPLACE "\\;" ";" NFO_LINE "${NFO_LINE}")

if (NFO_LINE MATCHES "^#include")
string(REGEX REPLACE "^#include \"(.*)\"$" "\\1" INCLUDE_FILE ${NFO_LINE})
file(READ ${GRF_SOURCE_FOLDER}/${INCLUDE_FILE} INCLUDE_LINES)
file(APPEND sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "${INCLUDE_LINES}")
else (NFO_LINE MATCHES "^#include")
file(APPEND sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "${NFO_LINE}\n")
endif (NFO_LINE MATCHES "^#include")
endforeach(NFO_LINE)

execute_process(COMMAND ${NFORENUM_EXECUTABLE} -s sprites/${GRF_SOURCE_FOLDER_NAME}.nfo)
execute_process(COMMAND ${GRFCODEC_EXECUTABLE} -n -s -e -p1 ${GRF_SOURCE_FOLDER_NAME}.grf)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${GRF_SOURCE_FOLDER_NAME}.grf ${GRF_BINARY_FILE})
87 changes: 87 additions & 0 deletions media/baseset/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
add_subdirectory(openttd)
add_subdirectory(orig_extra)

set(BASESET_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/orig_dos.obg
${CMAKE_CURRENT_SOURCE_DIR}/orig_dos_de.obg
${CMAKE_CURRENT_SOURCE_DIR}/orig_win.obg
${CMAKE_CURRENT_SOURCE_DIR}/no_music.obm
${CMAKE_CURRENT_SOURCE_DIR}/orig_dos.obm
${CMAKE_CURRENT_SOURCE_DIR}/orig_tto.obm
${CMAKE_CURRENT_SOURCE_DIR}/orig_win.obm
${CMAKE_CURRENT_SOURCE_DIR}/no_sound.obs
${CMAKE_CURRENT_SOURCE_DIR}/orig_dos.obs
${CMAKE_CURRENT_SOURCE_DIR}/orig_win.obs
)
set(BASESET_OTHER_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/openttd.grf
${CMAKE_CURRENT_SOURCE_DIR}/opntitle.dat
${CMAKE_CURRENT_SOURCE_DIR}/orig_extra.grf
)

# Done by the subdirectories, if nforenum / grfcodec is installed
if (NFORENUM_FOUND AND GRFCODEC_FOUND)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/openttd.grf PROPERTIES GENERATED TRUE)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/orig_extra.grf PROPERTIES GENERATED TRUE)

list(APPEND BASESET_BINARY_FILES openttd.grf)
list(APPEND BASESET_BINARY_FILES orig_extra.grf)
endif (NFORENUM_FOUND AND GRFCODEC_FOUND)

set(BASESET_EXTRAGRF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/orig_extra.grf)

# Walk over all the baseset files, and generate a command to configure them
foreach(BASESET_SOURCE_FILE IN LISTS BASESET_SOURCE_FILES)
get_filename_component(BASESET_SOURCE_FILE_NAME "${BASESET_SOURCE_FILE}" NAME)
set(BASESET_BINARY_FILE "${CMAKE_BINARY_DIR}/baseset/${BASESET_SOURCE_FILE_NAME}")

get_target_property(LANG_SOURCE_FILES language_files LANG_SOURCE_FILES)

add_custom_command_timestamp(OUTPUT ${BASESET_BINARY_FILE}
COMMAND ${CMAKE_COMMAND}
-DBASESET_SOURCE_FILE=${BASESET_SOURCE_FILE}
-DBASESET_BINARY_FILE=${BASESET_BINARY_FILE}
-DBASESET_EXTRAGRF_FILE=${BASESET_EXTRAGRF_FILE}
-P ${CMAKE_SOURCE_DIR}/cmake/scripts/Baseset.cmake
--
${LANG_SOURCE_FILES}
MAIN_DEPENDENCY ${BASESET_SOURCE_FILE}
DEPENDS ${LANG_SOURCE_FILES}
${BASESET_EXTRAGRF_FILE}
${CMAKE_SOURCE_DIR}/cmake/scripts/Baseset.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating ${BASESET_SOURCE_FILE_NAME} baseset metadata file"
)

list(APPEND BASESET_BINARY_FILES ${BASESET_BINARY_FILE})
endforeach(BASESET_SOURCE_FILE)

# Walk over all the other baseset files, and generate a command to copy them
foreach(BASESET_OTHER_SOURCE_FILE IN LISTS BASESET_OTHER_SOURCE_FILES)
get_filename_component(BASESET_OTHER_SOURCE_FILE_NAME "${BASESET_OTHER_SOURCE_FILE}" NAME)
set(BASESET_OTHER_BINARY_FILE "${CMAKE_BINARY_DIR}/baseset/${BASESET_OTHER_SOURCE_FILE_NAME}")

add_custom_command(OUTPUT ${BASESET_OTHER_BINARY_FILE}
COMMAND ${CMAKE_COMMAND} -E copy
${BASESET_OTHER_SOURCE_FILE}
${BASESET_OTHER_BINARY_FILE}
MAIN_DEPENDENCY ${BASESET_OTHER_SOURCE_FILE}
COMMENT "Copying ${BASESET_OTHER_SOURCE_FILE_NAME} baseset file"
)

list(APPEND BASESET_BINARY_FILES ${BASESET_OTHER_BINARY_FILE})
endforeach(BASESET_OTHER_SOURCE_FILE)

# Create a new target which generates all baseset metadata files
add_custom_target_timestamp(baseset_files
DEPENDS
${BASESET_BINARY_FILES}
)

add_library(basesets
INTERFACE
)
add_dependencies(basesets
baseset_files
)
add_library(openttd::basesets ALIAS basesets)
2 changes: 1 addition & 1 deletion media/baseset/no_music.obm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = NoMusic
shortname = NULL
version = 0
fallback = true
!! description STR_BASEMUSIC_NONE_DESCRIPTION
@description_STR_BASEMUSIC_NONE_DESCRIPTION@

[files]
theme =
Expand Down
2 changes: 1 addition & 1 deletion media/baseset/no_sound.obs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = NoSound
shortname = NULL
version = 2
fallback = true
!! description STR_BASESOUNDS_NONE_DESCRIPTION
@description_STR_BASESOUNDS_NONE_DESCRIPTION@

[files]
samples =
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions media/baseset/openttd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# In case both NFORenum and GRFCodec are found, generate the GRF.
# Otherwise, just use them from the cache (read: git).
# This is mainly because not many people have both of these tools installed,
# so it is cheaper to cache them in git, and only regenerate when you are
# working on it / have the tools installed.
if (NFORENUM_FOUND AND GRFCODEC_FOUND)
include(CreateGrfCommand REQUIRED)
create_grf_command()
endif (NFORENUM_FOUND AND GRFCODEC_FOUND)
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
4 changes: 2 additions & 2 deletions media/baseset/orig_dos.obg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = original_dos
shortname = TTDD
version = 1
palette = DOS
!! description STR_BASEGRAPHICS_DOS_DESCRIPTION
@description_STR_BASEGRAPHICS_DOS_DESCRIPTION@

[files]
base = TRG1.GRF
Expand All @@ -22,7 +22,7 @@ TRGI.GRF = da6a6c9dcc451eec88d79211437b76a8
TRGC.GRF = ed446637e034104c5559b32c18afe78d
TRGH.GRF = ee6616fb0e6ef6b24892c58c93d86fc9
TRGT.GRF = e30e8a398ae86c03dc534a8ac7dfb3b6
ORIG_EXTRA.GRF =
ORIG_EXTRA.GRF = ${ORIG_EXTRA_GRF_MD5}

[origin]
default = You can find it on your Transport Tycoon Deluxe CD-ROM.
Expand Down
2 changes: 1 addition & 1 deletion media/baseset/orig_dos.obm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name = original_dos
shortname = TTDD
version = 1
!! description STR_BASEMUSIC_DOS_DESCRIPTION
@description_STR_BASEMUSIC_DOS_DESCRIPTION@

[files]
theme = gm.cat
Expand Down
2 changes: 1 addition & 1 deletion media/baseset/orig_dos.obs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name = original_dos
shortname = TTDO
version = 0
!! description STR_BASESOUNDS_DOS_DESCRIPTION
@description_STR_BASESOUNDS_DOS_DESCRIPTION@

[files]
samples = SAMPLE.CAT
Expand Down
4 changes: 2 additions & 2 deletions media/baseset/orig_dos_de.obg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = original_dos_de
shortname = TTDD
version = 0
palette = DOS
!! description STR_BASEGRAPHICS_DOS_DE_DESCRIPTION
@description_STR_BASEGRAPHICS_DOS_DE_DESCRIPTION@

[files]
base = TRG1.GRF
Expand All @@ -22,7 +22,7 @@ TRGI.GRF = da6a6c9dcc451eec88d79211437b76a8
TRGC.GRF = ed446637e034104c5559b32c18afe78d
TRGH.GRF = ee6616fb0e6ef6b24892c58c93d86fc9
TRGT.GRF = fcde1d7e8a74197d72a62695884b909e
ORIG_EXTRA.GRF =
ORIG_EXTRA.GRF = ${ORIG_EXTRA_GRF_MD5}

[origin]
default = You can find it on your Transport Tycoon Deluxe CD-ROM.
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions media/baseset/orig_extra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# In case both NFORenum and GRFCodec are found, generate the GRF.
# Otherwise, just use them from the cache (read: git).
# This is mainly because not many people have both of these tools installed,
# so it is cheaper to cache them in git, and only regenerate when you are
# working on it / have the tools installed.
if (NFORENUM_FOUND AND GRFCODEC_FOUND)
include(CreateGrfCommand REQUIRED)
create_grf_command(
# We share some files with 'openttd' grf
${CMAKE_CURRENT_SOURCE_DIR}/../openttd/airports.png
${CMAKE_CURRENT_SOURCE_DIR}/../openttd/canals.png
${CMAKE_CURRENT_SOURCE_DIR}/../openttd/chars.png
)
endif (NFORENUM_FOUND AND GRFCODEC_FOUND)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
2 changes: 1 addition & 1 deletion media/baseset/orig_tto.obm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name = original_tto
shortname = TTOD
version = 1
!! description STR_BASEMUSIC_TTO_DESCRIPTION
@description_STR_BASEMUSIC_TTO_DESCRIPTION@

[files]
theme = gm-tto.cat
Expand Down
4 changes: 2 additions & 2 deletions media/baseset/orig_win.obg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = original_windows
shortname = TTDW
version = 0
palette = Windows
!! description STR_BASEGRAPHICS_WIN_DESCRIPTION
@description_STR_BASEGRAPHICS_WIN_DESCRIPTION@

[files]
base = TRG1R.GRF
Expand All @@ -22,7 +22,7 @@ TRGIR.GRF = 0c2484ff6be49fc63a83be6ab5c38f32
TRGCR.GRF = 3668f410c761a050b5e7095a2b14879b
TRGHR.GRF = 06bf2b7a31766f048baac2ebe43457b1
TRGTR.GRF = de53650517fe661ceaa3138c6edb0eb8
ORIG_EXTRA.GRF =
ORIG_EXTRA.GRF = ${ORIG_EXTRA_GRF_MD5}

[origin]
default = You can find it on your Transport Tycoon Deluxe CD-ROM.
Expand Down
2 changes: 1 addition & 1 deletion media/baseset/orig_win.obm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name = original_windows
shortname = TTDW
version = 1
!! description STR_BASEMUSIC_WIN_DESCRIPTION
@description_STR_BASEMUSIC_WIN_DESCRIPTION@

[files]
theme = GM_TT00.GM
Expand Down
2 changes: 1 addition & 1 deletion media/baseset/orig_win.obs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name = original_windows
shortname = TTDO
version = 0
!! description STR_BASESOUNDS_WIN_DESCRIPTION
@description_STR_BASESOUNDS_WIN_DESCRIPTION@

[files]
samples = SAMPLE.CAT
Expand Down
67 changes: 0 additions & 67 deletions media/baseset/translations.awk

This file was deleted.

Loading

0 comments on commit 85315e2

Please sign in to comment.