-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Update Simplified_Chinese.properties and Support +-*/%^ for mod-countable #13137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm sorry that I only submitted a rough code contribution this time, as I'm a beginner and not familiar with all of this. Apart from the translation updates, I was unable to correspondingly adjust the module documentation, module error checker, and the translation optimization within the brackets [] for the arithmetic extension feature. This challenging task is beyond my current capability, so I'll leave it to everyone else for now. |
update Unique-parameters.md
Well, we remember you as valuable modder and helper improving Unicode handling and such stuff, so welcome to a new challenge! Notes in no particular precedence:
All in all, respect, that's an ambitious first code PR. My notes don't mean to say "ditch this and start over" at all, more like 'food for thought' for you and the boss, let's hear more competent voices first... |
What I'm missing here is validation that a complex expression is correct |
Oh my gosh, your notes are way too advanced for me. It's like trying to get a primary school student to understand quantum mechanics.
I use IntelliJ IDEA Community Edition 2024.1.4
I will obey it next time.
Idk what happened and that's from my IDEA Itsel's change.
My bad, this is a leftover from the debugging process. Overall, I'm just an amateur programmer. In fact, my major is integrated circuit design, which involves building chips by assembling countless transistors, rather than writing program code. Many of your terms and theories are quite cutting-edge and difficult for me to understand. Thank you for your kind intentions. If you think there's anything inappropriate, please feel free to make changes as you see fit. |
I tested it, |
Oh my, way way too advanced for me. It's like trying to get a kindergarden toddler to understand quantum philosophy. 😆 Anyway, yes, but any learning curve always has parts where you can't see the next stretch around the next bend...
Yes, after cloning a new project I often do a conscious scan to look for any folders/files that need exclusions or type overrides and/or index exclusion1 and that the upstream might have forgotten or not known about because they use some other IDE. Basically any folder is suspect unless already excluded or you can guess how it has a part in the actual project sources or resources.
He means the UniqueParameterType should be able to verify the expressions compile or at least won't crash. Like Bobby Tables, you should treat mods as external input and defend against involuntary (or not) bad input endangering the app.
Nah, not that involved these days. I'm toying with LUA/C++ bindings at the moment, which means quite somewhere else. Footnotes |
I don't think you understand what I mean about validation. When a modder makes a mistake, we need to tell them as clearly as possible what the mistake was. I experimented previously with using exp4j for moddable complex math functions and that fell on validation as well, it's a tough problem, but one that's absolutely critical if we want to allow modders to input freeform equations |
That's not a problem, we could write a detailed doc file to tell modders how to use it, like this: ## countable
Indicates *something that can be counted*, used both for comparisons and for multiplying uniques
Allowed *simple* values:
- `year`, `turns`
- `Cities`, `[cityFilter] Cities`
- `City-States` - counts all undefeated city-states
- `Units`, `[mapUnitFilter] Units`
- `[buildingFilter] Buildings`
- `Remaining [civFilter] Civilizations`
- `Owned [tileFilter] Tiles`
- Stat name - gets the stat *reserve*, not the amount per turn (can be city stats or civilization stats, depending on where the unique is used)
- Resource name (can be city stats or civilization stats, depending on where the unique is used)
For example: If a unique is placed on a building, then the retrieved resources will be of the city. If placed on a policy, they will be of the civilization.
This can make a difference for e.g. local resources, which are counted per city.
Allowed *complex* values:
- `[complex value]`
- `[complex value] + [complex value]` - such as `[Cities] + 1`
- `[complex value] - [complex value]`
- `[complex value] * [complex value]`
- `[complex value] / [complex value]`
- `[complex value] % [complex value]`
- `[complex value] ^ [complex value]`
In addition, complex nested expressions can also be used, such as: `([Cities] + [turns]) * 2 + [Units]`. Note that the precedence of the 6 operations follows mathematical intuition: exponentiation(`^`) has the highest precedence, followed by multiplication(`*`), division(`/`), and modulus(`%`), and then addition(`+`) and subtraction(`-`) have the lowest precedence. If you need to adjust the precedence, please use parentheses.
Specifically, when calculating `n/0` or `n%0` , although these operations are meaningless, we still compute them as `0`.
|
That's not good enough. We need to be able to parse the expression and locate the problem, not just point modders at documentation. |
Let UniqueParameterType allow the correct complex Countables parameters
I'm really flustered... I couldn't understand what these words meant, and after clicking, I realized I had made a big mistake. I'm really sorry for cluttering everyone's notifications... This time, I have added support for the correct complex Countables parameters to UniqueParameterType, at least that's what I think I've done. |
When the countable parameter of the mod is invalid, the mod checker will throw an exception to inform the modder that this countable does not conform to the type. I think this prompt is very appropriate. What do you think? @yairm210 |
No :) If someone does "[A]++[B]", I want to indicate to them that the "++" is the problem. |
This task is too difficult for me at the moment.On the other hand,is it really cost-effective to make the mod checker so considerate that it teaches modders like a teacher?I think it is sufficient to get to the current stage.When modders write invalid parameters,they can ask questions on Discord and get corrected by others.We should assume that modders have such a level of literacy. |
I disagree :) |
Since this is basically a shunting yard implementation, we can separate the parse into 2 stages:
This is also better from a performance perspective, since currently, every time we want to evaluate the countable, we need to parse the tree from scratch. |
There are several hard parts here
When I say "AST" you can think of this as "reverse hungarian notation" if you want, then it's just list where each one corresponds to a function or a value and it's easy to iterate on |
Basic function for validating countables :) fun getCountableErrors(string:String, ruleset: Ruleset): List<String>{
// If this is a simple countable, we're done
if (UniqueParameterType.Countable.isKnownValue(string, ruleset)) return emptyList()
val countableTokens = string.getPlaceholderParameters()
val errorList = mutableListOf<String>()
for (token in countableTokens){
if (!UniqueParameterType.Countable.isKnownValue(string, ruleset))
errorList.add("\"$string\" contains the parameter \"$token\", which is not a valid countable")
}
// Check that all braces are matched
var openBraces = 0
for ((index,char) in string.withIndex()){
if (char == '(') openBraces += 1
if (char == ')') {
if (openBraces > 0) openBraces -= 1
else errorList.add("\"$string\" contains an unmatched closing brace at index $index")
}
}
return errorList
} IMO we should be using |
Although now that I examine it further, the current countable validity checks are sorely lacking - we only test if they fit the outer pattern, not the inner pattern |
No description provided.