mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
🆕 Added wired wf_slc_furni_bytype
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ConditionDefinition, OpenMessageComposer, Triggerable, TriggerDefinition, UpdateActionMessageComposer, UpdateConditionMessageComposer, UpdateTriggerMessageComposer, WiredActionDefinition, WiredFurniActionEvent, WiredFurniConditionEvent, WiredFurniTriggerEvent, WiredOpenEvent, WiredSaveSuccessEvent } from '@nitrots/nitro-renderer';
|
||||
import { ConditionDefinition, GetRoomEngine, GetSessionDataManager, OpenMessageComposer, RoomObjectCategory, RoomObjectVariable, Triggerable, TriggerDefinition, UpdateActionMessageComposer, UpdateConditionMessageComposer, UpdateTriggerMessageComposer, WiredActionDefinition, WiredFurniActionEvent, WiredFurniConditionEvent, WiredFurniTriggerEvent, WiredOpenEvent, WiredSaveSuccessEvent } from '@nitrots/nitro-renderer';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useBetween } from 'use-between';
|
||||
import { IsOwnerOfFloorFurniture, LocalizeText, SendMessageComposer, WiredFurniType, WiredSelectionVisualizer } from '../../api';
|
||||
import { GetRoomSession, IsOwnerOfFloorFurniture, LocalizeText, SendMessageComposer, WiredFurniType, WiredSelectionVisualizer } from '../../api';
|
||||
import { useMessageEvent } from '../events';
|
||||
import { useNotification } from '../notification';
|
||||
|
||||
@@ -13,6 +13,8 @@ const useWiredState = () =>
|
||||
const [ furniIds, setFurniIds ] = useState<number[]>([]);
|
||||
const [ actionDelay, setActionDelay ] = useState<number>(0);
|
||||
const [ allowsFurni, setAllowsFurni ] = useState<number>(WiredFurniType.STUFF_SELECTION_OPTION_NONE);
|
||||
const [ selectByType, setSelectByType ] = useState<boolean>(false);
|
||||
const [ invertSelection, setInvertSelection ] = useState<boolean>(false);
|
||||
const { showConfirm = null } = useNotification();
|
||||
|
||||
const saveWired = () =>
|
||||
@@ -56,6 +58,77 @@ const useWiredState = () =>
|
||||
|
||||
if(objectId <= 0) return;
|
||||
|
||||
if(selectByType && category === RoomObjectCategory.FLOOR)
|
||||
{
|
||||
const roomId = GetRoomSession().roomId;
|
||||
const clickedObject = GetRoomEngine().getRoomObject(roomId, objectId, RoomObjectCategory.FLOOR);
|
||||
|
||||
if(!clickedObject) return;
|
||||
|
||||
const typeId = clickedObject.model.getValue<number>(RoomObjectVariable.FURNITURE_TYPE_ID);
|
||||
const sourceFurniData = GetSessionDataManager().getFloorItemData(typeId);
|
||||
|
||||
if(!sourceFurniData) return;
|
||||
|
||||
const matchFurniLine = sourceFurniData.furniLine;
|
||||
const matchName = sourceFurniData.name;
|
||||
|
||||
const isSameGroup = (id: number): boolean =>
|
||||
{
|
||||
const obj = GetRoomEngine().getRoomObject(roomId, id, RoomObjectCategory.FLOOR);
|
||||
if(!obj) return false;
|
||||
|
||||
const tId = obj.model.getValue<number>(RoomObjectVariable.FURNITURE_TYPE_ID);
|
||||
const fd = GetSessionDataManager().getFloorItemData(tId);
|
||||
if(!fd) return false;
|
||||
|
||||
const furniLineMatch = matchFurniLine && matchFurniLine.length > 0 && fd.furniLine === matchFurniLine;
|
||||
return furniLineMatch || fd.name === matchName;
|
||||
};
|
||||
|
||||
setFurniIds(prevValue =>
|
||||
{
|
||||
// ── Click on already-selected furni: deselect the whole group ──
|
||||
if(prevValue.includes(objectId))
|
||||
{
|
||||
const toRemove = prevValue.filter(id => isSameGroup(id));
|
||||
const remaining = prevValue.filter(id => !toRemove.includes(id));
|
||||
|
||||
WiredSelectionVisualizer.clearSelectionShaderFromFurni(toRemove);
|
||||
|
||||
return remaining;
|
||||
}
|
||||
|
||||
// ── Select a new group ──────────────────────────────────────
|
||||
if(prevValue && prevValue.length) WiredSelectionVisualizer.clearSelectionShaderFromFurni(prevValue);
|
||||
|
||||
const allFloorObjects = GetRoomEngine().getRoomObjects(roomId, RoomObjectCategory.FLOOR);
|
||||
const newIds: number[] = [];
|
||||
const limit = trigger.maximumItemSelectionCount;
|
||||
|
||||
for(const obj of allFloorObjects)
|
||||
{
|
||||
if(newIds.length >= limit) break;
|
||||
if(obj.id < 0) continue;
|
||||
|
||||
const tId = obj.model.getValue<number>(RoomObjectVariable.FURNITURE_TYPE_ID);
|
||||
const fd = GetSessionDataManager().getFloorItemData(tId);
|
||||
if(!fd) continue;
|
||||
|
||||
const furniLineMatch = matchFurniLine && matchFurniLine.length > 0 && fd.furniLine === matchFurniLine;
|
||||
const matches = furniLineMatch || fd.name === matchName;
|
||||
|
||||
if(invertSelection ? !matches : matches) newIds.push(obj.id);
|
||||
}
|
||||
|
||||
WiredSelectionVisualizer.applySelectionShaderToFurni(newIds);
|
||||
|
||||
return newIds;
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
setFurniIds(prevValue =>
|
||||
{
|
||||
const newFurniIds = [ ...prevValue ];
|
||||
@@ -131,10 +204,12 @@ const useWiredState = () =>
|
||||
return [];
|
||||
});
|
||||
setAllowsFurni(WiredFurniType.STUFF_SELECTION_OPTION_NONE);
|
||||
setSelectByType(false);
|
||||
setInvertSelection(false);
|
||||
};
|
||||
}, [ trigger ]);
|
||||
|
||||
return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, setAllowsFurni, saveWired, selectObjectForWired };
|
||||
return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, setAllowsFurni, saveWired, selectObjectForWired, setSelectByType, setInvertSelection };
|
||||
};
|
||||
|
||||
export const useWired = () => useBetween(useWiredState);
|
||||
|
||||
Reference in New Issue
Block a user