47 Commits

Author SHA1 Message Date
dumb-kevin 77a999f2fa Mark TU-local helper templates static
- use_amount_stack template in map.cpp is only used inside the TU
- npc_pickup_from_stack template in npcmove.cpp is only used inside the TU
- silences misc-use-internal-linkage
2026-05-09 10:02:28 +04:00
dobbry-vechur 97067ca137 Use Catch::Matchers:: namespace for all test matchers (#85907) 2026-03-18 08:04:02 -05:00
Anton Simakov 1a0cc453dc Validate spell classes, targeted monster ids and species (#84439)
* Validate spell classes, targeted monster ids and species

* fix the check

* update code and tests

* Fix
2026-01-05 22:56:13 -06:00
salartarium fe7e2db864 Fix basic typos in code and comments (#83903)
* Update magic.cpp

fix typo

* Update OVERMAP.md

fix typo

* Update util.py

fix typo

* Update json_test.cpp

fix typos in comments and code

* Update 7.50mm.json

fix typo

* Update PowerDescriptionSpoilers.md

fix typo

* Update scavbots.json

fix typo

* Update tests/json_test.cpp

change the name in the declaration

Co-authored-by: Fris0uman <41293484+Fris0uman@users.noreply.github.com>

* Update tests/json_test.cpp

formatting

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Fris0uman <41293484+Fris0uman@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-11-27 09:33:58 +01:00
ehughsbaird 55556a3d5f units::temperature serialize and deserialize units
Serialize and deserialize units::temperature values as degrees celsius
offset from 0 degrees celsius. This means that temperature values are
saved with milli degrees celsius precision, which should not be plenty.

Add a round trip test to load/save/load units::temperature values and
ensure the in-memory values are not affected, and all the formats are
supported.

The legacy format "\"%f\"" needs to be supported because it exists in
save files as part of bodypart temperature calculations.
2025-09-23 13:55:58 +00:00
andrei 70f9c26037 eoc: merge variable helper structs
and prepare it for generic_factory
2025-08-31 13:16:12 +03:00
ehughsbaird 14ef051255 Allow serializing tripoints as map keys
Maps often require custom serialization code, as they only understand a
limited set of types as their keys.

Expand the set of allowed types to include tripoints by adding a
key_from_json_string specialization for types with a to_string_writeable
function, that writes the value as a string suitable for
serialization/deserialization.

Also add a JsonOut::write_as_string specialization for types with this
to_string writeable, as these are required for
deserialization/serialization respectively.

Add a limited set of test cases for this. There could be more, but the
rest should be covered by more specific test cases.

Also add a <typed_tripoint>::from_string, as is necessary for the
key_from_json_string specialization to easily encompass more than
untyped points.
2025-07-05 18:30:48 +00:00
RenechCDDA 3366eed9f5 Improve error reporting (#79381)
* Improve error reporting
-JSON syntax errors say they are syntax errors, to help people understand how to resolve them.
-The line and character offset of JSON errors has been made explicit, instead of requiring you to guess what the numbers mean.
-The C++ source file names/etc were made more explicit as well, which should hopefully reduce people asking "I can't find this .cpp file on my game, where is it"

* Update tests to new error messages
2025-02-24 08:02:16 +01:00
Bates Brodie 01def1e20a Add magic energy type field to magic type and add chronomancy 2025-01-05 22:46:45 -08:00
Andrew Krieger 67c1ad039a Categorically fix type issues with restore_on_out_of_scope 2024-12-09 21:51:35 -08:00
Jianxiang Wang (王健翔) ca7a489349 Add check to ensure translator comments are correctly located and extracted (#70897) 2024-01-17 15:37:24 +03:00
Alexey c011e9de12 Improve output for JSON errors (#66623)
* Colorize JSON errors

* Make formatter feed source filename to TextJsonIn

* Throw exception instead of dumping output to std::cerr

* Adjust math parser's caret appearance

* Set color in chkjson

* Adjust tests and formatters

* Add json error cursor check for unicode string

* Squelch global state lint for entry points

* Adjust stream offset so the buffer for utf8_width is pointing at a codepoint
2023-07-17 19:51:50 -05:00
Alexey 07356b65a5 Normalize TEST_CASE names (#66241)
* Convert integer parsing test to use normal TEST_CASEs

* Rename test name too similar to another

* Test to enforce normalized test names

* Normalize TEST_CASE names (scripted)
2023-06-17 13:57:19 -03:00
David Seguin 6141f7651e damage_type: jsonify damage types
It turns out that a lot of loading code depends on
the availability of certain damage types.

I see two ways to resolve this:
1) Juggle the loading order of JSON types so that damage
   types always load first.
2) Add deferred processing for every type with inline
   damage type definitions.

I went with option 2, which is better but still
not great since new code that loads damage/resistance
definitions would need to also call finalize_damage_map
in the finalizing stage. Option 1 would cause problems
for mods, especially because the load order would matter.

None of this can be done piecemeal, it has to all be ripped
out in one go unless we want commits that don't compile
on their own.
2023-04-24 01:38:15 -04:00
John Bytheway 89171fb202 Convert lots more things to string_view
These are mostly automated changes.  My automation tries to be
conservative, but I did have to do manual fixup of a few things.

I plan to PR the clang-tidy check that automates these changes later,
but I think more changes may be needed before that.

Some of the manual changes:
- Added svto<T> where T is an integer type, which parses integers in
  string_views.  This is our first use of the low-level C++17 int
  conversion functions.
- Added a shortcut to lcmatch for empty queries, to allow for
  refactoring overmapbuffer searches.
- Fixed an apparent bug in overmapbuffer::get_notes and get_extras,
  where it was inverting the match result.  As far as I can tell, these
  functions aren't actually used anywhere, so I guess this bug wasn't
  breaking anything.
- Allow use of string_view in JSON serialization.  Previously these were
  misidentified as sequences and appeared as a list of integers rather
  than a string.
2023-04-20 19:57:23 -04:00
Eric b411b72968 Allow spells to use dialog variables. (#64416) 2023-03-23 18:55:20 -07:00
Binrui Dong 32774b37da Migrate from cata::optional<T> to std::optional<T> (#64333)
Co-authored-by: Kevin Granade <kevin.granade@gmail.com>
2023-03-20 20:11:23 -07:00
akrieger 85e14ddd64 Improve FlexbufferJson parser error messaging. 2022-11-05 14:34:05 -07:00
akrieger e97415e789 Convert everything to json_loader from JsonValue::from_* 2022-09-15 22:04:55 -07:00
akrieger cb636bfee1 Fix test runtime failures. 2022-09-15 22:04:55 -07:00
akrieger 898708829f Fix test compilation 2022-09-15 22:04:54 -07:00
akrieger 3b22d13aa9 Move scope helpers to cata_scope_helpers.h 2022-09-15 22:04:51 -07:00
John Bytheway d4e5c54b08 Reorder JSON error function params (#58584)
The various JSON error functions tended to have a signature where the
error message string was followed by an optional string member name
and/or an optional integer offset.

This made it really easy to accidentally think that the functions
supported string formatting, if you added an extra string and/or int,
and it compiled.  But this was not so.

I made this mistake in #58527 and I've made it before.  As part of this
overhaul I found several places where this mistake persisted in the
codebase.

We can prevent this confusion by re-ordering the arguments to these
functions so that the error message is always last.

Do that, and fix the mistakes discovered along the way.

Remove one overload that was never used (using member name and offset).
2022-06-26 10:22:57 -04:00
Jianxiang Wang (王健翔) d7863be2b0 Clarify plural check message (#57786) 2022-05-18 15:15:27 -04:00
John Bytheway e95a4fc9b8 Promote string_id constants to global statics
Our string_id constants were a mixture of temporaries, locals, and
globals.  Pull them all out as globals, for consistency and efficiency.
The efficiency comes from the fact that each string_id instance caches
its respective int_id, and sharing one instance means that value need
not be recomputed.
2021-11-19 19:10:09 -05:00
Eric 836256a7d6 Use dialog conditions for mutation and enchantment triggers (#51726)
* Handle enchantment part

* Replace triggers with dialog conditions

Co-authored-by: Curtis Merrill <curtis.r.merrill@gmail.com>
2021-09-26 11:07:45 -07:00
Jianxiang Wang (王健翔) a11d8cf5ac Add code to check for irregular plural forms (#51259) 2021-09-11 07:49:42 -07:00
John Bytheway 42affda205 Fix a couple of serialization bugs
Two issues with serialization:
- If the entire stream was just a single integer then it would cause an
  infinite loop when reading.
- When reading a sequence of optionals, if one optional was empty, it
  would cause the sequence to grow until memory was exhausted without
  ever consuming that input.

Fix both these issues, and add unit tests.
2021-07-23 15:42:34 -04:00
John Bytheway ebd549b300 Fix StringMaker ODR violations in tests
Catch2 provides a customization point for converting our types to
strings by specializing the StringMaker template.

We have some specializations in stringmaker.h, but this feature was only
working intermittently.  I finally figured out that was due to an ODR
violation.  The test files that didn't include stringmaker.h were
compiling a different specialization than the ones that did.

Re-jig the test includes so that any file including catch.hpp also
includes stringmaker.h, thereby ensuring that the custom
specializations are used everywhere and there is no ODR violation.

I achieved this by adding a new cata_catch.h header and making all
existing headers include catch.hpp via the new header.
2021-07-03 07:42:06 -07:00
Binrui Dong 9fdb7ef59c Run IWYU
* Change _ctype.h and __locale to cctype and clocale

* Change _wctype.h to cwctype in game.cpp

* Change __functional_base to functional

* Remove libcxx internal headers

* Remove UNIX system headers

* Fix clang-tidy error with -nostdinc++
2021-02-06 00:18:41 -05:00
Ivan Zaitsev 6c4a9ebf6b Add RLE compression for json ser/deser of colony<item> (#46837)
* add RLE compression for json ser/deser of colony<item>

Co-authored-by: Jianxiang Wang (王健翔) <qrox@sina.com>
2021-01-19 13:45:22 +03:00
Qrox 493f6d4e83 Display multi-line error messages with github action 2020-12-31 15:01:53 +08:00
KorGgenT 37222e361e Refactor spell_type to use a shape enum for spell aoe 2020-10-05 01:19:13 -04:00
Qrox ed8a24fe82 Add more translation deserialization unit test cases 2020-10-01 12:23:27 +08:00
Curtis Merrill fef97d9058 refactor push/pull effects to be more general (#44441)
* refactor push/pull effects to be more general

* take two passes to move fields
2020-09-30 13:33:36 +03:00
ZhilkinSerg 62f4df63d6 Merge pull request #44278 from Qrox/json-error-caret
Properly handle escape sequence and unicode sequence when generating json text style error message
2020-09-24 09:34:49 +03:00
Qrox d8cb67907f Fix incorrect stream position after translation text style check debug message, and incorrect rewind logic 2020-09-21 23:10:31 +08:00
Qrox fa1323434b Fix crash in StringLiteralIterator.cpp and suppress text style check in json_test.cpp 2020-09-20 14:44:27 +08:00
Qrox ac4082f530 Add unit test for json string reading, error/debugmsg when reading string, and debugmsg when reading translatable string 2020-09-20 10:07:51 +08:00
KorGgenT 89e3dcfea8 update avoid_serializing_default_values to use const std::string 2020-09-17 18:46:56 -04:00
KorGgenT 171b31ebb1 write tests for spell_type::serialize 2020-09-17 18:46:56 -04:00
Curtis Merrill e1277a9f38 don't write default values in json: implementation (#44059) 2020-09-08 18:20:12 -07:00
Fris0uman 98f32ab0a3 Replace some body_part with bodypart_id (#42677) 2020-08-16 16:16:05 +03:00
Kevin Granade c5ccf0c2c7 IWYU for tests (#42806) 2020-08-09 09:46:57 +03:00
Kevin Granade 6d1841ac67 Precompiled Catch2 header (#42453)
* Hoist catch.hpp include to the top of files

* Precompile the catch header in tests
2020-07-29 01:28:26 +03:00
John Bytheway e189957ff2 Run IWYU 20200408 (#39364)
* Helper script to run IWYU

* Run IWYU

* Update deprecated headers

* Run IWYU again

* Re-suppress cxxabi.h

This pragma got accidentally removed because it was deemed to be a
comment attached to a #include.

* Remove extra SDL header includes

* Fix ime.cpp headers

Some tweaks to help IWYU not break this file by messing with
platform-specific stuff not relevant on Linux.

* Update game.h

* Move new point.h includes inside #ifdef

* Re-add platform_win.h to mapsharing.cpp

* Apply suggestions from code review

Co-authored-by: ZhilkinSerg <ZhilkinSerg@users.noreply.github.com>
2020-04-10 12:16:19 +03:00
John Bytheway 624b18306f Tests for STL container serialization 2019-09-01 14:33:26 -04:00