Skip to content

Variables Removal #195

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public void didDidChangeVariable(ActionRegistry registry, Variable variable, int
fail("Implement me");
}

@Override
public void didRemoveVariable(ActionRegistry registry, Variable variable, int index) {
addResult(String.format("removed variable: %s (%d)", variable.getName(), index));
}

////////////////////////////////////////////////////////////////////////////////////////////////
// Helpers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ public void didDidChangeVariable(ActionRegistry registry, Variable variable, int
_delegate.actionRegistryFilterDidChangeVariable(this, variable, index);
}

@Override
public void didRemoveVariable(ActionRegistry registry, Variable variable, int index) {
if (isFiltering()) {
index = filteredArrayIndexOfEntry(_filteredVariables, variable);
if (index == -1) {
return;
}

variable = _filteredVariables.get(index);
_filteredVariables.remove(index);
}

_delegate.actionRegistryFilterDidRemoveVariable(this, variable, index);
}

////////////////////////////////////////////////////////////////////////////////////////////////
// Properties

Expand Down Expand Up @@ -243,5 +258,7 @@ public interface Delegate {
void actionRegistryFilterDidRegisterVariable(ActionRegistryFilter registryFilter, Variable variable, int index);

void actionRegistryFilterDidChangeVariable(ActionRegistryFilter registryFilter, Variable variable, int index);

void actionRegistryFilterDidRemoveVariable(ActionRegistryFilter registryFilter, Variable variable, int index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ public void actionRegistryFilterDidRegisterVariable(ActionRegistryFilter registr
public void actionRegistryFilterDidChangeVariable(ActionRegistryFilter registryFilter, Variable variable, int index) {
notifyDataChanged();
}
@Override
public void actionRegistryFilterDidRemoveVariable(ActionRegistryFilter registryFilter, Variable variable, int index) {
notifyDataChanged();
updateNoActionWarningView();
}

////////////////////////////////////////////////////////////////////////////////////////////////
// Data Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ public void updateVariable(int variableId, String value) {
}
}

public boolean removeVariable(int variableId) {
int index = indexOfVariable(variableId);
if (index != -1) {
Variable var = variables.objectAtIndex(index);
variables.removeObjectAtIndex(index);
notifyVariableRemove(var, index);
return true;
} else {
Log.e("Can't server cvar value: variable id %d not found", variableId);
}
return false;
}

public Variable findVariable(int variableId) {
int index = indexOfVariable(variableId);
return index != -1 ? variables.objectAtIndex(index) : null;
Expand Down Expand Up @@ -148,6 +161,12 @@ private void notifyVariableChange(Variable cvar, int index) {
}
}

private void notifyVariableRemove(Variable cvar, int index){
if(delegate != null){
delegate.didRemoveVariable(this, cvar, index);
}
}

//region Getters/Setters

public List<Action> getActions()
Expand Down Expand Up @@ -185,6 +204,8 @@ public interface Delegate // FIXME: rename
void didRegisterVariable(ActionRegistry registry, Variable variable, int index);

void didDidChangeVariable(ActionRegistry registry, Variable variable, int index);

void didRemoveVariable(ActionRegistry registry, Variable variable, int index);
}

//endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ public void updateVariable(int variableId, String value) {
actionRegistry.updateVariable(variableId, value);
}

public void removeVariable(int variableId){
actionRegistry.removeVariable(variableId);
}

@Override
public void destroy() {
removeConsoleView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ protected void execute() {
});
}

public static void removeVariable(final int variableId){
dispatchQueue.dispatch(new DispatchTask() {
@Override
protected void execute() {
plugin.removeVariable(variableId);
}
});
}

public static void destroy() {
dispatchQueue.dispatch(new DispatchTask("destroy plugin") {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ extern NSString * const LUConsoleCheckFullVersionNotificationSource;
- (LUCVar *)registerVariableWithId:(int)entryId name:(NSString *)name type:(NSString *)type value:(NSString *)value defaultValue:(NSString *)defaultValue values:(NSArray<NSString *> *)values;
- (void)setValue:(NSString *)value forVariableWithId:(int)variableId;

- (void)removeVariableWithId:(int)variableId;

- (void)enableGestureRecognition;
- (void)disableGestureRecognition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ - (void)setValue:(NSString *)value forVariableWithId:(int)variableId
[_actionRegistry setValue:value forVariableWithId:variableId];
}

- (void)removeVariableWithId:(int)actionId
{
[_actionRegistry removeVariableWithId:actionId];
}

#pragma mark -
#pragma mark Warnings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ OBJC_EXTERN void __lunar_console_action_unregister(int actionId);
// variables
OBJC_EXTERN void __lunar_console_cvar_register(int entryId, const char *name, const char *type, const char *value, const char *defaultValue, int flags, BOOL hasRange, float min, float max, const char *values);
OBJC_EXTERN void __lunar_console_cvar_update(int entryId, const char *value);
OBJC_EXTERN void __lunar_console_cvar_remove(int variableId);

#endif /* defined(__LunarConsole__unity_native_interface__) */
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,14 @@ void __lunar_console_cvar_update(int entryId, const char *valueStr)
[_lunarConsolePlugin setValue:value forVariableWithId:entryId];
});
}

void __lunar_console_cvar_remove(int variableId)
{
if ([NSThread isMainThread]) {
[_lunarConsolePlugin removeVariableWithId:variableId];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[_lunarConsolePlugin removeVariableWithId:variableId];
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- (void)actionRegistry:(LUActionRegistry *)registry didRemoveAction:(LUAction *)action atIndex:(NSUInteger)index;
- (void)actionRegistry:(LUActionRegistry *)registry didRegisterVariable:(LUCVar *)variable atIndex:(NSUInteger)index;
- (void)actionRegistry:(LUActionRegistry *)registry didDidChangeVariable:(LUCVar *)variable atIndex:(NSUInteger)index;
- (void)actionRegistry:(LUActionRegistry *)registry didRemoveVariable:(LUCVar *)variable atIndex:(NSUInteger)index;

@end

Expand All @@ -54,5 +55,6 @@
- (LUCVar *)registerVariableWithId:(int)variableId name:(NSString *)name typeName:(NSString *)type value:(NSString *)value defaultValue:(NSString *)defaultValue values:(NSArray<NSString *> *)values;
- (void)setValue:(NSString *)value forVariableWithId:(int)variableId;
- (LUCVar *)variableWithId:(int)variableId;
- (BOOL)removeVariableWithId:(int)variableId;

@end
9 changes: 5 additions & 4 deletions Native/iOS/LunarConsole/LunarConsole/Common/Lunar.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#import "LUConsoleLogEntryLookupTable.h"
#import "LUConsoleLogEntryTableViewCell.h"
#import "LUConsoleLogMenuController.h"
#import "LULogMessage.h"
#import "LUUIHelper.h"
#import "LUEnumPickerViewController.h"
#import "LUPluginSettings.h"
#import "LUNotificationCenter.h"
#import "LUConsoleLogTypeButton.h"
#import "LUConsolePlugin.h"
#import "LUConsolePopupController.h"
Expand All @@ -43,19 +48,15 @@
#import "LUCVar.h"
#import "LUEntry.h"
#import "LUEntryTableViewCell.h"
#import "LUEnumPickerViewController.h"
#import "LUExceptionWarningController.h"
#import "LULogMessage.h"
#import "LUPanViewGestureRecognizer.h"
#import "LUPassTouchView.h"
#import "LUPluginSettings.h"
#import "LUSlider.h"
#import "LUSwitch.h"
#import "LUTableView.h"
#import "LUTextField.h"
#import "LUTheme.h"
#import "LUToggleButton.h"
#import "LUUIHelper.h"
#import "LUUnityScriptMessenger.h"
#import "LUViewController.h"
#import "LUWindow.h"
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ - (void)actionRegistryFilter:(LUActionRegistryFilter *)registry didChangeVariabl
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
}

- (void)actionRegistryFilter:(LUActionRegistryFilter *)registry didRemoveVariable:(LUCVar *)variable atIndex:(NSUInteger)index;
{
NSArray *array = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:kSectionIndexVariables]];
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];

[self updateNoActionWarningView];
}

#pragma mark -
#pragma mark Actions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ - (LUCVar *)registerVariableWithId:(int)variableId name:(NSString *)name typeNam
return variable;
}

- (BOOL)removeVariableWithId:(int)variableId
{
NSUInteger index = [self indexOfVariableWithId:variableId];
if (index != NSNotFound)
{
LUCVar *cvar = [_variables objectAtIndex:index];
[_variables removeObjectAtIndex:index];
[_delegate actionRegistry:self didRemoveVariable:cvar atIndex:index];
return YES;
}
else
{
NSLog(@"Can't server cvar value: variable id %d not found", variableId);
}

return NO;
}

- (void)setValue:(NSString *)value forVariableWithId:(int)variableId
{
NSUInteger index = [self indexOfVariableWithId:variableId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- (void)actionRegistryFilter:(LUActionRegistryFilter *)registryFilter didRemoveAction:(LUAction *)action atIndex:(NSUInteger)index;
- (void)actionRegistryFilter:(LUActionRegistryFilter *)registry didRegisterVariable:(LUCVar *)variable atIndex:(NSUInteger)index;
- (void)actionRegistryFilter:(LUActionRegistryFilter *)registry didChangeVariable:(LUCVar *)variable atIndex:(NSUInteger)index;
- (void)actionRegistryFilter:(LUActionRegistryFilter *)registry didRemoveVariable:(LUCVar *)variable atIndex:(NSUInteger)index;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ - (void)actionRegistry:(LUActionRegistry *)registry didDidChangeVariable:(LUCVar
[_delegate actionRegistryFilter:self didChangeVariable:variable atIndex:index];
}

- (void)actionRegistry:(LUActionRegistry *)registry didRemoveVariable:(LUCVar *)variable atIndex:(NSUInteger)index
{
if (self.isFiltering)
{
index = [self filteredArray:_filteredVariables indexOfEntry:variable];
if (index == NSNotFound)
{
return;
}

variable = [_filteredVariables objectAtIndex:index];
[_filteredVariables removeObjectAtIndex:index];
}

[_delegate actionRegistryFilter:self didRemoveVariable:variable atIndex:index];
}

#pragma mark -
#pragma mark Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ class LUActionRegistryFilterTest: TestCase, LUActionRegistryFilterDelegate {
XCTFail("Implement me")
}

func actionRegistryFilter(_ registry: LUActionRegistryFilter!, didRemoveVariable variable: LUCVar!, at index: UInt) {
addResult("removed variable: \(variable.name!) (\(index))")
}

// MARK: - Helpers

@discardableResult
Expand Down
10 changes: 10 additions & 0 deletions Native/iOS/LunarConsole/LunarConsoleTests/LUActionRegistryTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ - (void)actionRegistry:(LUActionRegistry *)registry didDidChangeVariable:(LUCVar
XCTFail(@"Implement me");
}

- (void)actionRegistry:(LUActionRegistry *)registry didRemoveVariable:(LUCVar *)variable atIndex:(NSUInteger)index
{
[self addResult:[NSString stringWithFormat:@"removed variable %@ (%d)", variable.name, (int) index]];
}

#pragma mark -
#pragma mark Helpers

Expand Down Expand Up @@ -190,6 +195,11 @@ - (void)unregisterActionWithId:(int)actionId
[_actionRegistry unregisterActionWithId:actionId];
}

- (void)removeVariableWithId:(int)variableId
{
[_actionRegistry removeVariableWithId:variableId];
}

- (BOOL)unregisterActionWithName:(NSString *)name
{
for (LUAction* action in _actionRegistry.actions)
Expand Down