Qwen2.5-Max
This is a great refinement to ensure that dynooverse respects existing custom descriptions and only modifies systems with default descriptions. To achieve this, you can implement a mechanism to detect whether a system's description matches the default pattern or has already been customized by another mod or script.
Here’s how you can approach this:
1. Understand Default Descriptions
Default system descriptions in Oolite typically follow a predictable pattern, such as:
"Agricultural colony"
"Industrial hub"
"Sparse asteroid field"
These descriptions are usually short and generic. If a mod has already replaced the description with something more detailed or unique, dynooverse should leave it untouched.
2. Solution: Detect Default Descriptions
You can use a regular expression (regex) to identify default descriptions based on their patterns. For example:
Default descriptions often include keywords like "agricultural," "industrial," "sparse," "rich," etc.
They are usually short and lack complex phrasing.
By defining a regex pattern that matches default descriptions, you can check whether a system's description matches the pattern before modifying it.
3. Implementation
Step 1: Define a Regex for Default Descriptions
Create a regex pattern that captures the characteristics of default descriptions. For example:
javascript
Copy
1
const defaultDescriptionPattern = /^(Agricultural|Industrial|Sparse|Rich|Poor|Mainly)\b/;
This pattern matches descriptions starting with common keywords like "Agricultural," "Industrial," "Sparse," etc.
The \b ensures that the match is at a word boundary, avoiding partial matches.
Step 2: Check Before Modifying
Before updating a system's description, check if its current description matches the default pattern. Only proceed with the update if it does.
Update the case 5 block in dayChanged as follows:
javascript
Copy
1
2
3
4
5
6
7
8
9
10
11
⌄
⌄
case 5: // Description
let oldDescription = sys.description;
// Check if the description matches the default pattern
if (defaultDescriptionPattern.test(oldDescription)) {
sys.description = this._viceRegalNotices();
this._sendMessage(sysID, sys.name, "Description", oldDescription, sys.description);
} else {
log(this.name, `Skipping description update for ${sys.name} (${sysID}): Custom description detected.`);
}
break;
Step 3: Log Skipped Updates
The log statement ensures that you can track when a description update is skipped due to a custom description being present. This is useful for debugging and verifying the behavior of the script.
4. Example Walkthrough
Case 1: Default Description
If a system's description is "Agricultural colony":
The regex matches because it starts with "Agricultural."
dynooverse generates a new description using _viceRegalNotices and updates the system.
Case 2: Custom Description
If a system's description is "The thriving trade hub of Lave":
The regex does not match because it does not start with a default keyword.
dynooverse skips the update and logs:
Copy
1
Skipping description update for Lave (131): Custom description detected.
5. Refinements
5.1 Expand the Regex
If the default descriptions in your game universe vary significantly, you can expand the regex to include more patterns. For example:
javascript
Copy
1
const defaultDescriptionPattern = /^(Agricultural|Industrial|Sparse|Rich|Poor|Mainly|Rocky|Dusty|Barren|Fertile)\b/;
5.2 Allow Whitelisting
If you want to explicitly allow certain mods or scripts to modify descriptions while still protecting others, you could maintain a whitelist of allowed prefixes or keywords. For example:
javascript
Copy
1
2
3
4
5
6
⌄
const allowedPrefixes = ["CustomMod:", "Dynooverse:"];
if (!allowedPrefixes.some(prefix => oldDescription.startsWith(prefix)) &&
defaultDescriptionPattern.test(oldDescription)) {
sys.description = this._viceRegalNotices();
this._sendMessage(sysID, sys.name, "Description", oldDescription, sys.description);
}
5.3 Preserve Custom Descriptions
If you later decide to allow dynooverse to append to custom descriptions instead of overwriting them, you can modify the logic accordingly:
javascript
Copy
1
2
3
4
5
⌄
⌄
if (defaultDescriptionPattern.test(oldDescription)) {
sys.description = this._viceRegalNotices(); // Replace default descriptions
} else {
sys.description += " " + this._viceRegalNotices(); // Append to custom descriptions
}
6. Final Code Snippet
Here’s the updated case 5 block with the refinement:
javascript
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
⌄
⌄
case 5: // Description
let oldDescription = sys.description;
// Regex to detect default descriptions
const defaultDescriptionPattern = /^(Agricultural|Industrial|Sparse|Rich|Poor|Mainly)\b/;
// Check if the description matches the default pattern
if (defaultDescriptionPattern.test(oldDescription)) {
sys.description = this._viceRegalNotices();
this._sendMessage(sysID, sys.name, "Description", oldDescription, sys.description);
} else {
log(this.name, `Skipping description update for ${sys.name} (${sysID}): Custom description detected.`);
}
break;
7. Benefits of This Approach
Respect for Mods :
Other mods or scripts that replace system descriptions will not be overwritten, preserving their contributions.
Selective Updates :
Only systems with default descriptions are modified, ensuring consistency with the intended behavior of dynooverse .
Extensibility :
The regex can be easily expanded or adjusted to accommodate additional default patterns.
Transparency :
Logging skipped updates provides visibility into the script's behavior, making it easier to debug or verify.
8. Conclusion
This refinement ensures that dynooverse interacts gracefully with other mods and scripts while still achieving its goal of dynamically enhancing system descriptions. By using a regex to detect default descriptions, you can selectively apply changes without disrupting custom content.
Let me know if you’d like further assistance or have additional ideas for refining dynooverse ! Once you're ready to return to Middlemap , I’ll be happy to help with that as well.
