Skip to content

feat: Add optional defaultValue parameter to GetGlobalVariable#12

Merged
hacha merged 7 commits intodevelopfrom
claude/issue-7-20250813-0434
Aug 13, 2025
Merged

feat: Add optional defaultValue parameter to GetGlobalVariable#12
hacha merged 7 commits intodevelopfrom
claude/issue-7-20250813-0434

Conversation

@from2001
Copy link
Collaborator

Add overloaded method GetGlobalVariable(string name, string defaultValue = null)

  • Implemented in both NetSyncManager and NetworkVariableManager
  • Maintains backward compatibility with existing method signature
  • Returns defaultValue when variable doesn't exist in global variables

Resolves #7

🤖 Generated with Claude Code

- Add overloaded method GetGlobalVariable(string name, string defaultValue = null)
- Implemented in both NetSyncManager and NetworkVariableManager
- Maintains backward compatibility with existing method signature
- Returns defaultValue when variable doesn't exist in global variables

Resolves #7

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Masahiro Yamaguchi <from2001@users.noreply.github.com>
@from2001
Copy link
Collaborator Author

@claude
Implement the defaultValue for GetClientVariable as well.
GetClientVariable is located at both NetSyncManager and NetSyncAvatar.

@claude
Copy link
Contributor

claude bot commented Aug 13, 2025

Claude finished @from2001's task —— View job


Implementation completed successfully!

Todo List

  • Read current PR changes to understand implementation pattern
  • Locate GetClientVariable methods in NetSyncManager
  • Locate GetClientVariable methods in NetSyncAvatar
  • Implement overloaded GetClientVariable methods with defaultValue parameter
  • Commit and push changes
  • Update final status

Changes Made

Added defaultValue parameter to all GetClientVariable methods following the same pattern as GetGlobalVariable:

NetworkVariableManager.cs (lines 141-148)

public string GetClientVariable(int clientNo, string name, string defaultValue = null)
{
    if (_clientVariables.TryGetValue(clientNo, out var clientVars))
    {
        return clientVars.TryGetValue(name, out var value) ? value : defaultValue;
    }
    return defaultValue;
}

NetSyncManager.cs (lines 109-112)

public string GetClientVariable(int clientNo, string name, string defaultValue = null)
{
    return _networkVariableManager?.GetClientVariable(clientNo, name, defaultValue) ?? defaultValue;
}

NetSyncAvatar.cs (lines 355-358, 379-382)

  • Added overload for owner client: GetClientVariable(string name, string defaultValue = null)
  • Added overload for specific client: GetClientVariable(int clientNo, string name, string defaultValue = null)

Key Features

  • Backward compatibility - existing method signatures unchanged
  • Consistent pattern - follows same approach as GetGlobalVariable
  • Complete coverage - all GetClientVariable methods now support default values
  • Thread-safe - leverages existing thread-safe implementations

The implementation returns the defaultValue when the requested client variable doesn't exist, maintaining consistency with the existing GetGlobalVariable behavior.

- Added overloaded GetClientVariable(int clientNo, string name, string defaultValue) to NetworkVariableManager
- Added overloaded GetClientVariable(int clientNo, string name, string defaultValue) to NetSyncManager
- Added overloaded GetClientVariable(string name, string defaultValue) and GetClientVariable(int clientNo, string name, string defaultValue) to NetSyncAvatar
- Maintains backward compatibility with existing method signatures
- Follows same pattern as GetGlobalVariable with defaultValue parameter

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Masahiro Yamaguchi <from2001@users.noreply.github.com>
@from2001 from2001 requested a review from Copilot August 13, 2025 04:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds optional default value support to variable getter methods in the NetSync system. The changes provide fallback values when requested variables don't exist, improving the robustness of variable access patterns.

  • Adds overloaded methods with defaultValue parameters to GetGlobalVariable and GetClientVariable methods
  • Implements the feature across all relevant classes in the NetSync hierarchy
  • Maintains backward compatibility with existing method signatures

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
NetSyncManager.cs Adds overloaded methods for getting global and client variables with default values
NetSyncAvatar.cs Extends client variable getter methods to support default values with documentation
NetworkVariableManager.cs Implements core logic for default value handling in the underlying variable storage

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

from2001 and others added 4 commits August 13, 2025 13:52
…etSyncManager.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…etSyncManager.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…etSyncAvatar.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…etSyncAvatar.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@from2001
Copy link
Collaborator Author

@claude
You implemented overloaded methods, but adding default value to the existing code is good enough. Refactor the code.

@claude
Copy link
Contributor

claude bot commented Aug 13, 2025

Claude finished @from2001's task —— View job


Todo List

  • Read current implementation to understand the changes
  • Refactor NetworkVariableManager to use default parameters
  • Refactor NetSyncManager to use default parameters and remove redundant operators
  • Refactor NetSyncAvatar to use default parameters and remove redundant operators
  • Commit and push changes
  • Update final status

Refactoring Complete!

Successfully refactored the code to use default parameters instead of overloaded methods:

Changes Made

NetworkVariableManager.cs:

  • Removed overloaded GetGlobalVariable(string name) method
  • Added defaultValue = null parameter to existing GetGlobalVariable method
  • Removed overloaded GetClientVariable(int clientNo, string name) method
  • Added defaultValue = null parameter to existing GetClientVariable method

NetSyncManager.cs:

  • Removed overloaded GetGlobalVariable(string name) method
  • Added defaultValue = null parameter to existing method
  • Removed overloaded GetClientVariable(int clientNo, string name) method
  • Added defaultValue = null parameter to existing method
  • Eliminated redundant null-coalescing operators as suggested in review comments

NetSyncAvatar.cs:

  • Removed overloaded GetClientVariable(string name) method (owner client)
  • Added defaultValue = null parameter to existing method
  • Removed overloaded GetClientVariable(int clientNo, string name) method (specific client)
  • Added defaultValue = null parameter to existing method

Benefits

  • Cleaner API - Single method per function instead of overloads
  • Backward compatibility - Existing code continues to work
  • Follows C# best practices - Default parameters preferred over overloads when possible
  • Addresses review feedback - Removed redundant null-coalescing operators

The refactored code maintains the same functionality while providing a simpler, more maintainable API.


…t*Variable

- Removed overloaded methods and added default parameters to existing methods
- Eliminated redundant null-coalescing operators as suggested in review
- Maintains backward compatibility while simplifying the API

Co-authored-by: Masahiro Yamaguchi <from2001@users.noreply.github.com>
@hacha
Copy link
Collaborator

hacha commented Aug 13, 2025

LGTM

@hacha hacha merged commit 4e681d4 into develop Aug 13, 2025
@hacha hacha deleted the claude/issue-7-20250813-0434 branch August 13, 2025 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support default value in GetGlobalVariable()

3 participants